qed_dcbx.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311
  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. memset(dcbx_info, 0, sizeof(*dcbx_info));
  1012. rc = qed_dcbx_query_params(p_hwfn, dcbx_info, QED_DCBX_OPERATIONAL_MIB);
  1013. if (rc) {
  1014. kfree(dcbx_info);
  1015. return rc;
  1016. }
  1017. p_hwfn->p_dcbx_info->set.override_flags = 0;
  1018. p_hwfn->p_dcbx_info->set.ver_num = DCBX_CONFIG_VERSION_DISABLED;
  1019. if (dcbx_info->operational.cee)
  1020. p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_CEE;
  1021. if (dcbx_info->operational.ieee)
  1022. p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
  1023. p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled;
  1024. memcpy(&p_hwfn->p_dcbx_info->set.config.params,
  1025. &dcbx_info->operational.params,
  1026. sizeof(struct qed_dcbx_admin_params));
  1027. p_hwfn->p_dcbx_info->set.config.valid = true;
  1028. memcpy(params, &p_hwfn->p_dcbx_info->set, sizeof(struct qed_dcbx_set));
  1029. kfree(dcbx_info);
  1030. return 0;
  1031. }
  1032. static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn,
  1033. enum qed_mib_read_type type)
  1034. {
  1035. struct qed_dcbx_get *dcbx_info;
  1036. dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_KERNEL);
  1037. if (!dcbx_info)
  1038. return NULL;
  1039. memset(dcbx_info, 0, sizeof(*dcbx_info));
  1040. if (qed_dcbx_query_params(hwfn, dcbx_info, type)) {
  1041. kfree(dcbx_info);
  1042. return NULL;
  1043. }
  1044. if ((type == QED_DCBX_OPERATIONAL_MIB) &&
  1045. !dcbx_info->operational.enabled) {
  1046. DP_INFO(hwfn, "DCBX is not enabled/operational\n");
  1047. kfree(dcbx_info);
  1048. return NULL;
  1049. }
  1050. return dcbx_info;
  1051. }
  1052. static u8 qed_dcbnl_getstate(struct qed_dev *cdev)
  1053. {
  1054. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1055. struct qed_dcbx_get *dcbx_info;
  1056. bool enabled;
  1057. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1058. if (!dcbx_info)
  1059. return 0;
  1060. enabled = dcbx_info->operational.enabled;
  1061. DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", enabled);
  1062. kfree(dcbx_info);
  1063. return enabled;
  1064. }
  1065. static u8 qed_dcbnl_setstate(struct qed_dev *cdev, u8 state)
  1066. {
  1067. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1068. struct qed_dcbx_set dcbx_set;
  1069. struct qed_ptt *ptt;
  1070. int rc;
  1071. DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", state);
  1072. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1073. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1074. if (rc)
  1075. return 1;
  1076. dcbx_set.enabled = !!state;
  1077. ptt = qed_ptt_acquire(hwfn);
  1078. if (!ptt)
  1079. return 1;
  1080. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1081. qed_ptt_release(hwfn, ptt);
  1082. return rc ? 1 : 0;
  1083. }
  1084. static void qed_dcbnl_getpgtccfgtx(struct qed_dev *cdev, int tc, u8 *prio_type,
  1085. u8 *pgid, u8 *bw_pct, u8 *up_map)
  1086. {
  1087. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1088. struct qed_dcbx_get *dcbx_info;
  1089. DP_VERBOSE(hwfn, QED_MSG_DCB, "tc = %d\n", tc);
  1090. *prio_type = *pgid = *bw_pct = *up_map = 0;
  1091. if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
  1092. DP_INFO(hwfn, "Invalid tc %d\n", tc);
  1093. return;
  1094. }
  1095. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1096. if (!dcbx_info)
  1097. return;
  1098. *pgid = dcbx_info->operational.params.ets_pri_tc_tbl[tc];
  1099. kfree(dcbx_info);
  1100. }
  1101. static void qed_dcbnl_getpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 *bw_pct)
  1102. {
  1103. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1104. struct qed_dcbx_get *dcbx_info;
  1105. *bw_pct = 0;
  1106. DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d\n", pgid);
  1107. if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
  1108. DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
  1109. return;
  1110. }
  1111. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1112. if (!dcbx_info)
  1113. return;
  1114. *bw_pct = dcbx_info->operational.params.ets_tc_bw_tbl[pgid];
  1115. DP_VERBOSE(hwfn, QED_MSG_DCB, "bw_pct = %d\n", *bw_pct);
  1116. kfree(dcbx_info);
  1117. }
  1118. static void qed_dcbnl_getpgtccfgrx(struct qed_dev *cdev, int tc, u8 *prio,
  1119. u8 *bwg_id, u8 *bw_pct, u8 *up_map)
  1120. {
  1121. DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
  1122. *prio = *bwg_id = *bw_pct = *up_map = 0;
  1123. }
  1124. static void qed_dcbnl_getpgbwgcfgrx(struct qed_dev *cdev,
  1125. int bwg_id, u8 *bw_pct)
  1126. {
  1127. DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
  1128. *bw_pct = 0;
  1129. }
  1130. static void qed_dcbnl_getpfccfg(struct qed_dev *cdev,
  1131. int priority, u8 *setting)
  1132. {
  1133. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1134. struct qed_dcbx_get *dcbx_info;
  1135. DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d\n", priority);
  1136. if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
  1137. DP_INFO(hwfn, "Invalid priority %d\n", priority);
  1138. return;
  1139. }
  1140. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1141. if (!dcbx_info)
  1142. return;
  1143. *setting = dcbx_info->operational.params.pfc.prio[priority];
  1144. DP_VERBOSE(hwfn, QED_MSG_DCB, "setting = %d\n", *setting);
  1145. kfree(dcbx_info);
  1146. }
  1147. static void qed_dcbnl_setpfccfg(struct qed_dev *cdev, int priority, u8 setting)
  1148. {
  1149. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1150. struct qed_dcbx_set dcbx_set;
  1151. struct qed_ptt *ptt;
  1152. int rc;
  1153. DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d setting = %d\n",
  1154. priority, setting);
  1155. if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
  1156. DP_INFO(hwfn, "Invalid priority %d\n", priority);
  1157. return;
  1158. }
  1159. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1160. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1161. if (rc)
  1162. return;
  1163. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
  1164. dcbx_set.config.params.pfc.prio[priority] = !!setting;
  1165. ptt = qed_ptt_acquire(hwfn);
  1166. if (!ptt)
  1167. return;
  1168. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1169. qed_ptt_release(hwfn, ptt);
  1170. }
  1171. static u8 qed_dcbnl_getcap(struct qed_dev *cdev, int capid, u8 *cap)
  1172. {
  1173. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1174. struct qed_dcbx_get *dcbx_info;
  1175. int rc = 0;
  1176. DP_VERBOSE(hwfn, QED_MSG_DCB, "capid = %d\n", capid);
  1177. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1178. if (!dcbx_info)
  1179. return 1;
  1180. switch (capid) {
  1181. case DCB_CAP_ATTR_PG:
  1182. case DCB_CAP_ATTR_PFC:
  1183. case DCB_CAP_ATTR_UP2TC:
  1184. case DCB_CAP_ATTR_GSP:
  1185. *cap = true;
  1186. break;
  1187. case DCB_CAP_ATTR_PG_TCS:
  1188. case DCB_CAP_ATTR_PFC_TCS:
  1189. *cap = 0x80;
  1190. break;
  1191. case DCB_CAP_ATTR_DCBX:
  1192. *cap = (DCB_CAP_DCBX_LLD_MANAGED | DCB_CAP_DCBX_VER_CEE |
  1193. DCB_CAP_DCBX_VER_IEEE);
  1194. break;
  1195. default:
  1196. *cap = false;
  1197. rc = 1;
  1198. }
  1199. DP_VERBOSE(hwfn, QED_MSG_DCB, "id = %d caps = %d\n", capid, *cap);
  1200. kfree(dcbx_info);
  1201. return rc;
  1202. }
  1203. static int qed_dcbnl_getnumtcs(struct qed_dev *cdev, int tcid, u8 *num)
  1204. {
  1205. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1206. struct qed_dcbx_get *dcbx_info;
  1207. int rc = 0;
  1208. DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d\n", tcid);
  1209. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1210. if (!dcbx_info)
  1211. return -EINVAL;
  1212. switch (tcid) {
  1213. case DCB_NUMTCS_ATTR_PG:
  1214. *num = dcbx_info->operational.params.max_ets_tc;
  1215. break;
  1216. case DCB_NUMTCS_ATTR_PFC:
  1217. *num = dcbx_info->operational.params.pfc.max_tc;
  1218. break;
  1219. default:
  1220. rc = -EINVAL;
  1221. }
  1222. kfree(dcbx_info);
  1223. DP_VERBOSE(hwfn, QED_MSG_DCB, "numtcs = %d\n", *num);
  1224. return rc;
  1225. }
  1226. static u8 qed_dcbnl_getpfcstate(struct qed_dev *cdev)
  1227. {
  1228. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1229. struct qed_dcbx_get *dcbx_info;
  1230. bool enabled;
  1231. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1232. if (!dcbx_info)
  1233. return 0;
  1234. enabled = dcbx_info->operational.params.pfc.enabled;
  1235. DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d\n", enabled);
  1236. kfree(dcbx_info);
  1237. return enabled;
  1238. }
  1239. static u8 qed_dcbnl_getdcbx(struct qed_dev *cdev)
  1240. {
  1241. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1242. struct qed_dcbx_get *dcbx_info;
  1243. u8 mode = 0;
  1244. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1245. if (!dcbx_info)
  1246. return 0;
  1247. if (dcbx_info->operational.enabled)
  1248. mode |= DCB_CAP_DCBX_LLD_MANAGED;
  1249. if (dcbx_info->operational.ieee)
  1250. mode |= DCB_CAP_DCBX_VER_IEEE;
  1251. if (dcbx_info->operational.cee)
  1252. mode |= DCB_CAP_DCBX_VER_CEE;
  1253. DP_VERBOSE(hwfn, QED_MSG_DCB, "dcb mode = %d\n", mode);
  1254. kfree(dcbx_info);
  1255. return mode;
  1256. }
  1257. static void qed_dcbnl_setpgtccfgtx(struct qed_dev *cdev,
  1258. int tc,
  1259. u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
  1260. {
  1261. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1262. struct qed_dcbx_set dcbx_set;
  1263. struct qed_ptt *ptt;
  1264. int rc;
  1265. DP_VERBOSE(hwfn, QED_MSG_DCB,
  1266. "tc = %d pri_type = %d pgid = %d bw_pct = %d up_map = %d\n",
  1267. tc, pri_type, pgid, bw_pct, up_map);
  1268. if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
  1269. DP_INFO(hwfn, "Invalid tc %d\n", tc);
  1270. return;
  1271. }
  1272. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1273. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1274. if (rc)
  1275. return;
  1276. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
  1277. dcbx_set.config.params.ets_pri_tc_tbl[tc] = pgid;
  1278. ptt = qed_ptt_acquire(hwfn);
  1279. if (!ptt)
  1280. return;
  1281. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1282. qed_ptt_release(hwfn, ptt);
  1283. }
  1284. static void qed_dcbnl_setpgtccfgrx(struct qed_dev *cdev, int prio,
  1285. u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
  1286. {
  1287. DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
  1288. }
  1289. static void qed_dcbnl_setpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 bw_pct)
  1290. {
  1291. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1292. struct qed_dcbx_set dcbx_set;
  1293. struct qed_ptt *ptt;
  1294. int rc;
  1295. DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d bw_pct = %d\n", pgid, bw_pct);
  1296. if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
  1297. DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
  1298. return;
  1299. }
  1300. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1301. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1302. if (rc)
  1303. return;
  1304. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
  1305. dcbx_set.config.params.ets_tc_bw_tbl[pgid] = bw_pct;
  1306. ptt = qed_ptt_acquire(hwfn);
  1307. if (!ptt)
  1308. return;
  1309. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1310. qed_ptt_release(hwfn, ptt);
  1311. }
  1312. static void qed_dcbnl_setpgbwgcfgrx(struct qed_dev *cdev, int pgid, u8 bw_pct)
  1313. {
  1314. DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
  1315. }
  1316. static u8 qed_dcbnl_setall(struct qed_dev *cdev)
  1317. {
  1318. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1319. struct qed_dcbx_set dcbx_set;
  1320. struct qed_ptt *ptt;
  1321. int rc;
  1322. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1323. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1324. if (rc)
  1325. return 1;
  1326. ptt = qed_ptt_acquire(hwfn);
  1327. if (!ptt)
  1328. return 1;
  1329. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 1);
  1330. qed_ptt_release(hwfn, ptt);
  1331. return rc;
  1332. }
  1333. static int qed_dcbnl_setnumtcs(struct qed_dev *cdev, int tcid, u8 num)
  1334. {
  1335. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1336. struct qed_dcbx_set dcbx_set;
  1337. struct qed_ptt *ptt;
  1338. int rc;
  1339. DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d num = %d\n", tcid, num);
  1340. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1341. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1342. if (rc)
  1343. return 1;
  1344. switch (tcid) {
  1345. case DCB_NUMTCS_ATTR_PG:
  1346. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
  1347. dcbx_set.config.params.max_ets_tc = num;
  1348. break;
  1349. case DCB_NUMTCS_ATTR_PFC:
  1350. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
  1351. dcbx_set.config.params.pfc.max_tc = num;
  1352. break;
  1353. default:
  1354. DP_INFO(hwfn, "Invalid tcid %d\n", tcid);
  1355. return -EINVAL;
  1356. }
  1357. ptt = qed_ptt_acquire(hwfn);
  1358. if (!ptt)
  1359. return -EINVAL;
  1360. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1361. qed_ptt_release(hwfn, ptt);
  1362. return 0;
  1363. }
  1364. static void qed_dcbnl_setpfcstate(struct qed_dev *cdev, u8 state)
  1365. {
  1366. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1367. struct qed_dcbx_set dcbx_set;
  1368. struct qed_ptt *ptt;
  1369. int rc;
  1370. DP_VERBOSE(hwfn, QED_MSG_DCB, "new state = %d\n", state);
  1371. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1372. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1373. if (rc)
  1374. return;
  1375. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
  1376. dcbx_set.config.params.pfc.enabled = !!state;
  1377. ptt = qed_ptt_acquire(hwfn);
  1378. if (!ptt)
  1379. return;
  1380. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1381. qed_ptt_release(hwfn, ptt);
  1382. }
  1383. static int qed_dcbnl_getapp(struct qed_dev *cdev, u8 idtype, u16 idval)
  1384. {
  1385. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1386. struct qed_dcbx_get *dcbx_info;
  1387. struct qed_app_entry *entry;
  1388. bool ethtype;
  1389. u8 prio = 0;
  1390. int i;
  1391. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1392. if (!dcbx_info)
  1393. return -EINVAL;
  1394. ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
  1395. for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
  1396. entry = &dcbx_info->operational.params.app_entry[i];
  1397. if ((entry->ethtype == ethtype) && (entry->proto_id == idval)) {
  1398. prio = entry->prio;
  1399. break;
  1400. }
  1401. }
  1402. if (i == QED_DCBX_MAX_APP_PROTOCOL) {
  1403. DP_ERR(cdev, "App entry (%d, %d) not found\n", idtype, idval);
  1404. kfree(dcbx_info);
  1405. return -EINVAL;
  1406. }
  1407. kfree(dcbx_info);
  1408. return prio;
  1409. }
  1410. static int qed_dcbnl_setapp(struct qed_dev *cdev,
  1411. u8 idtype, u16 idval, u8 pri_map)
  1412. {
  1413. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1414. struct qed_dcbx_set dcbx_set;
  1415. struct qed_app_entry *entry;
  1416. struct qed_ptt *ptt;
  1417. bool ethtype;
  1418. int rc, i;
  1419. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1420. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1421. if (rc)
  1422. return -EINVAL;
  1423. ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
  1424. for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
  1425. entry = &dcbx_set.config.params.app_entry[i];
  1426. if ((entry->ethtype == ethtype) && (entry->proto_id == idval))
  1427. break;
  1428. /* First empty slot */
  1429. if (!entry->proto_id) {
  1430. dcbx_set.config.params.num_app_entries++;
  1431. break;
  1432. }
  1433. }
  1434. if (i == QED_DCBX_MAX_APP_PROTOCOL) {
  1435. DP_ERR(cdev, "App table is full\n");
  1436. return -EBUSY;
  1437. }
  1438. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
  1439. dcbx_set.config.params.app_entry[i].ethtype = ethtype;
  1440. dcbx_set.config.params.app_entry[i].proto_id = idval;
  1441. dcbx_set.config.params.app_entry[i].prio = pri_map;
  1442. ptt = qed_ptt_acquire(hwfn);
  1443. if (!ptt)
  1444. return -EBUSY;
  1445. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1446. qed_ptt_release(hwfn, ptt);
  1447. return rc;
  1448. }
  1449. static u8 qed_dcbnl_setdcbx(struct qed_dev *cdev, u8 mode)
  1450. {
  1451. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1452. struct qed_dcbx_set dcbx_set;
  1453. struct qed_ptt *ptt;
  1454. int rc;
  1455. DP_VERBOSE(hwfn, QED_MSG_DCB, "new mode = %x\n", mode);
  1456. if (!(mode & DCB_CAP_DCBX_VER_IEEE) && !(mode & DCB_CAP_DCBX_VER_CEE)) {
  1457. DP_INFO(hwfn, "Allowed mode is cee, ieee or both\n");
  1458. return 1;
  1459. }
  1460. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1461. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1462. if (rc)
  1463. return 1;
  1464. dcbx_set.ver_num = 0;
  1465. if (mode & DCB_CAP_DCBX_VER_CEE) {
  1466. dcbx_set.ver_num |= DCBX_CONFIG_VERSION_CEE;
  1467. dcbx_set.enabled = true;
  1468. }
  1469. if (mode & DCB_CAP_DCBX_VER_IEEE) {
  1470. dcbx_set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
  1471. dcbx_set.enabled = true;
  1472. }
  1473. ptt = qed_ptt_acquire(hwfn);
  1474. if (!ptt)
  1475. return 1;
  1476. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1477. qed_ptt_release(hwfn, ptt);
  1478. return 0;
  1479. }
  1480. static u8 qed_dcbnl_getfeatcfg(struct qed_dev *cdev, int featid, u8 *flags)
  1481. {
  1482. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1483. struct qed_dcbx_get *dcbx_info;
  1484. DP_VERBOSE(hwfn, QED_MSG_DCB, "Feature id = %d\n", featid);
  1485. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1486. if (!dcbx_info)
  1487. return 1;
  1488. *flags = 0;
  1489. switch (featid) {
  1490. case DCB_FEATCFG_ATTR_PG:
  1491. if (dcbx_info->operational.params.ets_enabled)
  1492. *flags = DCB_FEATCFG_ENABLE;
  1493. else
  1494. *flags = DCB_FEATCFG_ERROR;
  1495. break;
  1496. case DCB_FEATCFG_ATTR_PFC:
  1497. if (dcbx_info->operational.params.pfc.enabled)
  1498. *flags = DCB_FEATCFG_ENABLE;
  1499. else
  1500. *flags = DCB_FEATCFG_ERROR;
  1501. break;
  1502. case DCB_FEATCFG_ATTR_APP:
  1503. if (dcbx_info->operational.params.app_valid)
  1504. *flags = DCB_FEATCFG_ENABLE;
  1505. else
  1506. *flags = DCB_FEATCFG_ERROR;
  1507. break;
  1508. default:
  1509. DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
  1510. kfree(dcbx_info);
  1511. return 1;
  1512. }
  1513. DP_VERBOSE(hwfn, QED_MSG_DCB, "flags = %d\n", *flags);
  1514. kfree(dcbx_info);
  1515. return 0;
  1516. }
  1517. static u8 qed_dcbnl_setfeatcfg(struct qed_dev *cdev, int featid, u8 flags)
  1518. {
  1519. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1520. struct qed_dcbx_set dcbx_set;
  1521. bool enabled, willing;
  1522. struct qed_ptt *ptt;
  1523. int rc;
  1524. DP_VERBOSE(hwfn, QED_MSG_DCB, "featid = %d flags = %d\n",
  1525. featid, flags);
  1526. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1527. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1528. if (rc)
  1529. return 1;
  1530. enabled = !!(flags & DCB_FEATCFG_ENABLE);
  1531. willing = !!(flags & DCB_FEATCFG_WILLING);
  1532. switch (featid) {
  1533. case DCB_FEATCFG_ATTR_PG:
  1534. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
  1535. dcbx_set.config.params.ets_enabled = enabled;
  1536. dcbx_set.config.params.ets_willing = willing;
  1537. break;
  1538. case DCB_FEATCFG_ATTR_PFC:
  1539. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
  1540. dcbx_set.config.params.pfc.enabled = enabled;
  1541. dcbx_set.config.params.pfc.willing = willing;
  1542. break;
  1543. case DCB_FEATCFG_ATTR_APP:
  1544. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
  1545. dcbx_set.config.params.app_willing = willing;
  1546. break;
  1547. default:
  1548. DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
  1549. return 1;
  1550. }
  1551. ptt = qed_ptt_acquire(hwfn);
  1552. if (!ptt)
  1553. return 1;
  1554. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1555. qed_ptt_release(hwfn, ptt);
  1556. return 0;
  1557. }
  1558. static int qed_dcbnl_peer_getappinfo(struct qed_dev *cdev,
  1559. struct dcb_peer_app_info *info,
  1560. u16 *app_count)
  1561. {
  1562. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1563. struct qed_dcbx_get *dcbx_info;
  1564. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
  1565. if (!dcbx_info)
  1566. return -EINVAL;
  1567. info->willing = dcbx_info->remote.params.app_willing;
  1568. info->error = dcbx_info->remote.params.app_error;
  1569. *app_count = dcbx_info->remote.params.num_app_entries;
  1570. kfree(dcbx_info);
  1571. return 0;
  1572. }
  1573. static int qed_dcbnl_peer_getapptable(struct qed_dev *cdev,
  1574. struct dcb_app *table)
  1575. {
  1576. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1577. struct qed_dcbx_get *dcbx_info;
  1578. int i;
  1579. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
  1580. if (!dcbx_info)
  1581. return -EINVAL;
  1582. for (i = 0; i < dcbx_info->remote.params.num_app_entries; i++) {
  1583. if (dcbx_info->remote.params.app_entry[i].ethtype)
  1584. table[i].selector = DCB_APP_IDTYPE_ETHTYPE;
  1585. else
  1586. table[i].selector = DCB_APP_IDTYPE_PORTNUM;
  1587. table[i].priority = dcbx_info->remote.params.app_entry[i].prio;
  1588. table[i].protocol =
  1589. dcbx_info->remote.params.app_entry[i].proto_id;
  1590. }
  1591. kfree(dcbx_info);
  1592. return 0;
  1593. }
  1594. static int qed_dcbnl_cee_peer_getpfc(struct qed_dev *cdev, struct cee_pfc *pfc)
  1595. {
  1596. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1597. struct qed_dcbx_get *dcbx_info;
  1598. int i;
  1599. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
  1600. if (!dcbx_info)
  1601. return -EINVAL;
  1602. for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
  1603. if (dcbx_info->remote.params.pfc.prio[i])
  1604. pfc->pfc_en |= BIT(i);
  1605. pfc->tcs_supported = dcbx_info->remote.params.pfc.max_tc;
  1606. DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d tcs_supported = %d\n",
  1607. pfc->pfc_en, pfc->tcs_supported);
  1608. kfree(dcbx_info);
  1609. return 0;
  1610. }
  1611. static int qed_dcbnl_cee_peer_getpg(struct qed_dev *cdev, struct cee_pg *pg)
  1612. {
  1613. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1614. struct qed_dcbx_get *dcbx_info;
  1615. int i;
  1616. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
  1617. if (!dcbx_info)
  1618. return -EINVAL;
  1619. pg->willing = dcbx_info->remote.params.ets_willing;
  1620. for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
  1621. pg->pg_bw[i] = dcbx_info->remote.params.ets_tc_bw_tbl[i];
  1622. pg->prio_pg[i] = dcbx_info->remote.params.ets_pri_tc_tbl[i];
  1623. }
  1624. DP_VERBOSE(hwfn, QED_MSG_DCB, "willing = %d", pg->willing);
  1625. kfree(dcbx_info);
  1626. return 0;
  1627. }
  1628. static int qed_dcbnl_get_ieee_pfc(struct qed_dev *cdev,
  1629. struct ieee_pfc *pfc, bool remote)
  1630. {
  1631. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1632. struct qed_dcbx_params *params;
  1633. struct qed_dcbx_get *dcbx_info;
  1634. int rc, i;
  1635. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1636. if (!dcbx_info)
  1637. return -EINVAL;
  1638. if (!dcbx_info->operational.ieee) {
  1639. DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
  1640. kfree(dcbx_info);
  1641. return -EINVAL;
  1642. }
  1643. if (remote) {
  1644. memset(dcbx_info, 0, sizeof(*dcbx_info));
  1645. rc = qed_dcbx_query_params(hwfn, dcbx_info,
  1646. QED_DCBX_REMOTE_MIB);
  1647. if (rc) {
  1648. kfree(dcbx_info);
  1649. return -EINVAL;
  1650. }
  1651. params = &dcbx_info->remote.params;
  1652. } else {
  1653. params = &dcbx_info->operational.params;
  1654. }
  1655. pfc->pfc_cap = params->pfc.max_tc;
  1656. pfc->pfc_en = 0;
  1657. for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
  1658. if (params->pfc.prio[i])
  1659. pfc->pfc_en |= BIT(i);
  1660. kfree(dcbx_info);
  1661. return 0;
  1662. }
  1663. static int qed_dcbnl_ieee_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
  1664. {
  1665. return qed_dcbnl_get_ieee_pfc(cdev, pfc, false);
  1666. }
  1667. static int qed_dcbnl_ieee_setpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
  1668. {
  1669. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1670. struct qed_dcbx_get *dcbx_info;
  1671. struct qed_dcbx_set dcbx_set;
  1672. struct qed_ptt *ptt;
  1673. int rc, i;
  1674. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1675. if (!dcbx_info)
  1676. return -EINVAL;
  1677. if (!dcbx_info->operational.ieee) {
  1678. DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
  1679. kfree(dcbx_info);
  1680. return -EINVAL;
  1681. }
  1682. kfree(dcbx_info);
  1683. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1684. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1685. if (rc)
  1686. return -EINVAL;
  1687. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
  1688. for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
  1689. dcbx_set.config.params.pfc.prio[i] = !!(pfc->pfc_en & BIT(i));
  1690. ptt = qed_ptt_acquire(hwfn);
  1691. if (!ptt)
  1692. return -EINVAL;
  1693. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1694. qed_ptt_release(hwfn, ptt);
  1695. return rc;
  1696. }
  1697. static int qed_dcbnl_get_ieee_ets(struct qed_dev *cdev,
  1698. struct ieee_ets *ets, bool remote)
  1699. {
  1700. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1701. struct qed_dcbx_get *dcbx_info;
  1702. struct qed_dcbx_params *params;
  1703. int rc;
  1704. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1705. if (!dcbx_info)
  1706. return -EINVAL;
  1707. if (!dcbx_info->operational.ieee) {
  1708. DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
  1709. kfree(dcbx_info);
  1710. return -EINVAL;
  1711. }
  1712. if (remote) {
  1713. memset(dcbx_info, 0, sizeof(*dcbx_info));
  1714. rc = qed_dcbx_query_params(hwfn, dcbx_info,
  1715. QED_DCBX_REMOTE_MIB);
  1716. if (rc) {
  1717. kfree(dcbx_info);
  1718. return -EINVAL;
  1719. }
  1720. params = &dcbx_info->remote.params;
  1721. } else {
  1722. params = &dcbx_info->operational.params;
  1723. }
  1724. ets->ets_cap = params->max_ets_tc;
  1725. ets->willing = params->ets_willing;
  1726. ets->cbs = params->ets_cbs;
  1727. memcpy(ets->tc_tx_bw, params->ets_tc_bw_tbl, sizeof(ets->tc_tx_bw));
  1728. memcpy(ets->tc_tsa, params->ets_tc_tsa_tbl, sizeof(ets->tc_tsa));
  1729. memcpy(ets->prio_tc, params->ets_pri_tc_tbl, sizeof(ets->prio_tc));
  1730. kfree(dcbx_info);
  1731. return 0;
  1732. }
  1733. static int qed_dcbnl_ieee_getets(struct qed_dev *cdev, struct ieee_ets *ets)
  1734. {
  1735. return qed_dcbnl_get_ieee_ets(cdev, ets, false);
  1736. }
  1737. static int qed_dcbnl_ieee_setets(struct qed_dev *cdev, struct ieee_ets *ets)
  1738. {
  1739. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1740. struct qed_dcbx_get *dcbx_info;
  1741. struct qed_dcbx_set dcbx_set;
  1742. struct qed_ptt *ptt;
  1743. int rc;
  1744. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1745. if (!dcbx_info)
  1746. return -EINVAL;
  1747. if (!dcbx_info->operational.ieee) {
  1748. DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
  1749. kfree(dcbx_info);
  1750. return -EINVAL;
  1751. }
  1752. kfree(dcbx_info);
  1753. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1754. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1755. if (rc)
  1756. return -EINVAL;
  1757. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
  1758. dcbx_set.config.params.max_ets_tc = ets->ets_cap;
  1759. dcbx_set.config.params.ets_willing = ets->willing;
  1760. dcbx_set.config.params.ets_cbs = ets->cbs;
  1761. memcpy(dcbx_set.config.params.ets_tc_bw_tbl, ets->tc_tx_bw,
  1762. sizeof(ets->tc_tx_bw));
  1763. memcpy(dcbx_set.config.params.ets_tc_tsa_tbl, ets->tc_tsa,
  1764. sizeof(ets->tc_tsa));
  1765. memcpy(dcbx_set.config.params.ets_pri_tc_tbl, ets->prio_tc,
  1766. sizeof(ets->prio_tc));
  1767. ptt = qed_ptt_acquire(hwfn);
  1768. if (!ptt)
  1769. return -EINVAL;
  1770. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1771. qed_ptt_release(hwfn, ptt);
  1772. return rc;
  1773. }
  1774. static int
  1775. qed_dcbnl_ieee_peer_getets(struct qed_dev *cdev, struct ieee_ets *ets)
  1776. {
  1777. return qed_dcbnl_get_ieee_ets(cdev, ets, true);
  1778. }
  1779. static int
  1780. qed_dcbnl_ieee_peer_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
  1781. {
  1782. return qed_dcbnl_get_ieee_pfc(cdev, pfc, true);
  1783. }
  1784. static int qed_dcbnl_ieee_getapp(struct qed_dev *cdev, struct dcb_app *app)
  1785. {
  1786. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1787. struct qed_dcbx_get *dcbx_info;
  1788. struct qed_app_entry *entry;
  1789. bool ethtype;
  1790. u8 prio = 0;
  1791. int i;
  1792. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1793. if (!dcbx_info)
  1794. return -EINVAL;
  1795. if (!dcbx_info->operational.ieee) {
  1796. DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
  1797. kfree(dcbx_info);
  1798. return -EINVAL;
  1799. }
  1800. /* ieee defines the selector field value for ethertype to be 1 */
  1801. ethtype = !!((app->selector - 1) == DCB_APP_IDTYPE_ETHTYPE);
  1802. for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
  1803. entry = &dcbx_info->operational.params.app_entry[i];
  1804. if ((entry->ethtype == ethtype) &&
  1805. (entry->proto_id == app->protocol)) {
  1806. prio = entry->prio;
  1807. break;
  1808. }
  1809. }
  1810. if (i == QED_DCBX_MAX_APP_PROTOCOL) {
  1811. DP_ERR(cdev, "App entry (%d, %d) not found\n", app->selector,
  1812. app->protocol);
  1813. kfree(dcbx_info);
  1814. return -EINVAL;
  1815. }
  1816. app->priority = ffs(prio) - 1;
  1817. kfree(dcbx_info);
  1818. return 0;
  1819. }
  1820. static int qed_dcbnl_ieee_setapp(struct qed_dev *cdev, struct dcb_app *app)
  1821. {
  1822. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1823. struct qed_dcbx_get *dcbx_info;
  1824. struct qed_dcbx_set dcbx_set;
  1825. struct qed_app_entry *entry;
  1826. struct qed_ptt *ptt;
  1827. bool ethtype;
  1828. int rc, i;
  1829. if (app->priority < 0 || app->priority >= QED_MAX_PFC_PRIORITIES) {
  1830. DP_INFO(hwfn, "Invalid priority %d\n", app->priority);
  1831. return -EINVAL;
  1832. }
  1833. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1834. if (!dcbx_info)
  1835. return -EINVAL;
  1836. if (!dcbx_info->operational.ieee) {
  1837. DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
  1838. kfree(dcbx_info);
  1839. return -EINVAL;
  1840. }
  1841. kfree(dcbx_info);
  1842. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1843. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1844. if (rc)
  1845. return -EINVAL;
  1846. /* ieee defines the selector field value for ethertype to be 1 */
  1847. ethtype = !!((app->selector - 1) == DCB_APP_IDTYPE_ETHTYPE);
  1848. for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
  1849. entry = &dcbx_set.config.params.app_entry[i];
  1850. if ((entry->ethtype == ethtype) &&
  1851. (entry->proto_id == app->protocol))
  1852. break;
  1853. /* First empty slot */
  1854. if (!entry->proto_id) {
  1855. dcbx_set.config.params.num_app_entries++;
  1856. break;
  1857. }
  1858. }
  1859. if (i == QED_DCBX_MAX_APP_PROTOCOL) {
  1860. DP_ERR(cdev, "App table is full\n");
  1861. return -EBUSY;
  1862. }
  1863. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
  1864. dcbx_set.config.params.app_entry[i].ethtype = ethtype;
  1865. dcbx_set.config.params.app_entry[i].proto_id = app->protocol;
  1866. dcbx_set.config.params.app_entry[i].prio = BIT(app->priority);
  1867. ptt = qed_ptt_acquire(hwfn);
  1868. if (!ptt)
  1869. return -EBUSY;
  1870. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1871. qed_ptt_release(hwfn, ptt);
  1872. return rc;
  1873. }
  1874. const struct qed_eth_dcbnl_ops qed_dcbnl_ops_pass = {
  1875. .getstate = qed_dcbnl_getstate,
  1876. .setstate = qed_dcbnl_setstate,
  1877. .getpgtccfgtx = qed_dcbnl_getpgtccfgtx,
  1878. .getpgbwgcfgtx = qed_dcbnl_getpgbwgcfgtx,
  1879. .getpgtccfgrx = qed_dcbnl_getpgtccfgrx,
  1880. .getpgbwgcfgrx = qed_dcbnl_getpgbwgcfgrx,
  1881. .getpfccfg = qed_dcbnl_getpfccfg,
  1882. .setpfccfg = qed_dcbnl_setpfccfg,
  1883. .getcap = qed_dcbnl_getcap,
  1884. .getnumtcs = qed_dcbnl_getnumtcs,
  1885. .getpfcstate = qed_dcbnl_getpfcstate,
  1886. .getdcbx = qed_dcbnl_getdcbx,
  1887. .setpgtccfgtx = qed_dcbnl_setpgtccfgtx,
  1888. .setpgtccfgrx = qed_dcbnl_setpgtccfgrx,
  1889. .setpgbwgcfgtx = qed_dcbnl_setpgbwgcfgtx,
  1890. .setpgbwgcfgrx = qed_dcbnl_setpgbwgcfgrx,
  1891. .setall = qed_dcbnl_setall,
  1892. .setnumtcs = qed_dcbnl_setnumtcs,
  1893. .setpfcstate = qed_dcbnl_setpfcstate,
  1894. .setapp = qed_dcbnl_setapp,
  1895. .setdcbx = qed_dcbnl_setdcbx,
  1896. .setfeatcfg = qed_dcbnl_setfeatcfg,
  1897. .getfeatcfg = qed_dcbnl_getfeatcfg,
  1898. .getapp = qed_dcbnl_getapp,
  1899. .peer_getappinfo = qed_dcbnl_peer_getappinfo,
  1900. .peer_getapptable = qed_dcbnl_peer_getapptable,
  1901. .cee_peer_getpfc = qed_dcbnl_cee_peer_getpfc,
  1902. .cee_peer_getpg = qed_dcbnl_cee_peer_getpg,
  1903. .ieee_getpfc = qed_dcbnl_ieee_getpfc,
  1904. .ieee_setpfc = qed_dcbnl_ieee_setpfc,
  1905. .ieee_getets = qed_dcbnl_ieee_getets,
  1906. .ieee_setets = qed_dcbnl_ieee_setets,
  1907. .ieee_peer_getpfc = qed_dcbnl_ieee_peer_getpfc,
  1908. .ieee_peer_getets = qed_dcbnl_ieee_peer_getets,
  1909. .ieee_getapp = qed_dcbnl_ieee_getapp,
  1910. .ieee_setapp = qed_dcbnl_ieee_setapp,
  1911. };
  1912. #endif