qed_dcbx.c 61 KB

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