qed_dcbx.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408
  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/dcbnl.h>
  36. #include <linux/errno.h>
  37. #include <linux/kernel.h>
  38. #include <linux/slab.h>
  39. #include <linux/string.h>
  40. #include "qed.h"
  41. #include "qed_cxt.h"
  42. #include "qed_dcbx.h"
  43. #include "qed_hsi.h"
  44. #include "qed_sp.h"
  45. #include "qed_sriov.h"
  46. #include "qed_rdma.h"
  47. #ifdef CONFIG_DCB
  48. #include <linux/qed/qed_eth_if.h>
  49. #endif
  50. #define QED_DCBX_MAX_MIB_READ_TRY (100)
  51. #define QED_ETH_TYPE_DEFAULT (0)
  52. #define QED_ETH_TYPE_ROCE (0x8915)
  53. #define QED_UDP_PORT_TYPE_ROCE_V2 (0x12B7)
  54. #define QED_ETH_TYPE_FCOE (0x8906)
  55. #define QED_TCP_PORT_ISCSI (0xCBC)
  56. #define QED_DCBX_INVALID_PRIORITY 0xFF
  57. /* Get Traffic Class from priority traffic class table, 4 bits represent
  58. * the traffic class corresponding to the priority.
  59. */
  60. #define QED_DCBX_PRIO2TC(prio_tc_tbl, prio) \
  61. ((u32)(prio_tc_tbl >> ((7 - prio) * 4)) & 0x7)
  62. static const struct qed_dcbx_app_metadata qed_dcbx_app_update[] = {
  63. {DCBX_PROTOCOL_ISCSI, "ISCSI", QED_PCI_ISCSI},
  64. {DCBX_PROTOCOL_FCOE, "FCOE", QED_PCI_FCOE},
  65. {DCBX_PROTOCOL_ROCE, "ROCE", QED_PCI_ETH_ROCE},
  66. {DCBX_PROTOCOL_ROCE_V2, "ROCE_V2", QED_PCI_ETH_ROCE},
  67. {DCBX_PROTOCOL_ETH, "ETH", QED_PCI_ETH},
  68. };
  69. static bool qed_dcbx_app_ethtype(u32 app_info_bitmap)
  70. {
  71. return !!(QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) ==
  72. DCBX_APP_SF_ETHTYPE);
  73. }
  74. static bool qed_dcbx_ieee_app_ethtype(u32 app_info_bitmap)
  75. {
  76. u8 mfw_val = QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE);
  77. /* Old MFW */
  78. if (mfw_val == DCBX_APP_SF_IEEE_RESERVED)
  79. return qed_dcbx_app_ethtype(app_info_bitmap);
  80. return !!(mfw_val == DCBX_APP_SF_IEEE_ETHTYPE);
  81. }
  82. static bool qed_dcbx_app_port(u32 app_info_bitmap)
  83. {
  84. return !!(QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) ==
  85. DCBX_APP_SF_PORT);
  86. }
  87. static bool qed_dcbx_ieee_app_port(u32 app_info_bitmap, u8 type)
  88. {
  89. u8 mfw_val = QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE);
  90. /* Old MFW */
  91. if (mfw_val == DCBX_APP_SF_IEEE_RESERVED)
  92. return qed_dcbx_app_port(app_info_bitmap);
  93. return !!(mfw_val == type || mfw_val == DCBX_APP_SF_IEEE_TCP_UDP_PORT);
  94. }
  95. static bool qed_dcbx_default_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
  96. {
  97. bool ethtype;
  98. if (ieee)
  99. ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
  100. else
  101. ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
  102. return !!(ethtype && (proto_id == QED_ETH_TYPE_DEFAULT));
  103. }
  104. static bool qed_dcbx_iscsi_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
  105. {
  106. bool port;
  107. if (ieee)
  108. port = qed_dcbx_ieee_app_port(app_info_bitmap,
  109. DCBX_APP_SF_IEEE_TCP_PORT);
  110. else
  111. port = qed_dcbx_app_port(app_info_bitmap);
  112. return !!(port && (proto_id == QED_TCP_PORT_ISCSI));
  113. }
  114. static bool qed_dcbx_fcoe_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
  115. {
  116. bool ethtype;
  117. if (ieee)
  118. ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
  119. else
  120. ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
  121. return !!(ethtype && (proto_id == QED_ETH_TYPE_FCOE));
  122. }
  123. static bool qed_dcbx_roce_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
  124. {
  125. bool ethtype;
  126. if (ieee)
  127. ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
  128. else
  129. ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
  130. return !!(ethtype && (proto_id == QED_ETH_TYPE_ROCE));
  131. }
  132. static bool qed_dcbx_roce_v2_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
  133. {
  134. bool port;
  135. if (ieee)
  136. port = qed_dcbx_ieee_app_port(app_info_bitmap,
  137. DCBX_APP_SF_IEEE_UDP_PORT);
  138. else
  139. port = qed_dcbx_app_port(app_info_bitmap);
  140. return !!(port && (proto_id == QED_UDP_PORT_TYPE_ROCE_V2));
  141. }
  142. static void
  143. qed_dcbx_dp_protocol(struct qed_hwfn *p_hwfn, struct qed_dcbx_results *p_data)
  144. {
  145. enum dcbx_protocol_type id;
  146. int i;
  147. DP_VERBOSE(p_hwfn, QED_MSG_DCB, "DCBX negotiated: %d\n",
  148. p_data->dcbx_enabled);
  149. for (i = 0; i < ARRAY_SIZE(qed_dcbx_app_update); i++) {
  150. id = qed_dcbx_app_update[i].id;
  151. DP_VERBOSE(p_hwfn, QED_MSG_DCB,
  152. "%s info: update %d, enable %d, prio %d, tc %d, num_tc %d\n",
  153. qed_dcbx_app_update[i].name, p_data->arr[id].update,
  154. p_data->arr[id].enable, p_data->arr[id].priority,
  155. p_data->arr[id].tc, p_hwfn->hw_info.num_active_tc);
  156. }
  157. }
  158. static void
  159. qed_dcbx_set_params(struct qed_dcbx_results *p_data,
  160. struct qed_hw_info *p_info,
  161. bool enable,
  162. u8 prio,
  163. u8 tc,
  164. enum dcbx_protocol_type type,
  165. enum qed_pci_personality personality)
  166. {
  167. /* PF update ramrod data */
  168. p_data->arr[type].enable = enable;
  169. p_data->arr[type].priority = prio;
  170. p_data->arr[type].tc = tc;
  171. if (enable)
  172. p_data->arr[type].update = UPDATE_DCB;
  173. else
  174. p_data->arr[type].update = DONT_UPDATE_DCB_DSCP;
  175. /* QM reconf data */
  176. if (p_info->personality == personality)
  177. p_info->offload_tc = tc;
  178. }
  179. /* Update app protocol data and hw_info fields with the TLV info */
  180. static void
  181. qed_dcbx_update_app_info(struct qed_dcbx_results *p_data,
  182. struct qed_hwfn *p_hwfn,
  183. bool enable,
  184. u8 prio, u8 tc, enum dcbx_protocol_type type)
  185. {
  186. struct qed_hw_info *p_info = &p_hwfn->hw_info;
  187. enum qed_pci_personality personality;
  188. enum dcbx_protocol_type id;
  189. char *name;
  190. int i;
  191. for (i = 0; i < ARRAY_SIZE(qed_dcbx_app_update); i++) {
  192. id = qed_dcbx_app_update[i].id;
  193. if (type != id)
  194. continue;
  195. personality = qed_dcbx_app_update[i].personality;
  196. name = qed_dcbx_app_update[i].name;
  197. qed_dcbx_set_params(p_data, p_info, enable,
  198. prio, tc, type, personality);
  199. }
  200. }
  201. static bool
  202. qed_dcbx_get_app_protocol_type(struct qed_hwfn *p_hwfn,
  203. u32 app_prio_bitmap,
  204. u16 id, enum dcbx_protocol_type *type, bool ieee)
  205. {
  206. if (qed_dcbx_fcoe_tlv(app_prio_bitmap, id, ieee)) {
  207. *type = DCBX_PROTOCOL_FCOE;
  208. } else if (qed_dcbx_roce_tlv(app_prio_bitmap, id, ieee)) {
  209. *type = DCBX_PROTOCOL_ROCE;
  210. } else if (qed_dcbx_iscsi_tlv(app_prio_bitmap, id, ieee)) {
  211. *type = DCBX_PROTOCOL_ISCSI;
  212. } else if (qed_dcbx_default_tlv(app_prio_bitmap, id, ieee)) {
  213. *type = DCBX_PROTOCOL_ETH;
  214. } else if (qed_dcbx_roce_v2_tlv(app_prio_bitmap, id, ieee)) {
  215. *type = DCBX_PROTOCOL_ROCE_V2;
  216. } else {
  217. *type = DCBX_MAX_PROTOCOL_TYPE;
  218. DP_ERR(p_hwfn,
  219. "No action required, App TLV id = 0x%x app_prio_bitmap = 0x%x\n",
  220. id, app_prio_bitmap);
  221. return false;
  222. }
  223. return true;
  224. }
  225. /* Parse app TLV's to update TC information in hw_info structure for
  226. * reconfiguring QM. Get protocol specific data for PF update ramrod command.
  227. */
  228. static int
  229. qed_dcbx_process_tlv(struct qed_hwfn *p_hwfn,
  230. struct qed_dcbx_results *p_data,
  231. struct dcbx_app_priority_entry *p_tbl,
  232. u32 pri_tc_tbl, int count, u8 dcbx_version)
  233. {
  234. enum dcbx_protocol_type type;
  235. u8 tc, priority_map;
  236. bool enable, ieee;
  237. u16 protocol_id;
  238. int priority;
  239. int i;
  240. DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Num APP entries = %d\n", count);
  241. ieee = (dcbx_version == DCBX_CONFIG_VERSION_IEEE);
  242. /* Parse APP TLV */
  243. for (i = 0; i < count; i++) {
  244. protocol_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
  245. DCBX_APP_PROTOCOL_ID);
  246. priority_map = QED_MFW_GET_FIELD(p_tbl[i].entry,
  247. DCBX_APP_PRI_MAP);
  248. priority = ffs(priority_map) - 1;
  249. if (priority < 0) {
  250. DP_ERR(p_hwfn, "Invalid priority\n");
  251. return -EINVAL;
  252. }
  253. tc = QED_DCBX_PRIO2TC(pri_tc_tbl, priority);
  254. if (qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
  255. protocol_id, &type, ieee)) {
  256. /* ETH always have the enable bit reset, as it gets
  257. * vlan information per packet. For other protocols,
  258. * should be set according to the dcbx_enabled
  259. * indication, but we only got here if there was an
  260. * app tlv for the protocol, so dcbx must be enabled.
  261. */
  262. enable = !(type == DCBX_PROTOCOL_ETH);
  263. qed_dcbx_update_app_info(p_data, p_hwfn, enable,
  264. priority, tc, type);
  265. }
  266. }
  267. /* Update ramrod protocol data and hw_info fields
  268. * with default info when corresponding APP TLV's are not detected.
  269. * The enabled field has a different logic for ethernet as only for
  270. * ethernet dcb should disabled by default, as the information arrives
  271. * from the OS (unless an explicit app tlv was present).
  272. */
  273. tc = p_data->arr[DCBX_PROTOCOL_ETH].tc;
  274. priority = p_data->arr[DCBX_PROTOCOL_ETH].priority;
  275. for (type = 0; type < DCBX_MAX_PROTOCOL_TYPE; type++) {
  276. if (p_data->arr[type].update)
  277. continue;
  278. enable = (type == DCBX_PROTOCOL_ETH) ? false : !!dcbx_version;
  279. qed_dcbx_update_app_info(p_data, p_hwfn, enable,
  280. priority, tc, type);
  281. }
  282. return 0;
  283. }
  284. /* Parse app TLV's to update TC information in hw_info structure for
  285. * reconfiguring QM. Get protocol specific data for PF update ramrod command.
  286. */
  287. static int qed_dcbx_process_mib_info(struct qed_hwfn *p_hwfn)
  288. {
  289. struct dcbx_app_priority_feature *p_app;
  290. struct dcbx_app_priority_entry *p_tbl;
  291. struct qed_dcbx_results data = { 0 };
  292. struct dcbx_ets_feature *p_ets;
  293. struct qed_hw_info *p_info;
  294. u32 pri_tc_tbl, flags;
  295. u8 dcbx_version;
  296. int num_entries;
  297. int rc = 0;
  298. flags = p_hwfn->p_dcbx_info->operational.flags;
  299. dcbx_version = QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION);
  300. p_app = &p_hwfn->p_dcbx_info->operational.features.app;
  301. p_tbl = p_app->app_pri_tbl;
  302. p_ets = &p_hwfn->p_dcbx_info->operational.features.ets;
  303. pri_tc_tbl = p_ets->pri_tc_tbl[0];
  304. p_info = &p_hwfn->hw_info;
  305. num_entries = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_NUM_ENTRIES);
  306. rc = qed_dcbx_process_tlv(p_hwfn, &data, p_tbl, pri_tc_tbl,
  307. num_entries, dcbx_version);
  308. if (rc)
  309. return rc;
  310. p_info->num_active_tc = QED_MFW_GET_FIELD(p_ets->flags,
  311. DCBX_ETS_MAX_TCS);
  312. p_hwfn->qm_info.ooo_tc = QED_MFW_GET_FIELD(p_ets->flags, DCBX_OOO_TC);
  313. data.pf_id = p_hwfn->rel_pf_id;
  314. data.dcbx_enabled = !!dcbx_version;
  315. qed_dcbx_dp_protocol(p_hwfn, &data);
  316. memcpy(&p_hwfn->p_dcbx_info->results, &data,
  317. sizeof(struct qed_dcbx_results));
  318. return 0;
  319. }
  320. static int
  321. qed_dcbx_copy_mib(struct qed_hwfn *p_hwfn,
  322. struct qed_ptt *p_ptt,
  323. struct qed_dcbx_mib_meta_data *p_data,
  324. enum qed_mib_read_type type)
  325. {
  326. u32 prefix_seq_num, suffix_seq_num;
  327. int read_count = 0;
  328. int rc = 0;
  329. /* The data is considered to be valid only if both sequence numbers are
  330. * the same.
  331. */
  332. do {
  333. if (type == QED_DCBX_REMOTE_LLDP_MIB) {
  334. qed_memcpy_from(p_hwfn, p_ptt, p_data->lldp_remote,
  335. p_data->addr, p_data->size);
  336. prefix_seq_num = p_data->lldp_remote->prefix_seq_num;
  337. suffix_seq_num = p_data->lldp_remote->suffix_seq_num;
  338. } else {
  339. qed_memcpy_from(p_hwfn, p_ptt, p_data->mib,
  340. p_data->addr, p_data->size);
  341. prefix_seq_num = p_data->mib->prefix_seq_num;
  342. suffix_seq_num = p_data->mib->suffix_seq_num;
  343. }
  344. read_count++;
  345. DP_VERBOSE(p_hwfn,
  346. QED_MSG_DCB,
  347. "mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
  348. type, read_count, prefix_seq_num, suffix_seq_num);
  349. } while ((prefix_seq_num != suffix_seq_num) &&
  350. (read_count < QED_DCBX_MAX_MIB_READ_TRY));
  351. if (read_count >= QED_DCBX_MAX_MIB_READ_TRY) {
  352. DP_ERR(p_hwfn,
  353. "MIB read err, mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
  354. type, read_count, prefix_seq_num, suffix_seq_num);
  355. rc = -EIO;
  356. }
  357. return rc;
  358. }
  359. static void
  360. qed_dcbx_get_priority_info(struct qed_hwfn *p_hwfn,
  361. struct qed_dcbx_app_prio *p_prio,
  362. struct qed_dcbx_results *p_results)
  363. {
  364. u8 val;
  365. p_prio->roce = QED_DCBX_INVALID_PRIORITY;
  366. p_prio->roce_v2 = QED_DCBX_INVALID_PRIORITY;
  367. p_prio->iscsi = QED_DCBX_INVALID_PRIORITY;
  368. p_prio->fcoe = QED_DCBX_INVALID_PRIORITY;
  369. if (p_results->arr[DCBX_PROTOCOL_ROCE].update &&
  370. p_results->arr[DCBX_PROTOCOL_ROCE].enable)
  371. p_prio->roce = p_results->arr[DCBX_PROTOCOL_ROCE].priority;
  372. if (p_results->arr[DCBX_PROTOCOL_ROCE_V2].update &&
  373. p_results->arr[DCBX_PROTOCOL_ROCE_V2].enable) {
  374. val = p_results->arr[DCBX_PROTOCOL_ROCE_V2].priority;
  375. p_prio->roce_v2 = val;
  376. }
  377. if (p_results->arr[DCBX_PROTOCOL_ISCSI].update &&
  378. p_results->arr[DCBX_PROTOCOL_ISCSI].enable)
  379. p_prio->iscsi = p_results->arr[DCBX_PROTOCOL_ISCSI].priority;
  380. if (p_results->arr[DCBX_PROTOCOL_FCOE].update &&
  381. p_results->arr[DCBX_PROTOCOL_FCOE].enable)
  382. p_prio->fcoe = p_results->arr[DCBX_PROTOCOL_FCOE].priority;
  383. if (p_results->arr[DCBX_PROTOCOL_ETH].update &&
  384. p_results->arr[DCBX_PROTOCOL_ETH].enable)
  385. p_prio->eth = p_results->arr[DCBX_PROTOCOL_ETH].priority;
  386. DP_VERBOSE(p_hwfn, QED_MSG_DCB,
  387. "Priorities: iscsi %d, roce %d, roce v2 %d, fcoe %d, eth %d\n",
  388. p_prio->iscsi, p_prio->roce, p_prio->roce_v2, p_prio->fcoe,
  389. p_prio->eth);
  390. }
  391. static void
  392. qed_dcbx_get_app_data(struct qed_hwfn *p_hwfn,
  393. struct dcbx_app_priority_feature *p_app,
  394. struct dcbx_app_priority_entry *p_tbl,
  395. struct qed_dcbx_params *p_params, bool ieee)
  396. {
  397. struct qed_app_entry *entry;
  398. u8 pri_map;
  399. int i;
  400. p_params->app_willing = QED_MFW_GET_FIELD(p_app->flags,
  401. DCBX_APP_WILLING);
  402. p_params->app_valid = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ENABLED);
  403. p_params->app_error = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ERROR);
  404. p_params->num_app_entries = QED_MFW_GET_FIELD(p_app->flags,
  405. DCBX_APP_NUM_ENTRIES);
  406. for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
  407. entry = &p_params->app_entry[i];
  408. if (ieee) {
  409. u8 sf_ieee;
  410. u32 val;
  411. sf_ieee = QED_MFW_GET_FIELD(p_tbl[i].entry,
  412. DCBX_APP_SF_IEEE);
  413. switch (sf_ieee) {
  414. case DCBX_APP_SF_IEEE_RESERVED:
  415. /* Old MFW */
  416. val = QED_MFW_GET_FIELD(p_tbl[i].entry,
  417. DCBX_APP_SF);
  418. entry->sf_ieee = val ?
  419. QED_DCBX_SF_IEEE_TCP_UDP_PORT :
  420. QED_DCBX_SF_IEEE_ETHTYPE;
  421. break;
  422. case DCBX_APP_SF_IEEE_ETHTYPE:
  423. entry->sf_ieee = QED_DCBX_SF_IEEE_ETHTYPE;
  424. break;
  425. case DCBX_APP_SF_IEEE_TCP_PORT:
  426. entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_PORT;
  427. break;
  428. case DCBX_APP_SF_IEEE_UDP_PORT:
  429. entry->sf_ieee = QED_DCBX_SF_IEEE_UDP_PORT;
  430. break;
  431. case DCBX_APP_SF_IEEE_TCP_UDP_PORT:
  432. entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_UDP_PORT;
  433. break;
  434. }
  435. } else {
  436. entry->ethtype = !(QED_MFW_GET_FIELD(p_tbl[i].entry,
  437. DCBX_APP_SF));
  438. }
  439. pri_map = QED_MFW_GET_FIELD(p_tbl[i].entry, DCBX_APP_PRI_MAP);
  440. entry->prio = ffs(pri_map) - 1;
  441. entry->proto_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
  442. DCBX_APP_PROTOCOL_ID);
  443. qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
  444. entry->proto_id,
  445. &entry->proto_type, ieee);
  446. }
  447. DP_VERBOSE(p_hwfn, QED_MSG_DCB,
  448. "APP params: willing %d, valid %d error = %d\n",
  449. p_params->app_willing, p_params->app_valid,
  450. p_params->app_error);
  451. }
  452. static void
  453. qed_dcbx_get_pfc_data(struct qed_hwfn *p_hwfn,
  454. u32 pfc, struct qed_dcbx_params *p_params)
  455. {
  456. u8 pfc_map;
  457. p_params->pfc.willing = QED_MFW_GET_FIELD(pfc, DCBX_PFC_WILLING);
  458. p_params->pfc.max_tc = QED_MFW_GET_FIELD(pfc, DCBX_PFC_CAPS);
  459. p_params->pfc.enabled = QED_MFW_GET_FIELD(pfc, DCBX_PFC_ENABLED);
  460. pfc_map = QED_MFW_GET_FIELD(pfc, DCBX_PFC_PRI_EN_BITMAP);
  461. p_params->pfc.prio[0] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_0);
  462. p_params->pfc.prio[1] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_1);
  463. p_params->pfc.prio[2] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_2);
  464. p_params->pfc.prio[3] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_3);
  465. p_params->pfc.prio[4] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_4);
  466. p_params->pfc.prio[5] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_5);
  467. p_params->pfc.prio[6] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_6);
  468. p_params->pfc.prio[7] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_7);
  469. DP_VERBOSE(p_hwfn, QED_MSG_DCB,
  470. "PFC params: willing %d, pfc_bitmap %u max_tc = %u enabled = %d\n",
  471. p_params->pfc.willing, pfc_map, p_params->pfc.max_tc,
  472. p_params->pfc.enabled);
  473. }
  474. static void
  475. qed_dcbx_get_ets_data(struct qed_hwfn *p_hwfn,
  476. struct dcbx_ets_feature *p_ets,
  477. struct qed_dcbx_params *p_params)
  478. {
  479. u32 bw_map[2], tsa_map[2], pri_map;
  480. int i;
  481. p_params->ets_willing = QED_MFW_GET_FIELD(p_ets->flags,
  482. DCBX_ETS_WILLING);
  483. p_params->ets_enabled = QED_MFW_GET_FIELD(p_ets->flags,
  484. DCBX_ETS_ENABLED);
  485. p_params->ets_cbs = QED_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_CBS);
  486. p_params->max_ets_tc = QED_MFW_GET_FIELD(p_ets->flags,
  487. DCBX_ETS_MAX_TCS);
  488. DP_VERBOSE(p_hwfn, QED_MSG_DCB,
  489. "ETS params: willing %d, enabled = %d ets_cbs %d pri_tc_tbl_0 %x max_ets_tc %d\n",
  490. p_params->ets_willing, p_params->ets_enabled,
  491. p_params->ets_cbs, p_ets->pri_tc_tbl[0],
  492. p_params->max_ets_tc);
  493. if (p_params->ets_enabled && !p_params->max_ets_tc) {
  494. p_params->max_ets_tc = QED_MAX_PFC_PRIORITIES;
  495. DP_VERBOSE(p_hwfn, QED_MSG_DCB,
  496. "ETS params: max_ets_tc is forced to %d\n",
  497. p_params->max_ets_tc);
  498. }
  499. /* 8 bit tsa and bw data corresponding to each of the 8 TC's are
  500. * encoded in a type u32 array of size 2.
  501. */
  502. bw_map[0] = be32_to_cpu(p_ets->tc_bw_tbl[0]);
  503. bw_map[1] = be32_to_cpu(p_ets->tc_bw_tbl[1]);
  504. tsa_map[0] = be32_to_cpu(p_ets->tc_tsa_tbl[0]);
  505. tsa_map[1] = be32_to_cpu(p_ets->tc_tsa_tbl[1]);
  506. pri_map = p_ets->pri_tc_tbl[0];
  507. for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
  508. p_params->ets_tc_bw_tbl[i] = ((u8 *)bw_map)[i];
  509. p_params->ets_tc_tsa_tbl[i] = ((u8 *)tsa_map)[i];
  510. p_params->ets_pri_tc_tbl[i] = QED_DCBX_PRIO2TC(pri_map, i);
  511. DP_VERBOSE(p_hwfn, QED_MSG_DCB,
  512. "elem %d bw_tbl %x tsa_tbl %x\n",
  513. i, p_params->ets_tc_bw_tbl[i],
  514. p_params->ets_tc_tsa_tbl[i]);
  515. }
  516. }
  517. static void
  518. qed_dcbx_get_common_params(struct qed_hwfn *p_hwfn,
  519. struct dcbx_app_priority_feature *p_app,
  520. struct dcbx_app_priority_entry *p_tbl,
  521. struct dcbx_ets_feature *p_ets,
  522. u32 pfc, struct qed_dcbx_params *p_params, bool ieee)
  523. {
  524. qed_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params, ieee);
  525. qed_dcbx_get_ets_data(p_hwfn, p_ets, p_params);
  526. qed_dcbx_get_pfc_data(p_hwfn, pfc, p_params);
  527. }
  528. static void
  529. qed_dcbx_get_local_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *params)
  530. {
  531. struct dcbx_features *p_feat;
  532. p_feat = &p_hwfn->p_dcbx_info->local_admin.features;
  533. qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
  534. p_feat->app.app_pri_tbl, &p_feat->ets,
  535. p_feat->pfc, &params->local.params, false);
  536. params->local.valid = true;
  537. }
  538. static void
  539. qed_dcbx_get_remote_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *params)
  540. {
  541. struct dcbx_features *p_feat;
  542. p_feat = &p_hwfn->p_dcbx_info->remote.features;
  543. qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
  544. p_feat->app.app_pri_tbl, &p_feat->ets,
  545. p_feat->pfc, &params->remote.params, false);
  546. params->remote.valid = true;
  547. }
  548. static void
  549. qed_dcbx_get_operational_params(struct qed_hwfn *p_hwfn,
  550. struct qed_dcbx_get *params)
  551. {
  552. struct qed_dcbx_operational_params *p_operational;
  553. struct qed_dcbx_results *p_results;
  554. struct dcbx_features *p_feat;
  555. bool enabled, err;
  556. u32 flags;
  557. bool val;
  558. flags = p_hwfn->p_dcbx_info->operational.flags;
  559. /* If DCBx version is non zero, then negotiation
  560. * was successfuly performed
  561. */
  562. p_operational = &params->operational;
  563. enabled = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) !=
  564. DCBX_CONFIG_VERSION_DISABLED);
  565. if (!enabled) {
  566. p_operational->enabled = enabled;
  567. p_operational->valid = false;
  568. DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Dcbx is disabled\n");
  569. return;
  570. }
  571. p_feat = &p_hwfn->p_dcbx_info->operational.features;
  572. p_results = &p_hwfn->p_dcbx_info->results;
  573. val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
  574. DCBX_CONFIG_VERSION_IEEE);
  575. p_operational->ieee = val;
  576. val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
  577. DCBX_CONFIG_VERSION_CEE);
  578. p_operational->cee = val;
  579. val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
  580. DCBX_CONFIG_VERSION_STATIC);
  581. p_operational->local = val;
  582. DP_VERBOSE(p_hwfn, QED_MSG_DCB,
  583. "Version support: ieee %d, cee %d, static %d\n",
  584. p_operational->ieee, p_operational->cee,
  585. p_operational->local);
  586. qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
  587. p_feat->app.app_pri_tbl, &p_feat->ets,
  588. p_feat->pfc, &params->operational.params,
  589. p_operational->ieee);
  590. qed_dcbx_get_priority_info(p_hwfn, &p_operational->app_prio, p_results);
  591. err = QED_MFW_GET_FIELD(p_feat->app.flags, DCBX_APP_ERROR);
  592. p_operational->err = err;
  593. p_operational->enabled = enabled;
  594. p_operational->valid = true;
  595. }
  596. static void
  597. qed_dcbx_get_local_lldp_params(struct qed_hwfn *p_hwfn,
  598. struct qed_dcbx_get *params)
  599. {
  600. struct lldp_config_params_s *p_local;
  601. p_local = &p_hwfn->p_dcbx_info->lldp_local[LLDP_NEAREST_BRIDGE];
  602. memcpy(params->lldp_local.local_chassis_id, p_local->local_chassis_id,
  603. ARRAY_SIZE(p_local->local_chassis_id));
  604. memcpy(params->lldp_local.local_port_id, p_local->local_port_id,
  605. ARRAY_SIZE(p_local->local_port_id));
  606. }
  607. static void
  608. qed_dcbx_get_remote_lldp_params(struct qed_hwfn *p_hwfn,
  609. struct qed_dcbx_get *params)
  610. {
  611. struct lldp_status_params_s *p_remote;
  612. p_remote = &p_hwfn->p_dcbx_info->lldp_remote[LLDP_NEAREST_BRIDGE];
  613. memcpy(params->lldp_remote.peer_chassis_id, p_remote->peer_chassis_id,
  614. ARRAY_SIZE(p_remote->peer_chassis_id));
  615. memcpy(params->lldp_remote.peer_port_id, p_remote->peer_port_id,
  616. ARRAY_SIZE(p_remote->peer_port_id));
  617. }
  618. static int
  619. qed_dcbx_get_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *p_params,
  620. enum qed_mib_read_type type)
  621. {
  622. switch (type) {
  623. case QED_DCBX_REMOTE_MIB:
  624. qed_dcbx_get_remote_params(p_hwfn, p_params);
  625. break;
  626. case QED_DCBX_LOCAL_MIB:
  627. qed_dcbx_get_local_params(p_hwfn, p_params);
  628. break;
  629. case QED_DCBX_OPERATIONAL_MIB:
  630. qed_dcbx_get_operational_params(p_hwfn, p_params);
  631. break;
  632. case QED_DCBX_REMOTE_LLDP_MIB:
  633. qed_dcbx_get_remote_lldp_params(p_hwfn, p_params);
  634. break;
  635. case QED_DCBX_LOCAL_LLDP_MIB:
  636. qed_dcbx_get_local_lldp_params(p_hwfn, p_params);
  637. break;
  638. default:
  639. DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
  640. return -EINVAL;
  641. }
  642. return 0;
  643. }
  644. static int
  645. qed_dcbx_read_local_lldp_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  646. {
  647. struct qed_dcbx_mib_meta_data data;
  648. int rc = 0;
  649. memset(&data, 0, sizeof(data));
  650. data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
  651. lldp_config_params);
  652. data.lldp_local = p_hwfn->p_dcbx_info->lldp_local;
  653. data.size = sizeof(struct lldp_config_params_s);
  654. qed_memcpy_from(p_hwfn, p_ptt, data.lldp_local, data.addr, data.size);
  655. return rc;
  656. }
  657. static int
  658. qed_dcbx_read_remote_lldp_mib(struct qed_hwfn *p_hwfn,
  659. struct qed_ptt *p_ptt,
  660. enum qed_mib_read_type type)
  661. {
  662. struct qed_dcbx_mib_meta_data data;
  663. int rc = 0;
  664. memset(&data, 0, sizeof(data));
  665. data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
  666. lldp_status_params);
  667. data.lldp_remote = p_hwfn->p_dcbx_info->lldp_remote;
  668. data.size = sizeof(struct lldp_status_params_s);
  669. rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
  670. return rc;
  671. }
  672. static int
  673. qed_dcbx_read_operational_mib(struct qed_hwfn *p_hwfn,
  674. struct qed_ptt *p_ptt,
  675. enum qed_mib_read_type type)
  676. {
  677. struct qed_dcbx_mib_meta_data data;
  678. int rc = 0;
  679. memset(&data, 0, sizeof(data));
  680. data.addr = p_hwfn->mcp_info->port_addr +
  681. offsetof(struct public_port, operational_dcbx_mib);
  682. data.mib = &p_hwfn->p_dcbx_info->operational;
  683. data.size = sizeof(struct dcbx_mib);
  684. rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
  685. return rc;
  686. }
  687. static int
  688. qed_dcbx_read_remote_mib(struct qed_hwfn *p_hwfn,
  689. struct qed_ptt *p_ptt, enum qed_mib_read_type type)
  690. {
  691. struct qed_dcbx_mib_meta_data data;
  692. int rc = 0;
  693. memset(&data, 0, sizeof(data));
  694. data.addr = p_hwfn->mcp_info->port_addr +
  695. offsetof(struct public_port, remote_dcbx_mib);
  696. data.mib = &p_hwfn->p_dcbx_info->remote;
  697. data.size = sizeof(struct dcbx_mib);
  698. rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
  699. return rc;
  700. }
  701. static int
  702. qed_dcbx_read_local_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  703. {
  704. struct qed_dcbx_mib_meta_data data;
  705. int rc = 0;
  706. memset(&data, 0, sizeof(data));
  707. data.addr = p_hwfn->mcp_info->port_addr +
  708. offsetof(struct public_port, local_admin_dcbx_mib);
  709. data.local_admin = &p_hwfn->p_dcbx_info->local_admin;
  710. data.size = sizeof(struct dcbx_local_params);
  711. qed_memcpy_from(p_hwfn, p_ptt, data.local_admin, data.addr, data.size);
  712. return rc;
  713. }
  714. static int qed_dcbx_read_mib(struct qed_hwfn *p_hwfn,
  715. struct qed_ptt *p_ptt, enum qed_mib_read_type type)
  716. {
  717. int rc = -EINVAL;
  718. switch (type) {
  719. case QED_DCBX_OPERATIONAL_MIB:
  720. rc = qed_dcbx_read_operational_mib(p_hwfn, p_ptt, type);
  721. break;
  722. case QED_DCBX_REMOTE_MIB:
  723. rc = qed_dcbx_read_remote_mib(p_hwfn, p_ptt, type);
  724. break;
  725. case QED_DCBX_LOCAL_MIB:
  726. rc = qed_dcbx_read_local_mib(p_hwfn, p_ptt);
  727. break;
  728. case QED_DCBX_REMOTE_LLDP_MIB:
  729. rc = qed_dcbx_read_remote_lldp_mib(p_hwfn, p_ptt, type);
  730. break;
  731. case QED_DCBX_LOCAL_LLDP_MIB:
  732. rc = qed_dcbx_read_local_lldp_mib(p_hwfn, p_ptt);
  733. break;
  734. default:
  735. DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
  736. }
  737. return rc;
  738. }
  739. void qed_dcbx_aen(struct qed_hwfn *hwfn, u32 mib_type)
  740. {
  741. struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
  742. void *cookie = hwfn->cdev->ops_cookie;
  743. if (cookie && op->dcbx_aen)
  744. op->dcbx_aen(cookie, &hwfn->p_dcbx_info->get, mib_type);
  745. }
  746. /* Read updated MIB.
  747. * Reconfigure QM and invoke PF update ramrod command if operational MIB
  748. * change is detected.
  749. */
  750. int
  751. qed_dcbx_mib_update_event(struct qed_hwfn *p_hwfn,
  752. struct qed_ptt *p_ptt, enum qed_mib_read_type type)
  753. {
  754. int rc = 0;
  755. rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
  756. if (rc)
  757. return rc;
  758. if (type == QED_DCBX_OPERATIONAL_MIB) {
  759. rc = qed_dcbx_process_mib_info(p_hwfn);
  760. if (!rc) {
  761. /* reconfigure tcs of QM queues according
  762. * to negotiation results
  763. */
  764. qed_qm_reconf(p_hwfn, p_ptt);
  765. /* update storm FW with negotiation results */
  766. qed_sp_pf_update(p_hwfn);
  767. /* for roce PFs, we may want to enable/disable DPM
  768. * when DCBx change occurs
  769. */
  770. if (p_hwfn->hw_info.personality ==
  771. QED_PCI_ETH_ROCE)
  772. qed_roce_dpm_dcbx(p_hwfn, p_ptt);
  773. }
  774. }
  775. qed_dcbx_get_params(p_hwfn, &p_hwfn->p_dcbx_info->get, type);
  776. if (type == QED_DCBX_OPERATIONAL_MIB) {
  777. struct qed_dcbx_results *p_data;
  778. u16 val;
  779. /* Configure in NIG which protocols support EDPM and should
  780. * honor PFC.
  781. */
  782. p_data = &p_hwfn->p_dcbx_info->results;
  783. val = (0x1 << p_data->arr[DCBX_PROTOCOL_ROCE].tc) |
  784. (0x1 << p_data->arr[DCBX_PROTOCOL_ROCE_V2].tc);
  785. val <<= NIG_REG_TX_EDPM_CTRL_TX_EDPM_TC_EN_SHIFT;
  786. val |= NIG_REG_TX_EDPM_CTRL_TX_EDPM_EN;
  787. qed_wr(p_hwfn, p_ptt, NIG_REG_TX_EDPM_CTRL, val);
  788. }
  789. qed_dcbx_aen(p_hwfn, type);
  790. return rc;
  791. }
  792. int qed_dcbx_info_alloc(struct qed_hwfn *p_hwfn)
  793. {
  794. p_hwfn->p_dcbx_info = kzalloc(sizeof(*p_hwfn->p_dcbx_info), GFP_KERNEL);
  795. if (!p_hwfn->p_dcbx_info)
  796. return -ENOMEM;
  797. return 0;
  798. }
  799. void qed_dcbx_info_free(struct qed_hwfn *p_hwfn)
  800. {
  801. kfree(p_hwfn->p_dcbx_info);
  802. p_hwfn->p_dcbx_info = NULL;
  803. }
  804. static void qed_dcbx_update_protocol_data(struct protocol_dcb_data *p_data,
  805. struct qed_dcbx_results *p_src,
  806. enum dcbx_protocol_type type)
  807. {
  808. p_data->dcb_enable_flag = p_src->arr[type].enable;
  809. p_data->dcb_priority = p_src->arr[type].priority;
  810. p_data->dcb_tc = p_src->arr[type].tc;
  811. }
  812. /* Set pf update ramrod command params */
  813. void qed_dcbx_set_pf_update_params(struct qed_dcbx_results *p_src,
  814. struct pf_update_ramrod_data *p_dest)
  815. {
  816. struct protocol_dcb_data *p_dcb_data;
  817. u8 update_flag;
  818. update_flag = p_src->arr[DCBX_PROTOCOL_FCOE].update;
  819. p_dest->update_fcoe_dcb_data_mode = update_flag;
  820. update_flag = p_src->arr[DCBX_PROTOCOL_ROCE].update;
  821. p_dest->update_roce_dcb_data_mode = update_flag;
  822. update_flag = p_src->arr[DCBX_PROTOCOL_ROCE_V2].update;
  823. p_dest->update_rroce_dcb_data_mode = update_flag;
  824. update_flag = p_src->arr[DCBX_PROTOCOL_ISCSI].update;
  825. p_dest->update_iscsi_dcb_data_mode = update_flag;
  826. update_flag = p_src->arr[DCBX_PROTOCOL_ETH].update;
  827. p_dest->update_eth_dcb_data_mode = update_flag;
  828. p_dcb_data = &p_dest->fcoe_dcb_data;
  829. qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_FCOE);
  830. p_dcb_data = &p_dest->roce_dcb_data;
  831. qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ROCE);
  832. p_dcb_data = &p_dest->rroce_dcb_data;
  833. qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ROCE_V2);
  834. p_dcb_data = &p_dest->iscsi_dcb_data;
  835. qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ISCSI);
  836. p_dcb_data = &p_dest->eth_dcb_data;
  837. qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ETH);
  838. }
  839. #ifdef CONFIG_DCB
  840. static int qed_dcbx_query_params(struct qed_hwfn *p_hwfn,
  841. struct qed_dcbx_get *p_get,
  842. enum qed_mib_read_type type)
  843. {
  844. struct qed_ptt *p_ptt;
  845. int rc;
  846. if (IS_VF(p_hwfn->cdev))
  847. return -EINVAL;
  848. p_ptt = qed_ptt_acquire(p_hwfn);
  849. if (!p_ptt)
  850. return -EBUSY;
  851. rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
  852. if (rc)
  853. goto out;
  854. rc = qed_dcbx_get_params(p_hwfn, p_get, type);
  855. out:
  856. qed_ptt_release(p_hwfn, p_ptt);
  857. return rc;
  858. }
  859. static void
  860. qed_dcbx_set_pfc_data(struct qed_hwfn *p_hwfn,
  861. u32 *pfc, struct qed_dcbx_params *p_params)
  862. {
  863. u8 pfc_map = 0;
  864. int i;
  865. *pfc &= ~DCBX_PFC_ERROR_MASK;
  866. if (p_params->pfc.willing)
  867. *pfc |= DCBX_PFC_WILLING_MASK;
  868. else
  869. *pfc &= ~DCBX_PFC_WILLING_MASK;
  870. if (p_params->pfc.enabled)
  871. *pfc |= DCBX_PFC_ENABLED_MASK;
  872. else
  873. *pfc &= ~DCBX_PFC_ENABLED_MASK;
  874. *pfc &= ~DCBX_PFC_CAPS_MASK;
  875. *pfc |= (u32)p_params->pfc.max_tc << DCBX_PFC_CAPS_SHIFT;
  876. for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
  877. if (p_params->pfc.prio[i])
  878. pfc_map |= BIT(i);
  879. *pfc &= ~DCBX_PFC_PRI_EN_BITMAP_MASK;
  880. *pfc |= (pfc_map << DCBX_PFC_PRI_EN_BITMAP_SHIFT);
  881. DP_VERBOSE(p_hwfn, QED_MSG_DCB, "pfc = 0x%x\n", *pfc);
  882. }
  883. static void
  884. qed_dcbx_set_ets_data(struct qed_hwfn *p_hwfn,
  885. struct dcbx_ets_feature *p_ets,
  886. struct qed_dcbx_params *p_params)
  887. {
  888. u8 *bw_map, *tsa_map;
  889. u32 val;
  890. int i;
  891. if (p_params->ets_willing)
  892. p_ets->flags |= DCBX_ETS_WILLING_MASK;
  893. else
  894. p_ets->flags &= ~DCBX_ETS_WILLING_MASK;
  895. if (p_params->ets_cbs)
  896. p_ets->flags |= DCBX_ETS_CBS_MASK;
  897. else
  898. p_ets->flags &= ~DCBX_ETS_CBS_MASK;
  899. if (p_params->ets_enabled)
  900. p_ets->flags |= DCBX_ETS_ENABLED_MASK;
  901. else
  902. p_ets->flags &= ~DCBX_ETS_ENABLED_MASK;
  903. p_ets->flags &= ~DCBX_ETS_MAX_TCS_MASK;
  904. p_ets->flags |= (u32)p_params->max_ets_tc << DCBX_ETS_MAX_TCS_SHIFT;
  905. bw_map = (u8 *)&p_ets->tc_bw_tbl[0];
  906. tsa_map = (u8 *)&p_ets->tc_tsa_tbl[0];
  907. p_ets->pri_tc_tbl[0] = 0;
  908. for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
  909. bw_map[i] = p_params->ets_tc_bw_tbl[i];
  910. tsa_map[i] = p_params->ets_tc_tsa_tbl[i];
  911. /* Copy the priority value to the corresponding 4 bits in the
  912. * traffic class table.
  913. */
  914. val = (((u32)p_params->ets_pri_tc_tbl[i]) << ((7 - i) * 4));
  915. p_ets->pri_tc_tbl[0] |= val;
  916. }
  917. for (i = 0; i < 2; i++) {
  918. p_ets->tc_bw_tbl[i] = cpu_to_be32(p_ets->tc_bw_tbl[i]);
  919. p_ets->tc_tsa_tbl[i] = cpu_to_be32(p_ets->tc_tsa_tbl[i]);
  920. }
  921. }
  922. static void
  923. qed_dcbx_set_app_data(struct qed_hwfn *p_hwfn,
  924. struct dcbx_app_priority_feature *p_app,
  925. struct qed_dcbx_params *p_params, bool ieee)
  926. {
  927. u32 *entry;
  928. int i;
  929. if (p_params->app_willing)
  930. p_app->flags |= DCBX_APP_WILLING_MASK;
  931. else
  932. p_app->flags &= ~DCBX_APP_WILLING_MASK;
  933. if (p_params->app_valid)
  934. p_app->flags |= DCBX_APP_ENABLED_MASK;
  935. else
  936. p_app->flags &= ~DCBX_APP_ENABLED_MASK;
  937. p_app->flags &= ~DCBX_APP_NUM_ENTRIES_MASK;
  938. p_app->flags |= (u32)p_params->num_app_entries <<
  939. DCBX_APP_NUM_ENTRIES_SHIFT;
  940. for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
  941. entry = &p_app->app_pri_tbl[i].entry;
  942. *entry = 0;
  943. if (ieee) {
  944. *entry &= ~(DCBX_APP_SF_IEEE_MASK | DCBX_APP_SF_MASK);
  945. switch (p_params->app_entry[i].sf_ieee) {
  946. case QED_DCBX_SF_IEEE_ETHTYPE:
  947. *entry |= ((u32)DCBX_APP_SF_IEEE_ETHTYPE <<
  948. DCBX_APP_SF_IEEE_SHIFT);
  949. *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
  950. DCBX_APP_SF_SHIFT);
  951. break;
  952. case QED_DCBX_SF_IEEE_TCP_PORT:
  953. *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_PORT <<
  954. DCBX_APP_SF_IEEE_SHIFT);
  955. *entry |= ((u32)DCBX_APP_SF_PORT <<
  956. DCBX_APP_SF_SHIFT);
  957. break;
  958. case QED_DCBX_SF_IEEE_UDP_PORT:
  959. *entry |= ((u32)DCBX_APP_SF_IEEE_UDP_PORT <<
  960. DCBX_APP_SF_IEEE_SHIFT);
  961. *entry |= ((u32)DCBX_APP_SF_PORT <<
  962. DCBX_APP_SF_SHIFT);
  963. break;
  964. case QED_DCBX_SF_IEEE_TCP_UDP_PORT:
  965. *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_UDP_PORT <<
  966. DCBX_APP_SF_IEEE_SHIFT);
  967. *entry |= ((u32)DCBX_APP_SF_PORT <<
  968. DCBX_APP_SF_SHIFT);
  969. break;
  970. }
  971. } else {
  972. *entry &= ~DCBX_APP_SF_MASK;
  973. if (p_params->app_entry[i].ethtype)
  974. *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
  975. DCBX_APP_SF_SHIFT);
  976. else
  977. *entry |= ((u32)DCBX_APP_SF_PORT <<
  978. DCBX_APP_SF_SHIFT);
  979. }
  980. *entry &= ~DCBX_APP_PROTOCOL_ID_MASK;
  981. *entry |= ((u32)p_params->app_entry[i].proto_id <<
  982. DCBX_APP_PROTOCOL_ID_SHIFT);
  983. *entry &= ~DCBX_APP_PRI_MAP_MASK;
  984. *entry |= ((u32)(p_params->app_entry[i].prio) <<
  985. DCBX_APP_PRI_MAP_SHIFT);
  986. }
  987. }
  988. static void
  989. qed_dcbx_set_local_params(struct qed_hwfn *p_hwfn,
  990. struct dcbx_local_params *local_admin,
  991. struct qed_dcbx_set *params)
  992. {
  993. bool ieee = false;
  994. local_admin->flags = 0;
  995. memcpy(&local_admin->features,
  996. &p_hwfn->p_dcbx_info->operational.features,
  997. sizeof(local_admin->features));
  998. if (params->enabled) {
  999. local_admin->config = params->ver_num;
  1000. ieee = !!(params->ver_num & DCBX_CONFIG_VERSION_IEEE);
  1001. } else {
  1002. local_admin->config = DCBX_CONFIG_VERSION_DISABLED;
  1003. }
  1004. DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Dcbx version = %d\n",
  1005. local_admin->config);
  1006. if (params->override_flags & QED_DCBX_OVERRIDE_PFC_CFG)
  1007. qed_dcbx_set_pfc_data(p_hwfn, &local_admin->features.pfc,
  1008. &params->config.params);
  1009. if (params->override_flags & QED_DCBX_OVERRIDE_ETS_CFG)
  1010. qed_dcbx_set_ets_data(p_hwfn, &local_admin->features.ets,
  1011. &params->config.params);
  1012. if (params->override_flags & QED_DCBX_OVERRIDE_APP_CFG)
  1013. qed_dcbx_set_app_data(p_hwfn, &local_admin->features.app,
  1014. &params->config.params, ieee);
  1015. }
  1016. int qed_dcbx_config_params(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
  1017. struct qed_dcbx_set *params, bool hw_commit)
  1018. {
  1019. struct dcbx_local_params local_admin;
  1020. struct qed_dcbx_mib_meta_data data;
  1021. u32 resp = 0, param = 0;
  1022. int rc = 0;
  1023. if (!hw_commit) {
  1024. memcpy(&p_hwfn->p_dcbx_info->set, params,
  1025. sizeof(struct qed_dcbx_set));
  1026. return 0;
  1027. }
  1028. /* clear set-parmas cache */
  1029. memset(&p_hwfn->p_dcbx_info->set, 0, sizeof(p_hwfn->p_dcbx_info->set));
  1030. memset(&local_admin, 0, sizeof(local_admin));
  1031. qed_dcbx_set_local_params(p_hwfn, &local_admin, params);
  1032. data.addr = p_hwfn->mcp_info->port_addr +
  1033. offsetof(struct public_port, local_admin_dcbx_mib);
  1034. data.local_admin = &local_admin;
  1035. data.size = sizeof(struct dcbx_local_params);
  1036. qed_memcpy_to(p_hwfn, p_ptt, data.addr, data.local_admin, data.size);
  1037. rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_DCBX,
  1038. 1 << DRV_MB_PARAM_LLDP_SEND_SHIFT, &resp, &param);
  1039. if (rc)
  1040. DP_NOTICE(p_hwfn, "Failed to send DCBX update request\n");
  1041. return rc;
  1042. }
  1043. int qed_dcbx_get_config_params(struct qed_hwfn *p_hwfn,
  1044. struct qed_dcbx_set *params)
  1045. {
  1046. struct qed_dcbx_get *dcbx_info;
  1047. int rc;
  1048. if (p_hwfn->p_dcbx_info->set.config.valid) {
  1049. memcpy(params, &p_hwfn->p_dcbx_info->set,
  1050. sizeof(struct qed_dcbx_set));
  1051. return 0;
  1052. }
  1053. dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_KERNEL);
  1054. if (!dcbx_info)
  1055. return -ENOMEM;
  1056. rc = qed_dcbx_query_params(p_hwfn, dcbx_info, QED_DCBX_OPERATIONAL_MIB);
  1057. if (rc) {
  1058. kfree(dcbx_info);
  1059. return rc;
  1060. }
  1061. p_hwfn->p_dcbx_info->set.override_flags = 0;
  1062. p_hwfn->p_dcbx_info->set.ver_num = DCBX_CONFIG_VERSION_DISABLED;
  1063. if (dcbx_info->operational.cee)
  1064. p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_CEE;
  1065. if (dcbx_info->operational.ieee)
  1066. p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
  1067. if (dcbx_info->operational.local)
  1068. p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
  1069. p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled;
  1070. memcpy(&p_hwfn->p_dcbx_info->set.config.params,
  1071. &dcbx_info->operational.params,
  1072. sizeof(struct qed_dcbx_admin_params));
  1073. p_hwfn->p_dcbx_info->set.config.valid = true;
  1074. memcpy(params, &p_hwfn->p_dcbx_info->set, sizeof(struct qed_dcbx_set));
  1075. kfree(dcbx_info);
  1076. return 0;
  1077. }
  1078. static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn,
  1079. enum qed_mib_read_type type)
  1080. {
  1081. struct qed_dcbx_get *dcbx_info;
  1082. dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_ATOMIC);
  1083. if (!dcbx_info)
  1084. return NULL;
  1085. if (qed_dcbx_query_params(hwfn, dcbx_info, type)) {
  1086. kfree(dcbx_info);
  1087. return NULL;
  1088. }
  1089. if ((type == QED_DCBX_OPERATIONAL_MIB) &&
  1090. !dcbx_info->operational.enabled) {
  1091. DP_INFO(hwfn, "DCBX is not enabled/operational\n");
  1092. kfree(dcbx_info);
  1093. return NULL;
  1094. }
  1095. return dcbx_info;
  1096. }
  1097. static u8 qed_dcbnl_getstate(struct qed_dev *cdev)
  1098. {
  1099. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1100. struct qed_dcbx_get *dcbx_info;
  1101. bool enabled;
  1102. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1103. if (!dcbx_info)
  1104. return 0;
  1105. enabled = dcbx_info->operational.enabled;
  1106. DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", enabled);
  1107. kfree(dcbx_info);
  1108. return enabled;
  1109. }
  1110. static u8 qed_dcbnl_setstate(struct qed_dev *cdev, u8 state)
  1111. {
  1112. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1113. struct qed_dcbx_set dcbx_set;
  1114. struct qed_ptt *ptt;
  1115. int rc;
  1116. DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", state);
  1117. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1118. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1119. if (rc)
  1120. return 1;
  1121. dcbx_set.enabled = !!state;
  1122. ptt = qed_ptt_acquire(hwfn);
  1123. if (!ptt)
  1124. return 1;
  1125. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1126. qed_ptt_release(hwfn, ptt);
  1127. return rc ? 1 : 0;
  1128. }
  1129. static void qed_dcbnl_getpgtccfgtx(struct qed_dev *cdev, int tc, u8 *prio_type,
  1130. u8 *pgid, u8 *bw_pct, u8 *up_map)
  1131. {
  1132. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1133. struct qed_dcbx_get *dcbx_info;
  1134. DP_VERBOSE(hwfn, QED_MSG_DCB, "tc = %d\n", tc);
  1135. *prio_type = *pgid = *bw_pct = *up_map = 0;
  1136. if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
  1137. DP_INFO(hwfn, "Invalid tc %d\n", tc);
  1138. return;
  1139. }
  1140. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1141. if (!dcbx_info)
  1142. return;
  1143. *pgid = dcbx_info->operational.params.ets_pri_tc_tbl[tc];
  1144. kfree(dcbx_info);
  1145. }
  1146. static void qed_dcbnl_getpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 *bw_pct)
  1147. {
  1148. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1149. struct qed_dcbx_get *dcbx_info;
  1150. *bw_pct = 0;
  1151. DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d\n", pgid);
  1152. if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
  1153. DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
  1154. return;
  1155. }
  1156. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1157. if (!dcbx_info)
  1158. return;
  1159. *bw_pct = dcbx_info->operational.params.ets_tc_bw_tbl[pgid];
  1160. DP_VERBOSE(hwfn, QED_MSG_DCB, "bw_pct = %d\n", *bw_pct);
  1161. kfree(dcbx_info);
  1162. }
  1163. static void qed_dcbnl_getpgtccfgrx(struct qed_dev *cdev, int tc, u8 *prio,
  1164. u8 *bwg_id, u8 *bw_pct, u8 *up_map)
  1165. {
  1166. DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
  1167. *prio = *bwg_id = *bw_pct = *up_map = 0;
  1168. }
  1169. static void qed_dcbnl_getpgbwgcfgrx(struct qed_dev *cdev,
  1170. int bwg_id, u8 *bw_pct)
  1171. {
  1172. DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
  1173. *bw_pct = 0;
  1174. }
  1175. static void qed_dcbnl_getpfccfg(struct qed_dev *cdev,
  1176. int priority, u8 *setting)
  1177. {
  1178. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1179. struct qed_dcbx_get *dcbx_info;
  1180. DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d\n", priority);
  1181. if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
  1182. DP_INFO(hwfn, "Invalid priority %d\n", priority);
  1183. return;
  1184. }
  1185. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1186. if (!dcbx_info)
  1187. return;
  1188. *setting = dcbx_info->operational.params.pfc.prio[priority];
  1189. DP_VERBOSE(hwfn, QED_MSG_DCB, "setting = %d\n", *setting);
  1190. kfree(dcbx_info);
  1191. }
  1192. static void qed_dcbnl_setpfccfg(struct qed_dev *cdev, int priority, u8 setting)
  1193. {
  1194. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1195. struct qed_dcbx_set dcbx_set;
  1196. struct qed_ptt *ptt;
  1197. int rc;
  1198. DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d setting = %d\n",
  1199. priority, setting);
  1200. if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
  1201. DP_INFO(hwfn, "Invalid priority %d\n", priority);
  1202. return;
  1203. }
  1204. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1205. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1206. if (rc)
  1207. return;
  1208. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
  1209. dcbx_set.config.params.pfc.prio[priority] = !!setting;
  1210. ptt = qed_ptt_acquire(hwfn);
  1211. if (!ptt)
  1212. return;
  1213. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1214. qed_ptt_release(hwfn, ptt);
  1215. }
  1216. static u8 qed_dcbnl_getcap(struct qed_dev *cdev, int capid, u8 *cap)
  1217. {
  1218. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1219. struct qed_dcbx_get *dcbx_info;
  1220. int rc = 0;
  1221. DP_VERBOSE(hwfn, QED_MSG_DCB, "capid = %d\n", capid);
  1222. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1223. if (!dcbx_info)
  1224. return 1;
  1225. switch (capid) {
  1226. case DCB_CAP_ATTR_PG:
  1227. case DCB_CAP_ATTR_PFC:
  1228. case DCB_CAP_ATTR_UP2TC:
  1229. case DCB_CAP_ATTR_GSP:
  1230. *cap = true;
  1231. break;
  1232. case DCB_CAP_ATTR_PG_TCS:
  1233. case DCB_CAP_ATTR_PFC_TCS:
  1234. *cap = 0x80;
  1235. break;
  1236. case DCB_CAP_ATTR_DCBX:
  1237. *cap = (DCB_CAP_DCBX_LLD_MANAGED | DCB_CAP_DCBX_VER_CEE |
  1238. DCB_CAP_DCBX_VER_IEEE | DCB_CAP_DCBX_STATIC);
  1239. break;
  1240. default:
  1241. *cap = false;
  1242. rc = 1;
  1243. }
  1244. DP_VERBOSE(hwfn, QED_MSG_DCB, "id = %d caps = %d\n", capid, *cap);
  1245. kfree(dcbx_info);
  1246. return rc;
  1247. }
  1248. static int qed_dcbnl_getnumtcs(struct qed_dev *cdev, int tcid, u8 *num)
  1249. {
  1250. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1251. struct qed_dcbx_get *dcbx_info;
  1252. int rc = 0;
  1253. DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d\n", tcid);
  1254. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1255. if (!dcbx_info)
  1256. return -EINVAL;
  1257. switch (tcid) {
  1258. case DCB_NUMTCS_ATTR_PG:
  1259. *num = dcbx_info->operational.params.max_ets_tc;
  1260. break;
  1261. case DCB_NUMTCS_ATTR_PFC:
  1262. *num = dcbx_info->operational.params.pfc.max_tc;
  1263. break;
  1264. default:
  1265. rc = -EINVAL;
  1266. }
  1267. kfree(dcbx_info);
  1268. DP_VERBOSE(hwfn, QED_MSG_DCB, "numtcs = %d\n", *num);
  1269. return rc;
  1270. }
  1271. static u8 qed_dcbnl_getpfcstate(struct qed_dev *cdev)
  1272. {
  1273. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1274. struct qed_dcbx_get *dcbx_info;
  1275. bool enabled;
  1276. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1277. if (!dcbx_info)
  1278. return 0;
  1279. enabled = dcbx_info->operational.params.pfc.enabled;
  1280. DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d\n", enabled);
  1281. kfree(dcbx_info);
  1282. return enabled;
  1283. }
  1284. static u8 qed_dcbnl_getdcbx(struct qed_dev *cdev)
  1285. {
  1286. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1287. struct qed_dcbx_get *dcbx_info;
  1288. u8 mode = 0;
  1289. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1290. if (!dcbx_info)
  1291. return 0;
  1292. if (dcbx_info->operational.enabled)
  1293. mode |= DCB_CAP_DCBX_LLD_MANAGED;
  1294. if (dcbx_info->operational.ieee)
  1295. mode |= DCB_CAP_DCBX_VER_IEEE;
  1296. if (dcbx_info->operational.cee)
  1297. mode |= DCB_CAP_DCBX_VER_CEE;
  1298. if (dcbx_info->operational.local)
  1299. mode |= DCB_CAP_DCBX_STATIC;
  1300. DP_VERBOSE(hwfn, QED_MSG_DCB, "dcb mode = %d\n", mode);
  1301. kfree(dcbx_info);
  1302. return mode;
  1303. }
  1304. static void qed_dcbnl_setpgtccfgtx(struct qed_dev *cdev,
  1305. int tc,
  1306. u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
  1307. {
  1308. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1309. struct qed_dcbx_set dcbx_set;
  1310. struct qed_ptt *ptt;
  1311. int rc;
  1312. DP_VERBOSE(hwfn, QED_MSG_DCB,
  1313. "tc = %d pri_type = %d pgid = %d bw_pct = %d up_map = %d\n",
  1314. tc, pri_type, pgid, bw_pct, up_map);
  1315. if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
  1316. DP_INFO(hwfn, "Invalid tc %d\n", tc);
  1317. return;
  1318. }
  1319. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1320. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1321. if (rc)
  1322. return;
  1323. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
  1324. dcbx_set.config.params.ets_pri_tc_tbl[tc] = pgid;
  1325. ptt = qed_ptt_acquire(hwfn);
  1326. if (!ptt)
  1327. return;
  1328. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1329. qed_ptt_release(hwfn, ptt);
  1330. }
  1331. static void qed_dcbnl_setpgtccfgrx(struct qed_dev *cdev, int prio,
  1332. u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
  1333. {
  1334. DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
  1335. }
  1336. static void qed_dcbnl_setpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 bw_pct)
  1337. {
  1338. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1339. struct qed_dcbx_set dcbx_set;
  1340. struct qed_ptt *ptt;
  1341. int rc;
  1342. DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d bw_pct = %d\n", pgid, bw_pct);
  1343. if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
  1344. DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
  1345. return;
  1346. }
  1347. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1348. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1349. if (rc)
  1350. return;
  1351. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
  1352. dcbx_set.config.params.ets_tc_bw_tbl[pgid] = bw_pct;
  1353. ptt = qed_ptt_acquire(hwfn);
  1354. if (!ptt)
  1355. return;
  1356. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1357. qed_ptt_release(hwfn, ptt);
  1358. }
  1359. static void qed_dcbnl_setpgbwgcfgrx(struct qed_dev *cdev, int pgid, u8 bw_pct)
  1360. {
  1361. DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
  1362. }
  1363. static u8 qed_dcbnl_setall(struct qed_dev *cdev)
  1364. {
  1365. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1366. struct qed_dcbx_set dcbx_set;
  1367. struct qed_ptt *ptt;
  1368. int rc;
  1369. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1370. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1371. if (rc)
  1372. return 1;
  1373. ptt = qed_ptt_acquire(hwfn);
  1374. if (!ptt)
  1375. return 1;
  1376. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 1);
  1377. qed_ptt_release(hwfn, ptt);
  1378. return rc;
  1379. }
  1380. static int qed_dcbnl_setnumtcs(struct qed_dev *cdev, int tcid, u8 num)
  1381. {
  1382. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1383. struct qed_dcbx_set dcbx_set;
  1384. struct qed_ptt *ptt;
  1385. int rc;
  1386. DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d num = %d\n", tcid, num);
  1387. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1388. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1389. if (rc)
  1390. return 1;
  1391. switch (tcid) {
  1392. case DCB_NUMTCS_ATTR_PG:
  1393. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
  1394. dcbx_set.config.params.max_ets_tc = num;
  1395. break;
  1396. case DCB_NUMTCS_ATTR_PFC:
  1397. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
  1398. dcbx_set.config.params.pfc.max_tc = num;
  1399. break;
  1400. default:
  1401. DP_INFO(hwfn, "Invalid tcid %d\n", tcid);
  1402. return -EINVAL;
  1403. }
  1404. ptt = qed_ptt_acquire(hwfn);
  1405. if (!ptt)
  1406. return -EINVAL;
  1407. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1408. qed_ptt_release(hwfn, ptt);
  1409. return 0;
  1410. }
  1411. static void qed_dcbnl_setpfcstate(struct qed_dev *cdev, u8 state)
  1412. {
  1413. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1414. struct qed_dcbx_set dcbx_set;
  1415. struct qed_ptt *ptt;
  1416. int rc;
  1417. DP_VERBOSE(hwfn, QED_MSG_DCB, "new state = %d\n", state);
  1418. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1419. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1420. if (rc)
  1421. return;
  1422. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
  1423. dcbx_set.config.params.pfc.enabled = !!state;
  1424. ptt = qed_ptt_acquire(hwfn);
  1425. if (!ptt)
  1426. return;
  1427. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1428. qed_ptt_release(hwfn, ptt);
  1429. }
  1430. static int qed_dcbnl_getapp(struct qed_dev *cdev, u8 idtype, u16 idval)
  1431. {
  1432. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1433. struct qed_dcbx_get *dcbx_info;
  1434. struct qed_app_entry *entry;
  1435. bool ethtype;
  1436. u8 prio = 0;
  1437. int i;
  1438. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1439. if (!dcbx_info)
  1440. return -EINVAL;
  1441. ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
  1442. for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
  1443. entry = &dcbx_info->operational.params.app_entry[i];
  1444. if ((entry->ethtype == ethtype) && (entry->proto_id == idval)) {
  1445. prio = entry->prio;
  1446. break;
  1447. }
  1448. }
  1449. if (i == QED_DCBX_MAX_APP_PROTOCOL) {
  1450. DP_ERR(cdev, "App entry (%d, %d) not found\n", idtype, idval);
  1451. kfree(dcbx_info);
  1452. return -EINVAL;
  1453. }
  1454. kfree(dcbx_info);
  1455. return prio;
  1456. }
  1457. static int qed_dcbnl_setapp(struct qed_dev *cdev,
  1458. u8 idtype, u16 idval, u8 pri_map)
  1459. {
  1460. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1461. struct qed_dcbx_set dcbx_set;
  1462. struct qed_app_entry *entry;
  1463. struct qed_ptt *ptt;
  1464. bool ethtype;
  1465. int rc, i;
  1466. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1467. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1468. if (rc)
  1469. return -EINVAL;
  1470. ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
  1471. for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
  1472. entry = &dcbx_set.config.params.app_entry[i];
  1473. if ((entry->ethtype == ethtype) && (entry->proto_id == idval))
  1474. break;
  1475. /* First empty slot */
  1476. if (!entry->proto_id) {
  1477. dcbx_set.config.params.num_app_entries++;
  1478. break;
  1479. }
  1480. }
  1481. if (i == QED_DCBX_MAX_APP_PROTOCOL) {
  1482. DP_ERR(cdev, "App table is full\n");
  1483. return -EBUSY;
  1484. }
  1485. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
  1486. dcbx_set.config.params.app_entry[i].ethtype = ethtype;
  1487. dcbx_set.config.params.app_entry[i].proto_id = idval;
  1488. dcbx_set.config.params.app_entry[i].prio = pri_map;
  1489. ptt = qed_ptt_acquire(hwfn);
  1490. if (!ptt)
  1491. return -EBUSY;
  1492. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1493. qed_ptt_release(hwfn, ptt);
  1494. return rc;
  1495. }
  1496. static u8 qed_dcbnl_setdcbx(struct qed_dev *cdev, u8 mode)
  1497. {
  1498. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1499. struct qed_dcbx_set dcbx_set;
  1500. struct qed_ptt *ptt;
  1501. int rc;
  1502. DP_VERBOSE(hwfn, QED_MSG_DCB, "new mode = %x\n", mode);
  1503. if (!(mode & DCB_CAP_DCBX_VER_IEEE) &&
  1504. !(mode & DCB_CAP_DCBX_VER_CEE) && !(mode & DCB_CAP_DCBX_STATIC)) {
  1505. DP_INFO(hwfn, "Allowed modes are cee, ieee or static\n");
  1506. return 1;
  1507. }
  1508. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1509. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1510. if (rc)
  1511. return 1;
  1512. dcbx_set.ver_num = 0;
  1513. if (mode & DCB_CAP_DCBX_VER_CEE) {
  1514. dcbx_set.ver_num |= DCBX_CONFIG_VERSION_CEE;
  1515. dcbx_set.enabled = true;
  1516. }
  1517. if (mode & DCB_CAP_DCBX_VER_IEEE) {
  1518. dcbx_set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
  1519. dcbx_set.enabled = true;
  1520. }
  1521. if (mode & DCB_CAP_DCBX_STATIC) {
  1522. dcbx_set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
  1523. dcbx_set.enabled = true;
  1524. }
  1525. ptt = qed_ptt_acquire(hwfn);
  1526. if (!ptt)
  1527. return 1;
  1528. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1529. qed_ptt_release(hwfn, ptt);
  1530. return rc;
  1531. }
  1532. static u8 qed_dcbnl_getfeatcfg(struct qed_dev *cdev, int featid, u8 *flags)
  1533. {
  1534. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1535. struct qed_dcbx_get *dcbx_info;
  1536. DP_VERBOSE(hwfn, QED_MSG_DCB, "Feature id = %d\n", featid);
  1537. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1538. if (!dcbx_info)
  1539. return 1;
  1540. *flags = 0;
  1541. switch (featid) {
  1542. case DCB_FEATCFG_ATTR_PG:
  1543. if (dcbx_info->operational.params.ets_enabled)
  1544. *flags = DCB_FEATCFG_ENABLE;
  1545. else
  1546. *flags = DCB_FEATCFG_ERROR;
  1547. break;
  1548. case DCB_FEATCFG_ATTR_PFC:
  1549. if (dcbx_info->operational.params.pfc.enabled)
  1550. *flags = DCB_FEATCFG_ENABLE;
  1551. else
  1552. *flags = DCB_FEATCFG_ERROR;
  1553. break;
  1554. case DCB_FEATCFG_ATTR_APP:
  1555. if (dcbx_info->operational.params.app_valid)
  1556. *flags = DCB_FEATCFG_ENABLE;
  1557. else
  1558. *flags = DCB_FEATCFG_ERROR;
  1559. break;
  1560. default:
  1561. DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
  1562. kfree(dcbx_info);
  1563. return 1;
  1564. }
  1565. DP_VERBOSE(hwfn, QED_MSG_DCB, "flags = %d\n", *flags);
  1566. kfree(dcbx_info);
  1567. return 0;
  1568. }
  1569. static u8 qed_dcbnl_setfeatcfg(struct qed_dev *cdev, int featid, u8 flags)
  1570. {
  1571. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1572. struct qed_dcbx_set dcbx_set;
  1573. bool enabled, willing;
  1574. struct qed_ptt *ptt;
  1575. int rc;
  1576. DP_VERBOSE(hwfn, QED_MSG_DCB, "featid = %d flags = %d\n",
  1577. featid, flags);
  1578. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1579. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1580. if (rc)
  1581. return 1;
  1582. enabled = !!(flags & DCB_FEATCFG_ENABLE);
  1583. willing = !!(flags & DCB_FEATCFG_WILLING);
  1584. switch (featid) {
  1585. case DCB_FEATCFG_ATTR_PG:
  1586. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
  1587. dcbx_set.config.params.ets_enabled = enabled;
  1588. dcbx_set.config.params.ets_willing = willing;
  1589. break;
  1590. case DCB_FEATCFG_ATTR_PFC:
  1591. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
  1592. dcbx_set.config.params.pfc.enabled = enabled;
  1593. dcbx_set.config.params.pfc.willing = willing;
  1594. break;
  1595. case DCB_FEATCFG_ATTR_APP:
  1596. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
  1597. dcbx_set.config.params.app_willing = willing;
  1598. break;
  1599. default:
  1600. DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
  1601. return 1;
  1602. }
  1603. ptt = qed_ptt_acquire(hwfn);
  1604. if (!ptt)
  1605. return 1;
  1606. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1607. qed_ptt_release(hwfn, ptt);
  1608. return 0;
  1609. }
  1610. static int qed_dcbnl_peer_getappinfo(struct qed_dev *cdev,
  1611. struct dcb_peer_app_info *info,
  1612. u16 *app_count)
  1613. {
  1614. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1615. struct qed_dcbx_get *dcbx_info;
  1616. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
  1617. if (!dcbx_info)
  1618. return -EINVAL;
  1619. info->willing = dcbx_info->remote.params.app_willing;
  1620. info->error = dcbx_info->remote.params.app_error;
  1621. *app_count = dcbx_info->remote.params.num_app_entries;
  1622. kfree(dcbx_info);
  1623. return 0;
  1624. }
  1625. static int qed_dcbnl_peer_getapptable(struct qed_dev *cdev,
  1626. struct dcb_app *table)
  1627. {
  1628. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1629. struct qed_dcbx_get *dcbx_info;
  1630. int i;
  1631. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
  1632. if (!dcbx_info)
  1633. return -EINVAL;
  1634. for (i = 0; i < dcbx_info->remote.params.num_app_entries; i++) {
  1635. if (dcbx_info->remote.params.app_entry[i].ethtype)
  1636. table[i].selector = DCB_APP_IDTYPE_ETHTYPE;
  1637. else
  1638. table[i].selector = DCB_APP_IDTYPE_PORTNUM;
  1639. table[i].priority = dcbx_info->remote.params.app_entry[i].prio;
  1640. table[i].protocol =
  1641. dcbx_info->remote.params.app_entry[i].proto_id;
  1642. }
  1643. kfree(dcbx_info);
  1644. return 0;
  1645. }
  1646. static int qed_dcbnl_cee_peer_getpfc(struct qed_dev *cdev, struct cee_pfc *pfc)
  1647. {
  1648. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1649. struct qed_dcbx_get *dcbx_info;
  1650. int i;
  1651. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
  1652. if (!dcbx_info)
  1653. return -EINVAL;
  1654. for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
  1655. if (dcbx_info->remote.params.pfc.prio[i])
  1656. pfc->pfc_en |= BIT(i);
  1657. pfc->tcs_supported = dcbx_info->remote.params.pfc.max_tc;
  1658. DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d tcs_supported = %d\n",
  1659. pfc->pfc_en, pfc->tcs_supported);
  1660. kfree(dcbx_info);
  1661. return 0;
  1662. }
  1663. static int qed_dcbnl_cee_peer_getpg(struct qed_dev *cdev, struct cee_pg *pg)
  1664. {
  1665. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1666. struct qed_dcbx_get *dcbx_info;
  1667. int i;
  1668. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
  1669. if (!dcbx_info)
  1670. return -EINVAL;
  1671. pg->willing = dcbx_info->remote.params.ets_willing;
  1672. for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
  1673. pg->pg_bw[i] = dcbx_info->remote.params.ets_tc_bw_tbl[i];
  1674. pg->prio_pg[i] = dcbx_info->remote.params.ets_pri_tc_tbl[i];
  1675. }
  1676. DP_VERBOSE(hwfn, QED_MSG_DCB, "willing = %d", pg->willing);
  1677. kfree(dcbx_info);
  1678. return 0;
  1679. }
  1680. static int qed_dcbnl_get_ieee_pfc(struct qed_dev *cdev,
  1681. struct ieee_pfc *pfc, bool remote)
  1682. {
  1683. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1684. struct qed_dcbx_params *params;
  1685. struct qed_dcbx_get *dcbx_info;
  1686. int rc, i;
  1687. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1688. if (!dcbx_info)
  1689. return -EINVAL;
  1690. if (!dcbx_info->operational.ieee) {
  1691. DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
  1692. kfree(dcbx_info);
  1693. return -EINVAL;
  1694. }
  1695. if (remote) {
  1696. memset(dcbx_info, 0, sizeof(*dcbx_info));
  1697. rc = qed_dcbx_query_params(hwfn, dcbx_info,
  1698. QED_DCBX_REMOTE_MIB);
  1699. if (rc) {
  1700. kfree(dcbx_info);
  1701. return -EINVAL;
  1702. }
  1703. params = &dcbx_info->remote.params;
  1704. } else {
  1705. params = &dcbx_info->operational.params;
  1706. }
  1707. pfc->pfc_cap = params->pfc.max_tc;
  1708. pfc->pfc_en = 0;
  1709. for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
  1710. if (params->pfc.prio[i])
  1711. pfc->pfc_en |= BIT(i);
  1712. kfree(dcbx_info);
  1713. return 0;
  1714. }
  1715. static int qed_dcbnl_ieee_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
  1716. {
  1717. return qed_dcbnl_get_ieee_pfc(cdev, pfc, false);
  1718. }
  1719. static int qed_dcbnl_ieee_setpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
  1720. {
  1721. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1722. struct qed_dcbx_get *dcbx_info;
  1723. struct qed_dcbx_set dcbx_set;
  1724. struct qed_ptt *ptt;
  1725. int rc, i;
  1726. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1727. if (!dcbx_info)
  1728. return -EINVAL;
  1729. if (!dcbx_info->operational.ieee) {
  1730. DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
  1731. kfree(dcbx_info);
  1732. return -EINVAL;
  1733. }
  1734. kfree(dcbx_info);
  1735. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1736. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1737. if (rc)
  1738. return -EINVAL;
  1739. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
  1740. for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
  1741. dcbx_set.config.params.pfc.prio[i] = !!(pfc->pfc_en & BIT(i));
  1742. dcbx_set.config.params.pfc.max_tc = pfc->pfc_cap;
  1743. ptt = qed_ptt_acquire(hwfn);
  1744. if (!ptt)
  1745. return -EINVAL;
  1746. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1747. qed_ptt_release(hwfn, ptt);
  1748. return rc;
  1749. }
  1750. static int qed_dcbnl_get_ieee_ets(struct qed_dev *cdev,
  1751. struct ieee_ets *ets, bool remote)
  1752. {
  1753. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1754. struct qed_dcbx_get *dcbx_info;
  1755. struct qed_dcbx_params *params;
  1756. int rc;
  1757. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1758. if (!dcbx_info)
  1759. return -EINVAL;
  1760. if (!dcbx_info->operational.ieee) {
  1761. DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
  1762. kfree(dcbx_info);
  1763. return -EINVAL;
  1764. }
  1765. if (remote) {
  1766. memset(dcbx_info, 0, sizeof(*dcbx_info));
  1767. rc = qed_dcbx_query_params(hwfn, dcbx_info,
  1768. QED_DCBX_REMOTE_MIB);
  1769. if (rc) {
  1770. kfree(dcbx_info);
  1771. return -EINVAL;
  1772. }
  1773. params = &dcbx_info->remote.params;
  1774. } else {
  1775. params = &dcbx_info->operational.params;
  1776. }
  1777. ets->ets_cap = params->max_ets_tc;
  1778. ets->willing = params->ets_willing;
  1779. ets->cbs = params->ets_cbs;
  1780. memcpy(ets->tc_tx_bw, params->ets_tc_bw_tbl, sizeof(ets->tc_tx_bw));
  1781. memcpy(ets->tc_tsa, params->ets_tc_tsa_tbl, sizeof(ets->tc_tsa));
  1782. memcpy(ets->prio_tc, params->ets_pri_tc_tbl, sizeof(ets->prio_tc));
  1783. kfree(dcbx_info);
  1784. return 0;
  1785. }
  1786. static int qed_dcbnl_ieee_getets(struct qed_dev *cdev, struct ieee_ets *ets)
  1787. {
  1788. return qed_dcbnl_get_ieee_ets(cdev, ets, false);
  1789. }
  1790. static int qed_dcbnl_ieee_setets(struct qed_dev *cdev, struct ieee_ets *ets)
  1791. {
  1792. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1793. struct qed_dcbx_get *dcbx_info;
  1794. struct qed_dcbx_set dcbx_set;
  1795. struct qed_ptt *ptt;
  1796. int rc;
  1797. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1798. if (!dcbx_info)
  1799. return -EINVAL;
  1800. if (!dcbx_info->operational.ieee) {
  1801. DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
  1802. kfree(dcbx_info);
  1803. return -EINVAL;
  1804. }
  1805. kfree(dcbx_info);
  1806. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1807. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1808. if (rc)
  1809. return -EINVAL;
  1810. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
  1811. dcbx_set.config.params.max_ets_tc = ets->ets_cap;
  1812. dcbx_set.config.params.ets_willing = ets->willing;
  1813. dcbx_set.config.params.ets_cbs = ets->cbs;
  1814. memcpy(dcbx_set.config.params.ets_tc_bw_tbl, ets->tc_tx_bw,
  1815. sizeof(ets->tc_tx_bw));
  1816. memcpy(dcbx_set.config.params.ets_tc_tsa_tbl, ets->tc_tsa,
  1817. sizeof(ets->tc_tsa));
  1818. memcpy(dcbx_set.config.params.ets_pri_tc_tbl, ets->prio_tc,
  1819. sizeof(ets->prio_tc));
  1820. ptt = qed_ptt_acquire(hwfn);
  1821. if (!ptt)
  1822. return -EINVAL;
  1823. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1824. qed_ptt_release(hwfn, ptt);
  1825. return rc;
  1826. }
  1827. static int
  1828. qed_dcbnl_ieee_peer_getets(struct qed_dev *cdev, struct ieee_ets *ets)
  1829. {
  1830. return qed_dcbnl_get_ieee_ets(cdev, ets, true);
  1831. }
  1832. static int
  1833. qed_dcbnl_ieee_peer_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
  1834. {
  1835. return qed_dcbnl_get_ieee_pfc(cdev, pfc, true);
  1836. }
  1837. static int qed_get_sf_ieee_value(u8 selector, u8 *sf_ieee)
  1838. {
  1839. switch (selector) {
  1840. case IEEE_8021QAZ_APP_SEL_ETHERTYPE:
  1841. *sf_ieee = QED_DCBX_SF_IEEE_ETHTYPE;
  1842. break;
  1843. case IEEE_8021QAZ_APP_SEL_STREAM:
  1844. *sf_ieee = QED_DCBX_SF_IEEE_TCP_PORT;
  1845. break;
  1846. case IEEE_8021QAZ_APP_SEL_DGRAM:
  1847. *sf_ieee = QED_DCBX_SF_IEEE_UDP_PORT;
  1848. break;
  1849. case IEEE_8021QAZ_APP_SEL_ANY:
  1850. *sf_ieee = QED_DCBX_SF_IEEE_TCP_UDP_PORT;
  1851. break;
  1852. default:
  1853. return -EINVAL;
  1854. }
  1855. return 0;
  1856. }
  1857. static int qed_dcbnl_ieee_getapp(struct qed_dev *cdev, struct dcb_app *app)
  1858. {
  1859. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1860. struct qed_dcbx_get *dcbx_info;
  1861. struct qed_app_entry *entry;
  1862. u8 prio = 0;
  1863. u8 sf_ieee;
  1864. int i;
  1865. DP_VERBOSE(hwfn, QED_MSG_DCB, "selector = %d protocol = %d\n",
  1866. app->selector, app->protocol);
  1867. if (qed_get_sf_ieee_value(app->selector, &sf_ieee)) {
  1868. DP_INFO(cdev, "Invalid selector field value %d\n",
  1869. app->selector);
  1870. return -EINVAL;
  1871. }
  1872. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1873. if (!dcbx_info)
  1874. return -EINVAL;
  1875. if (!dcbx_info->operational.ieee) {
  1876. DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
  1877. kfree(dcbx_info);
  1878. return -EINVAL;
  1879. }
  1880. for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
  1881. entry = &dcbx_info->operational.params.app_entry[i];
  1882. if ((entry->sf_ieee == sf_ieee) &&
  1883. (entry->proto_id == app->protocol)) {
  1884. prio = entry->prio;
  1885. break;
  1886. }
  1887. }
  1888. if (i == QED_DCBX_MAX_APP_PROTOCOL) {
  1889. DP_ERR(cdev, "App entry (%d, %d) not found\n", app->selector,
  1890. app->protocol);
  1891. kfree(dcbx_info);
  1892. return -EINVAL;
  1893. }
  1894. app->priority = ffs(prio) - 1;
  1895. kfree(dcbx_info);
  1896. return 0;
  1897. }
  1898. static int qed_dcbnl_ieee_setapp(struct qed_dev *cdev, struct dcb_app *app)
  1899. {
  1900. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1901. struct qed_dcbx_get *dcbx_info;
  1902. struct qed_dcbx_set dcbx_set;
  1903. struct qed_app_entry *entry;
  1904. struct qed_ptt *ptt;
  1905. u8 sf_ieee;
  1906. int rc, i;
  1907. DP_VERBOSE(hwfn, QED_MSG_DCB, "selector = %d protocol = %d pri = %d\n",
  1908. app->selector, app->protocol, app->priority);
  1909. if (app->priority >= QED_MAX_PFC_PRIORITIES) {
  1910. DP_INFO(hwfn, "Invalid priority %d\n", app->priority);
  1911. return -EINVAL;
  1912. }
  1913. if (qed_get_sf_ieee_value(app->selector, &sf_ieee)) {
  1914. DP_INFO(cdev, "Invalid selector field value %d\n",
  1915. app->selector);
  1916. return -EINVAL;
  1917. }
  1918. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1919. if (!dcbx_info)
  1920. return -EINVAL;
  1921. if (!dcbx_info->operational.ieee) {
  1922. DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
  1923. kfree(dcbx_info);
  1924. return -EINVAL;
  1925. }
  1926. kfree(dcbx_info);
  1927. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1928. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1929. if (rc)
  1930. return -EINVAL;
  1931. for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
  1932. entry = &dcbx_set.config.params.app_entry[i];
  1933. if ((entry->sf_ieee == sf_ieee) &&
  1934. (entry->proto_id == app->protocol))
  1935. break;
  1936. /* First empty slot */
  1937. if (!entry->proto_id) {
  1938. dcbx_set.config.params.num_app_entries++;
  1939. break;
  1940. }
  1941. }
  1942. if (i == QED_DCBX_MAX_APP_PROTOCOL) {
  1943. DP_ERR(cdev, "App table is full\n");
  1944. return -EBUSY;
  1945. }
  1946. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
  1947. dcbx_set.config.params.app_entry[i].sf_ieee = sf_ieee;
  1948. dcbx_set.config.params.app_entry[i].proto_id = app->protocol;
  1949. dcbx_set.config.params.app_entry[i].prio = BIT(app->priority);
  1950. ptt = qed_ptt_acquire(hwfn);
  1951. if (!ptt)
  1952. return -EBUSY;
  1953. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1954. qed_ptt_release(hwfn, ptt);
  1955. return rc;
  1956. }
  1957. const struct qed_eth_dcbnl_ops qed_dcbnl_ops_pass = {
  1958. .getstate = qed_dcbnl_getstate,
  1959. .setstate = qed_dcbnl_setstate,
  1960. .getpgtccfgtx = qed_dcbnl_getpgtccfgtx,
  1961. .getpgbwgcfgtx = qed_dcbnl_getpgbwgcfgtx,
  1962. .getpgtccfgrx = qed_dcbnl_getpgtccfgrx,
  1963. .getpgbwgcfgrx = qed_dcbnl_getpgbwgcfgrx,
  1964. .getpfccfg = qed_dcbnl_getpfccfg,
  1965. .setpfccfg = qed_dcbnl_setpfccfg,
  1966. .getcap = qed_dcbnl_getcap,
  1967. .getnumtcs = qed_dcbnl_getnumtcs,
  1968. .getpfcstate = qed_dcbnl_getpfcstate,
  1969. .getdcbx = qed_dcbnl_getdcbx,
  1970. .setpgtccfgtx = qed_dcbnl_setpgtccfgtx,
  1971. .setpgtccfgrx = qed_dcbnl_setpgtccfgrx,
  1972. .setpgbwgcfgtx = qed_dcbnl_setpgbwgcfgtx,
  1973. .setpgbwgcfgrx = qed_dcbnl_setpgbwgcfgrx,
  1974. .setall = qed_dcbnl_setall,
  1975. .setnumtcs = qed_dcbnl_setnumtcs,
  1976. .setpfcstate = qed_dcbnl_setpfcstate,
  1977. .setapp = qed_dcbnl_setapp,
  1978. .setdcbx = qed_dcbnl_setdcbx,
  1979. .setfeatcfg = qed_dcbnl_setfeatcfg,
  1980. .getfeatcfg = qed_dcbnl_getfeatcfg,
  1981. .getapp = qed_dcbnl_getapp,
  1982. .peer_getappinfo = qed_dcbnl_peer_getappinfo,
  1983. .peer_getapptable = qed_dcbnl_peer_getapptable,
  1984. .cee_peer_getpfc = qed_dcbnl_cee_peer_getpfc,
  1985. .cee_peer_getpg = qed_dcbnl_cee_peer_getpg,
  1986. .ieee_getpfc = qed_dcbnl_ieee_getpfc,
  1987. .ieee_setpfc = qed_dcbnl_ieee_setpfc,
  1988. .ieee_getets = qed_dcbnl_ieee_getets,
  1989. .ieee_setets = qed_dcbnl_ieee_setets,
  1990. .ieee_peer_getpfc = qed_dcbnl_ieee_peer_getpfc,
  1991. .ieee_peer_getets = qed_dcbnl_ieee_peer_getets,
  1992. .ieee_getapp = qed_dcbnl_ieee_getapp,
  1993. .ieee_setapp = qed_dcbnl_ieee_setapp,
  1994. };
  1995. #endif