qed_dcbx.c 61 KB

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