qed_dev.c 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629
  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/io.h>
  11. #include <linux/delay.h>
  12. #include <linux/dma-mapping.h>
  13. #include <linux/errno.h>
  14. #include <linux/kernel.h>
  15. #include <linux/mutex.h>
  16. #include <linux/pci.h>
  17. #include <linux/slab.h>
  18. #include <linux/string.h>
  19. #include <linux/vmalloc.h>
  20. #include <linux/etherdevice.h>
  21. #include <linux/qed/qed_chain.h>
  22. #include <linux/qed/qed_if.h>
  23. #include "qed.h"
  24. #include "qed_cxt.h"
  25. #include "qed_dcbx.h"
  26. #include "qed_dev_api.h"
  27. #include "qed_hsi.h"
  28. #include "qed_hw.h"
  29. #include "qed_init_ops.h"
  30. #include "qed_int.h"
  31. #include "qed_mcp.h"
  32. #include "qed_reg_addr.h"
  33. #include "qed_sp.h"
  34. #include "qed_sriov.h"
  35. #include "qed_vf.h"
  36. static DEFINE_SPINLOCK(qm_lock);
  37. /* API common to all protocols */
  38. enum BAR_ID {
  39. BAR_ID_0, /* used for GRC */
  40. BAR_ID_1 /* Used for doorbells */
  41. };
  42. static u32 qed_hw_bar_size(struct qed_hwfn *p_hwfn, enum BAR_ID bar_id)
  43. {
  44. u32 bar_reg = (bar_id == BAR_ID_0 ?
  45. PGLUE_B_REG_PF_BAR0_SIZE : PGLUE_B_REG_PF_BAR1_SIZE);
  46. u32 val;
  47. if (IS_VF(p_hwfn->cdev))
  48. return 1 << 17;
  49. val = qed_rd(p_hwfn, p_hwfn->p_main_ptt, bar_reg);
  50. if (val)
  51. return 1 << (val + 15);
  52. /* Old MFW initialized above registered only conditionally */
  53. if (p_hwfn->cdev->num_hwfns > 1) {
  54. DP_INFO(p_hwfn,
  55. "BAR size not configured. Assuming BAR size of 256kB for GRC and 512kB for DB\n");
  56. return BAR_ID_0 ? 256 * 1024 : 512 * 1024;
  57. } else {
  58. DP_INFO(p_hwfn,
  59. "BAR size not configured. Assuming BAR size of 512kB for GRC and 512kB for DB\n");
  60. return 512 * 1024;
  61. }
  62. }
  63. void qed_init_dp(struct qed_dev *cdev, u32 dp_module, u8 dp_level)
  64. {
  65. u32 i;
  66. cdev->dp_level = dp_level;
  67. cdev->dp_module = dp_module;
  68. for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
  69. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  70. p_hwfn->dp_level = dp_level;
  71. p_hwfn->dp_module = dp_module;
  72. }
  73. }
  74. void qed_init_struct(struct qed_dev *cdev)
  75. {
  76. u8 i;
  77. for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
  78. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  79. p_hwfn->cdev = cdev;
  80. p_hwfn->my_id = i;
  81. p_hwfn->b_active = false;
  82. mutex_init(&p_hwfn->dmae_info.mutex);
  83. }
  84. /* hwfn 0 is always active */
  85. cdev->hwfns[0].b_active = true;
  86. /* set the default cache alignment to 128 */
  87. cdev->cache_shift = 7;
  88. }
  89. static void qed_qm_info_free(struct qed_hwfn *p_hwfn)
  90. {
  91. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  92. kfree(qm_info->qm_pq_params);
  93. qm_info->qm_pq_params = NULL;
  94. kfree(qm_info->qm_vport_params);
  95. qm_info->qm_vport_params = NULL;
  96. kfree(qm_info->qm_port_params);
  97. qm_info->qm_port_params = NULL;
  98. kfree(qm_info->wfq_data);
  99. qm_info->wfq_data = NULL;
  100. }
  101. void qed_resc_free(struct qed_dev *cdev)
  102. {
  103. int i;
  104. if (IS_VF(cdev))
  105. return;
  106. kfree(cdev->fw_data);
  107. cdev->fw_data = NULL;
  108. kfree(cdev->reset_stats);
  109. for_each_hwfn(cdev, i) {
  110. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  111. kfree(p_hwfn->p_tx_cids);
  112. p_hwfn->p_tx_cids = NULL;
  113. kfree(p_hwfn->p_rx_cids);
  114. p_hwfn->p_rx_cids = NULL;
  115. }
  116. for_each_hwfn(cdev, i) {
  117. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  118. qed_cxt_mngr_free(p_hwfn);
  119. qed_qm_info_free(p_hwfn);
  120. qed_spq_free(p_hwfn);
  121. qed_eq_free(p_hwfn, p_hwfn->p_eq);
  122. qed_consq_free(p_hwfn, p_hwfn->p_consq);
  123. qed_int_free(p_hwfn);
  124. qed_iov_free(p_hwfn);
  125. qed_dmae_info_free(p_hwfn);
  126. qed_dcbx_info_free(p_hwfn, p_hwfn->p_dcbx_info);
  127. }
  128. }
  129. static int qed_init_qm_info(struct qed_hwfn *p_hwfn, bool b_sleepable)
  130. {
  131. u8 num_vports, vf_offset = 0, i, vport_id, num_ports, curr_queue = 0;
  132. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  133. struct init_qm_port_params *p_qm_port;
  134. bool init_rdma_offload_pq = false;
  135. bool init_pure_ack_pq = false;
  136. bool init_ooo_pq = false;
  137. u16 num_pqs, multi_cos_tcs = 1;
  138. u8 pf_wfq = qm_info->pf_wfq;
  139. u32 pf_rl = qm_info->pf_rl;
  140. u16 num_pf_rls = 0;
  141. u16 num_vfs = 0;
  142. #ifdef CONFIG_QED_SRIOV
  143. if (p_hwfn->cdev->p_iov_info)
  144. num_vfs = p_hwfn->cdev->p_iov_info->total_vfs;
  145. #endif
  146. memset(qm_info, 0, sizeof(*qm_info));
  147. num_pqs = multi_cos_tcs + num_vfs + 1; /* The '1' is for pure-LB */
  148. num_vports = (u8)RESC_NUM(p_hwfn, QED_VPORT);
  149. if (p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE) {
  150. num_pqs++; /* for RoCE queue */
  151. init_rdma_offload_pq = true;
  152. /* we subtract num_vfs because each require a rate limiter,
  153. * and one default rate limiter
  154. */
  155. if (p_hwfn->pf_params.rdma_pf_params.enable_dcqcn)
  156. num_pf_rls = RESC_NUM(p_hwfn, QED_RL) - num_vfs - 1;
  157. num_pqs += num_pf_rls;
  158. qm_info->num_pf_rls = (u8) num_pf_rls;
  159. }
  160. if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
  161. num_pqs += 2; /* for iSCSI pure-ACK / OOO queue */
  162. init_pure_ack_pq = true;
  163. init_ooo_pq = true;
  164. }
  165. /* Sanity checking that setup requires legal number of resources */
  166. if (num_pqs > RESC_NUM(p_hwfn, QED_PQ)) {
  167. DP_ERR(p_hwfn,
  168. "Need too many Physical queues - 0x%04x when only %04x are available\n",
  169. num_pqs, RESC_NUM(p_hwfn, QED_PQ));
  170. return -EINVAL;
  171. }
  172. /* PQs will be arranged as follows: First per-TC PQ then pure-LB quete.
  173. */
  174. qm_info->qm_pq_params = kcalloc(num_pqs,
  175. sizeof(struct init_qm_pq_params),
  176. b_sleepable ? GFP_KERNEL : GFP_ATOMIC);
  177. if (!qm_info->qm_pq_params)
  178. goto alloc_err;
  179. qm_info->qm_vport_params = kcalloc(num_vports,
  180. sizeof(struct init_qm_vport_params),
  181. b_sleepable ? GFP_KERNEL
  182. : GFP_ATOMIC);
  183. if (!qm_info->qm_vport_params)
  184. goto alloc_err;
  185. qm_info->qm_port_params = kcalloc(MAX_NUM_PORTS,
  186. sizeof(struct init_qm_port_params),
  187. b_sleepable ? GFP_KERNEL
  188. : GFP_ATOMIC);
  189. if (!qm_info->qm_port_params)
  190. goto alloc_err;
  191. qm_info->wfq_data = kcalloc(num_vports, sizeof(struct qed_wfq_data),
  192. b_sleepable ? GFP_KERNEL : GFP_ATOMIC);
  193. if (!qm_info->wfq_data)
  194. goto alloc_err;
  195. vport_id = (u8)RESC_START(p_hwfn, QED_VPORT);
  196. /* First init rate limited queues */
  197. for (curr_queue = 0; curr_queue < num_pf_rls; curr_queue++) {
  198. qm_info->qm_pq_params[curr_queue].vport_id = vport_id++;
  199. qm_info->qm_pq_params[curr_queue].tc_id =
  200. p_hwfn->hw_info.non_offload_tc;
  201. qm_info->qm_pq_params[curr_queue].wrr_group = 1;
  202. qm_info->qm_pq_params[curr_queue].rl_valid = 1;
  203. }
  204. /* First init per-TC PQs */
  205. for (i = 0; i < multi_cos_tcs; i++) {
  206. struct init_qm_pq_params *params =
  207. &qm_info->qm_pq_params[curr_queue++];
  208. if (p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE ||
  209. p_hwfn->hw_info.personality == QED_PCI_ETH) {
  210. params->vport_id = vport_id;
  211. params->tc_id = p_hwfn->hw_info.non_offload_tc;
  212. params->wrr_group = 1;
  213. } else {
  214. params->vport_id = vport_id;
  215. params->tc_id = p_hwfn->hw_info.offload_tc;
  216. params->wrr_group = 1;
  217. }
  218. }
  219. /* Then init pure-LB PQ */
  220. qm_info->pure_lb_pq = curr_queue;
  221. qm_info->qm_pq_params[curr_queue].vport_id =
  222. (u8) RESC_START(p_hwfn, QED_VPORT);
  223. qm_info->qm_pq_params[curr_queue].tc_id = PURE_LB_TC;
  224. qm_info->qm_pq_params[curr_queue].wrr_group = 1;
  225. curr_queue++;
  226. qm_info->offload_pq = 0;
  227. if (init_rdma_offload_pq) {
  228. qm_info->offload_pq = curr_queue;
  229. qm_info->qm_pq_params[curr_queue].vport_id = vport_id;
  230. qm_info->qm_pq_params[curr_queue].tc_id =
  231. p_hwfn->hw_info.offload_tc;
  232. qm_info->qm_pq_params[curr_queue].wrr_group = 1;
  233. curr_queue++;
  234. }
  235. if (init_pure_ack_pq) {
  236. qm_info->pure_ack_pq = curr_queue;
  237. qm_info->qm_pq_params[curr_queue].vport_id = vport_id;
  238. qm_info->qm_pq_params[curr_queue].tc_id =
  239. p_hwfn->hw_info.offload_tc;
  240. qm_info->qm_pq_params[curr_queue].wrr_group = 1;
  241. curr_queue++;
  242. }
  243. if (init_ooo_pq) {
  244. qm_info->ooo_pq = curr_queue;
  245. qm_info->qm_pq_params[curr_queue].vport_id = vport_id;
  246. qm_info->qm_pq_params[curr_queue].tc_id = DCBX_ISCSI_OOO_TC;
  247. qm_info->qm_pq_params[curr_queue].wrr_group = 1;
  248. curr_queue++;
  249. }
  250. /* Then init per-VF PQs */
  251. vf_offset = curr_queue;
  252. for (i = 0; i < num_vfs; i++) {
  253. /* First vport is used by the PF */
  254. qm_info->qm_pq_params[curr_queue].vport_id = vport_id + i + 1;
  255. qm_info->qm_pq_params[curr_queue].tc_id =
  256. p_hwfn->hw_info.non_offload_tc;
  257. qm_info->qm_pq_params[curr_queue].wrr_group = 1;
  258. qm_info->qm_pq_params[curr_queue].rl_valid = 1;
  259. curr_queue++;
  260. }
  261. qm_info->vf_queues_offset = vf_offset;
  262. qm_info->num_pqs = num_pqs;
  263. qm_info->num_vports = num_vports;
  264. /* Initialize qm port parameters */
  265. num_ports = p_hwfn->cdev->num_ports_in_engines;
  266. for (i = 0; i < num_ports; i++) {
  267. p_qm_port = &qm_info->qm_port_params[i];
  268. p_qm_port->active = 1;
  269. if (num_ports == 4)
  270. p_qm_port->active_phys_tcs = 0x7;
  271. else
  272. p_qm_port->active_phys_tcs = 0x9f;
  273. p_qm_port->num_pbf_cmd_lines = PBF_MAX_CMD_LINES / num_ports;
  274. p_qm_port->num_btb_blocks = BTB_MAX_BLOCKS / num_ports;
  275. }
  276. qm_info->max_phys_tcs_per_port = NUM_OF_PHYS_TCS;
  277. qm_info->start_pq = (u16)RESC_START(p_hwfn, QED_PQ);
  278. qm_info->num_vf_pqs = num_vfs;
  279. qm_info->start_vport = (u8) RESC_START(p_hwfn, QED_VPORT);
  280. for (i = 0; i < qm_info->num_vports; i++)
  281. qm_info->qm_vport_params[i].vport_wfq = 1;
  282. qm_info->vport_rl_en = 1;
  283. qm_info->vport_wfq_en = 1;
  284. qm_info->pf_rl = pf_rl;
  285. qm_info->pf_wfq = pf_wfq;
  286. return 0;
  287. alloc_err:
  288. qed_qm_info_free(p_hwfn);
  289. return -ENOMEM;
  290. }
  291. /* This function reconfigures the QM pf on the fly.
  292. * For this purpose we:
  293. * 1. reconfigure the QM database
  294. * 2. set new values to runtime arrat
  295. * 3. send an sdm_qm_cmd through the rbc interface to stop the QM
  296. * 4. activate init tool in QM_PF stage
  297. * 5. send an sdm_qm_cmd through rbc interface to release the QM
  298. */
  299. int qed_qm_reconf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  300. {
  301. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  302. bool b_rc;
  303. int rc;
  304. /* qm_info is allocated in qed_init_qm_info() which is already called
  305. * from qed_resc_alloc() or previous call of qed_qm_reconf().
  306. * The allocated size may change each init, so we free it before next
  307. * allocation.
  308. */
  309. qed_qm_info_free(p_hwfn);
  310. /* initialize qed's qm data structure */
  311. rc = qed_init_qm_info(p_hwfn, false);
  312. if (rc)
  313. return rc;
  314. /* stop PF's qm queues */
  315. spin_lock_bh(&qm_lock);
  316. b_rc = qed_send_qm_stop_cmd(p_hwfn, p_ptt, false, true,
  317. qm_info->start_pq, qm_info->num_pqs);
  318. spin_unlock_bh(&qm_lock);
  319. if (!b_rc)
  320. return -EINVAL;
  321. /* clear the QM_PF runtime phase leftovers from previous init */
  322. qed_init_clear_rt_data(p_hwfn);
  323. /* prepare QM portion of runtime array */
  324. qed_qm_init_pf(p_hwfn);
  325. /* activate init tool on runtime array */
  326. rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, p_hwfn->rel_pf_id,
  327. p_hwfn->hw_info.hw_mode);
  328. if (rc)
  329. return rc;
  330. /* start PF's qm queues */
  331. spin_lock_bh(&qm_lock);
  332. b_rc = qed_send_qm_stop_cmd(p_hwfn, p_ptt, true, true,
  333. qm_info->start_pq, qm_info->num_pqs);
  334. spin_unlock_bh(&qm_lock);
  335. if (!b_rc)
  336. return -EINVAL;
  337. return 0;
  338. }
  339. int qed_resc_alloc(struct qed_dev *cdev)
  340. {
  341. struct qed_consq *p_consq;
  342. struct qed_eq *p_eq;
  343. int i, rc = 0;
  344. if (IS_VF(cdev))
  345. return rc;
  346. cdev->fw_data = kzalloc(sizeof(*cdev->fw_data), GFP_KERNEL);
  347. if (!cdev->fw_data)
  348. return -ENOMEM;
  349. /* Allocate Memory for the Queue->CID mapping */
  350. for_each_hwfn(cdev, i) {
  351. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  352. int tx_size = sizeof(struct qed_hw_cid_data) *
  353. RESC_NUM(p_hwfn, QED_L2_QUEUE);
  354. int rx_size = sizeof(struct qed_hw_cid_data) *
  355. RESC_NUM(p_hwfn, QED_L2_QUEUE);
  356. p_hwfn->p_tx_cids = kzalloc(tx_size, GFP_KERNEL);
  357. if (!p_hwfn->p_tx_cids)
  358. goto alloc_no_mem;
  359. p_hwfn->p_rx_cids = kzalloc(rx_size, GFP_KERNEL);
  360. if (!p_hwfn->p_rx_cids)
  361. goto alloc_no_mem;
  362. }
  363. for_each_hwfn(cdev, i) {
  364. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  365. u32 n_eqes, num_cons;
  366. /* First allocate the context manager structure */
  367. rc = qed_cxt_mngr_alloc(p_hwfn);
  368. if (rc)
  369. goto alloc_err;
  370. /* Set the HW cid/tid numbers (in the contest manager)
  371. * Must be done prior to any further computations.
  372. */
  373. rc = qed_cxt_set_pf_params(p_hwfn);
  374. if (rc)
  375. goto alloc_err;
  376. /* Prepare and process QM requirements */
  377. rc = qed_init_qm_info(p_hwfn, true);
  378. if (rc)
  379. goto alloc_err;
  380. /* Compute the ILT client partition */
  381. rc = qed_cxt_cfg_ilt_compute(p_hwfn);
  382. if (rc)
  383. goto alloc_err;
  384. /* CID map / ILT shadow table / T2
  385. * The talbes sizes are determined by the computations above
  386. */
  387. rc = qed_cxt_tables_alloc(p_hwfn);
  388. if (rc)
  389. goto alloc_err;
  390. /* SPQ, must follow ILT because initializes SPQ context */
  391. rc = qed_spq_alloc(p_hwfn);
  392. if (rc)
  393. goto alloc_err;
  394. /* SP status block allocation */
  395. p_hwfn->p_dpc_ptt = qed_get_reserved_ptt(p_hwfn,
  396. RESERVED_PTT_DPC);
  397. rc = qed_int_alloc(p_hwfn, p_hwfn->p_main_ptt);
  398. if (rc)
  399. goto alloc_err;
  400. rc = qed_iov_alloc(p_hwfn);
  401. if (rc)
  402. goto alloc_err;
  403. /* EQ */
  404. n_eqes = qed_chain_get_capacity(&p_hwfn->p_spq->chain);
  405. if (p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE) {
  406. num_cons = qed_cxt_get_proto_cid_count(p_hwfn,
  407. PROTOCOLID_ROCE,
  408. 0) * 2;
  409. n_eqes += num_cons + 2 * MAX_NUM_VFS_BB;
  410. } else if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
  411. num_cons =
  412. qed_cxt_get_proto_cid_count(p_hwfn,
  413. PROTOCOLID_ISCSI, 0);
  414. n_eqes += 2 * num_cons;
  415. }
  416. if (n_eqes > 0xFFFF) {
  417. DP_ERR(p_hwfn,
  418. "Cannot allocate 0x%x EQ elements. The maximum of a u16 chain is 0x%x\n",
  419. n_eqes, 0xFFFF);
  420. rc = -EINVAL;
  421. goto alloc_err;
  422. }
  423. p_eq = qed_eq_alloc(p_hwfn, (u16) n_eqes);
  424. if (!p_eq)
  425. goto alloc_no_mem;
  426. p_hwfn->p_eq = p_eq;
  427. p_consq = qed_consq_alloc(p_hwfn);
  428. if (!p_consq)
  429. goto alloc_no_mem;
  430. p_hwfn->p_consq = p_consq;
  431. /* DMA info initialization */
  432. rc = qed_dmae_info_alloc(p_hwfn);
  433. if (rc)
  434. goto alloc_err;
  435. /* DCBX initialization */
  436. rc = qed_dcbx_info_alloc(p_hwfn);
  437. if (rc)
  438. goto alloc_err;
  439. }
  440. cdev->reset_stats = kzalloc(sizeof(*cdev->reset_stats), GFP_KERNEL);
  441. if (!cdev->reset_stats)
  442. goto alloc_no_mem;
  443. return 0;
  444. alloc_no_mem:
  445. rc = -ENOMEM;
  446. alloc_err:
  447. qed_resc_free(cdev);
  448. return rc;
  449. }
  450. void qed_resc_setup(struct qed_dev *cdev)
  451. {
  452. int i;
  453. if (IS_VF(cdev))
  454. return;
  455. for_each_hwfn(cdev, i) {
  456. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  457. qed_cxt_mngr_setup(p_hwfn);
  458. qed_spq_setup(p_hwfn);
  459. qed_eq_setup(p_hwfn, p_hwfn->p_eq);
  460. qed_consq_setup(p_hwfn, p_hwfn->p_consq);
  461. /* Read shadow of current MFW mailbox */
  462. qed_mcp_read_mb(p_hwfn, p_hwfn->p_main_ptt);
  463. memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
  464. p_hwfn->mcp_info->mfw_mb_cur,
  465. p_hwfn->mcp_info->mfw_mb_length);
  466. qed_int_setup(p_hwfn, p_hwfn->p_main_ptt);
  467. qed_iov_setup(p_hwfn, p_hwfn->p_main_ptt);
  468. }
  469. }
  470. #define FINAL_CLEANUP_POLL_CNT (100)
  471. #define FINAL_CLEANUP_POLL_TIME (10)
  472. int qed_final_cleanup(struct qed_hwfn *p_hwfn,
  473. struct qed_ptt *p_ptt, u16 id, bool is_vf)
  474. {
  475. u32 command = 0, addr, count = FINAL_CLEANUP_POLL_CNT;
  476. int rc = -EBUSY;
  477. addr = GTT_BAR0_MAP_REG_USDM_RAM +
  478. USTORM_FLR_FINAL_ACK_OFFSET(p_hwfn->rel_pf_id);
  479. if (is_vf)
  480. id += 0x10;
  481. command |= X_FINAL_CLEANUP_AGG_INT <<
  482. SDM_AGG_INT_COMP_PARAMS_AGG_INT_INDEX_SHIFT;
  483. command |= 1 << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_ENABLE_SHIFT;
  484. command |= id << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_BIT_SHIFT;
  485. command |= SDM_COMP_TYPE_AGG_INT << SDM_OP_GEN_COMP_TYPE_SHIFT;
  486. /* Make sure notification is not set before initiating final cleanup */
  487. if (REG_RD(p_hwfn, addr)) {
  488. DP_NOTICE(p_hwfn,
  489. "Unexpected; Found final cleanup notification before initiating final cleanup\n");
  490. REG_WR(p_hwfn, addr, 0);
  491. }
  492. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  493. "Sending final cleanup for PFVF[%d] [Command %08x\n]",
  494. id, command);
  495. qed_wr(p_hwfn, p_ptt, XSDM_REG_OPERATION_GEN, command);
  496. /* Poll until completion */
  497. while (!REG_RD(p_hwfn, addr) && count--)
  498. msleep(FINAL_CLEANUP_POLL_TIME);
  499. if (REG_RD(p_hwfn, addr))
  500. rc = 0;
  501. else
  502. DP_NOTICE(p_hwfn,
  503. "Failed to receive FW final cleanup notification\n");
  504. /* Cleanup afterwards */
  505. REG_WR(p_hwfn, addr, 0);
  506. return rc;
  507. }
  508. static void qed_calc_hw_mode(struct qed_hwfn *p_hwfn)
  509. {
  510. int hw_mode = 0;
  511. hw_mode = (1 << MODE_BB_B0);
  512. switch (p_hwfn->cdev->num_ports_in_engines) {
  513. case 1:
  514. hw_mode |= 1 << MODE_PORTS_PER_ENG_1;
  515. break;
  516. case 2:
  517. hw_mode |= 1 << MODE_PORTS_PER_ENG_2;
  518. break;
  519. case 4:
  520. hw_mode |= 1 << MODE_PORTS_PER_ENG_4;
  521. break;
  522. default:
  523. DP_NOTICE(p_hwfn, "num_ports_in_engine = %d not supported\n",
  524. p_hwfn->cdev->num_ports_in_engines);
  525. return;
  526. }
  527. switch (p_hwfn->cdev->mf_mode) {
  528. case QED_MF_DEFAULT:
  529. case QED_MF_NPAR:
  530. hw_mode |= 1 << MODE_MF_SI;
  531. break;
  532. case QED_MF_OVLAN:
  533. hw_mode |= 1 << MODE_MF_SD;
  534. break;
  535. default:
  536. DP_NOTICE(p_hwfn, "Unsupported MF mode, init as DEFAULT\n");
  537. hw_mode |= 1 << MODE_MF_SI;
  538. }
  539. hw_mode |= 1 << MODE_ASIC;
  540. if (p_hwfn->cdev->num_hwfns > 1)
  541. hw_mode |= 1 << MODE_100G;
  542. p_hwfn->hw_info.hw_mode = hw_mode;
  543. DP_VERBOSE(p_hwfn, (NETIF_MSG_PROBE | NETIF_MSG_IFUP),
  544. "Configuring function for hw_mode: 0x%08x\n",
  545. p_hwfn->hw_info.hw_mode);
  546. }
  547. /* Init run time data for all PFs on an engine. */
  548. static void qed_init_cau_rt_data(struct qed_dev *cdev)
  549. {
  550. u32 offset = CAU_REG_SB_VAR_MEMORY_RT_OFFSET;
  551. int i, sb_id;
  552. for_each_hwfn(cdev, i) {
  553. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  554. struct qed_igu_info *p_igu_info;
  555. struct qed_igu_block *p_block;
  556. struct cau_sb_entry sb_entry;
  557. p_igu_info = p_hwfn->hw_info.p_igu_info;
  558. for (sb_id = 0; sb_id < QED_MAPPING_MEMORY_SIZE(cdev);
  559. sb_id++) {
  560. p_block = &p_igu_info->igu_map.igu_blocks[sb_id];
  561. if (!p_block->is_pf)
  562. continue;
  563. qed_init_cau_sb_entry(p_hwfn, &sb_entry,
  564. p_block->function_id, 0, 0);
  565. STORE_RT_REG_AGG(p_hwfn, offset + sb_id * 2, sb_entry);
  566. }
  567. }
  568. }
  569. static int qed_hw_init_common(struct qed_hwfn *p_hwfn,
  570. struct qed_ptt *p_ptt, int hw_mode)
  571. {
  572. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  573. struct qed_qm_common_rt_init_params params;
  574. struct qed_dev *cdev = p_hwfn->cdev;
  575. u16 num_pfs, pf_id;
  576. u32 concrete_fid;
  577. int rc = 0;
  578. u8 vf_id;
  579. qed_init_cau_rt_data(cdev);
  580. /* Program GTT windows */
  581. qed_gtt_init(p_hwfn);
  582. if (p_hwfn->mcp_info) {
  583. if (p_hwfn->mcp_info->func_info.bandwidth_max)
  584. qm_info->pf_rl_en = 1;
  585. if (p_hwfn->mcp_info->func_info.bandwidth_min)
  586. qm_info->pf_wfq_en = 1;
  587. }
  588. memset(&params, 0, sizeof(params));
  589. params.max_ports_per_engine = p_hwfn->cdev->num_ports_in_engines;
  590. params.max_phys_tcs_per_port = qm_info->max_phys_tcs_per_port;
  591. params.pf_rl_en = qm_info->pf_rl_en;
  592. params.pf_wfq_en = qm_info->pf_wfq_en;
  593. params.vport_rl_en = qm_info->vport_rl_en;
  594. params.vport_wfq_en = qm_info->vport_wfq_en;
  595. params.port_params = qm_info->qm_port_params;
  596. qed_qm_common_rt_init(p_hwfn, &params);
  597. qed_cxt_hw_init_common(p_hwfn);
  598. /* Close gate from NIG to BRB/Storm; By default they are open, but
  599. * we close them to prevent NIG from passing data to reset blocks.
  600. * Should have been done in the ENGINE phase, but init-tool lacks
  601. * proper port-pretend capabilities.
  602. */
  603. qed_wr(p_hwfn, p_ptt, NIG_REG_RX_BRB_OUT_EN, 0);
  604. qed_wr(p_hwfn, p_ptt, NIG_REG_STORM_OUT_EN, 0);
  605. qed_port_pretend(p_hwfn, p_ptt, p_hwfn->port_id ^ 1);
  606. qed_wr(p_hwfn, p_ptt, NIG_REG_RX_BRB_OUT_EN, 0);
  607. qed_wr(p_hwfn, p_ptt, NIG_REG_STORM_OUT_EN, 0);
  608. qed_port_unpretend(p_hwfn, p_ptt);
  609. rc = qed_init_run(p_hwfn, p_ptt, PHASE_ENGINE, ANY_PHASE_ID, hw_mode);
  610. if (rc)
  611. return rc;
  612. qed_wr(p_hwfn, p_ptt, PSWRQ2_REG_L2P_VALIDATE_VFID, 0);
  613. qed_wr(p_hwfn, p_ptt, PGLUE_B_REG_USE_CLIENTID_IN_TAG, 1);
  614. if (QED_IS_BB(p_hwfn->cdev)) {
  615. num_pfs = NUM_OF_ENG_PFS(p_hwfn->cdev);
  616. for (pf_id = 0; pf_id < num_pfs; pf_id++) {
  617. qed_fid_pretend(p_hwfn, p_ptt, pf_id);
  618. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
  619. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
  620. }
  621. /* pretend to original PF */
  622. qed_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
  623. }
  624. for (vf_id = 0; vf_id < MAX_NUM_VFS_BB; vf_id++) {
  625. concrete_fid = qed_vfid_to_concrete(p_hwfn, vf_id);
  626. qed_fid_pretend(p_hwfn, p_ptt, (u16) concrete_fid);
  627. qed_wr(p_hwfn, p_ptt, CCFC_REG_STRONG_ENABLE_VF, 0x1);
  628. qed_wr(p_hwfn, p_ptt, CCFC_REG_WEAK_ENABLE_VF, 0x0);
  629. qed_wr(p_hwfn, p_ptt, TCFC_REG_STRONG_ENABLE_VF, 0x1);
  630. qed_wr(p_hwfn, p_ptt, TCFC_REG_WEAK_ENABLE_VF, 0x0);
  631. }
  632. /* pretend to original PF */
  633. qed_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
  634. return rc;
  635. }
  636. static int qed_hw_init_port(struct qed_hwfn *p_hwfn,
  637. struct qed_ptt *p_ptt, int hw_mode)
  638. {
  639. return qed_init_run(p_hwfn, p_ptt, PHASE_PORT,
  640. p_hwfn->port_id, hw_mode);
  641. }
  642. static int qed_hw_init_pf(struct qed_hwfn *p_hwfn,
  643. struct qed_ptt *p_ptt,
  644. struct qed_tunn_start_params *p_tunn,
  645. int hw_mode,
  646. bool b_hw_start,
  647. enum qed_int_mode int_mode,
  648. bool allow_npar_tx_switch)
  649. {
  650. u8 rel_pf_id = p_hwfn->rel_pf_id;
  651. int rc = 0;
  652. if (p_hwfn->mcp_info) {
  653. struct qed_mcp_function_info *p_info;
  654. p_info = &p_hwfn->mcp_info->func_info;
  655. if (p_info->bandwidth_min)
  656. p_hwfn->qm_info.pf_wfq = p_info->bandwidth_min;
  657. /* Update rate limit once we'll actually have a link */
  658. p_hwfn->qm_info.pf_rl = 100000;
  659. }
  660. qed_cxt_hw_init_pf(p_hwfn);
  661. qed_int_igu_init_rt(p_hwfn);
  662. /* Set VLAN in NIG if needed */
  663. if (hw_mode & BIT(MODE_MF_SD)) {
  664. DP_VERBOSE(p_hwfn, NETIF_MSG_HW, "Configuring LLH_FUNC_TAG\n");
  665. STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_EN_RT_OFFSET, 1);
  666. STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_VALUE_RT_OFFSET,
  667. p_hwfn->hw_info.ovlan);
  668. }
  669. /* Enable classification by MAC if needed */
  670. if (hw_mode & BIT(MODE_MF_SI)) {
  671. DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
  672. "Configuring TAGMAC_CLS_TYPE\n");
  673. STORE_RT_REG(p_hwfn,
  674. NIG_REG_LLH_FUNC_TAGMAC_CLS_TYPE_RT_OFFSET, 1);
  675. }
  676. /* Protocl Configuration */
  677. STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_TCP_RT_OFFSET,
  678. (p_hwfn->hw_info.personality == QED_PCI_ISCSI) ? 1 : 0);
  679. STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_FCOE_RT_OFFSET, 0);
  680. STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_ROCE_RT_OFFSET, 0);
  681. /* Cleanup chip from previous driver if such remains exist */
  682. rc = qed_final_cleanup(p_hwfn, p_ptt, rel_pf_id, false);
  683. if (rc)
  684. return rc;
  685. /* PF Init sequence */
  686. rc = qed_init_run(p_hwfn, p_ptt, PHASE_PF, rel_pf_id, hw_mode);
  687. if (rc)
  688. return rc;
  689. /* QM_PF Init sequence (may be invoked separately e.g. for DCB) */
  690. rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, rel_pf_id, hw_mode);
  691. if (rc)
  692. return rc;
  693. /* Pure runtime initializations - directly to the HW */
  694. qed_int_igu_init_pure_rt(p_hwfn, p_ptt, true, true);
  695. if (b_hw_start) {
  696. /* enable interrupts */
  697. qed_int_igu_enable(p_hwfn, p_ptt, int_mode);
  698. /* send function start command */
  699. rc = qed_sp_pf_start(p_hwfn, p_tunn, p_hwfn->cdev->mf_mode,
  700. allow_npar_tx_switch);
  701. if (rc)
  702. DP_NOTICE(p_hwfn, "Function start ramrod failed\n");
  703. }
  704. return rc;
  705. }
  706. static int qed_change_pci_hwfn(struct qed_hwfn *p_hwfn,
  707. struct qed_ptt *p_ptt,
  708. u8 enable)
  709. {
  710. u32 delay_idx = 0, val, set_val = enable ? 1 : 0;
  711. /* Change PF in PXP */
  712. qed_wr(p_hwfn, p_ptt,
  713. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, set_val);
  714. /* wait until value is set - try for 1 second every 50us */
  715. for (delay_idx = 0; delay_idx < 20000; delay_idx++) {
  716. val = qed_rd(p_hwfn, p_ptt,
  717. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  718. if (val == set_val)
  719. break;
  720. usleep_range(50, 60);
  721. }
  722. if (val != set_val) {
  723. DP_NOTICE(p_hwfn,
  724. "PFID_ENABLE_MASTER wasn't changed after a second\n");
  725. return -EAGAIN;
  726. }
  727. return 0;
  728. }
  729. static void qed_reset_mb_shadow(struct qed_hwfn *p_hwfn,
  730. struct qed_ptt *p_main_ptt)
  731. {
  732. /* Read shadow of current MFW mailbox */
  733. qed_mcp_read_mb(p_hwfn, p_main_ptt);
  734. memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
  735. p_hwfn->mcp_info->mfw_mb_cur, p_hwfn->mcp_info->mfw_mb_length);
  736. }
  737. int qed_hw_init(struct qed_dev *cdev,
  738. struct qed_tunn_start_params *p_tunn,
  739. bool b_hw_start,
  740. enum qed_int_mode int_mode,
  741. bool allow_npar_tx_switch,
  742. const u8 *bin_fw_data)
  743. {
  744. u32 load_code, param;
  745. int rc, mfw_rc, i;
  746. if ((int_mode == QED_INT_MODE_MSI) && (cdev->num_hwfns > 1)) {
  747. DP_NOTICE(cdev, "MSI mode is not supported for CMT devices\n");
  748. return -EINVAL;
  749. }
  750. if (IS_PF(cdev)) {
  751. rc = qed_init_fw_data(cdev, bin_fw_data);
  752. if (rc)
  753. return rc;
  754. }
  755. for_each_hwfn(cdev, i) {
  756. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  757. if (IS_VF(cdev)) {
  758. p_hwfn->b_int_enabled = 1;
  759. continue;
  760. }
  761. /* Enable DMAE in PXP */
  762. rc = qed_change_pci_hwfn(p_hwfn, p_hwfn->p_main_ptt, true);
  763. qed_calc_hw_mode(p_hwfn);
  764. rc = qed_mcp_load_req(p_hwfn, p_hwfn->p_main_ptt, &load_code);
  765. if (rc) {
  766. DP_NOTICE(p_hwfn, "Failed sending LOAD_REQ command\n");
  767. return rc;
  768. }
  769. qed_reset_mb_shadow(p_hwfn, p_hwfn->p_main_ptt);
  770. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  771. "Load request was sent. Resp:0x%x, Load code: 0x%x\n",
  772. rc, load_code);
  773. p_hwfn->first_on_engine = (load_code ==
  774. FW_MSG_CODE_DRV_LOAD_ENGINE);
  775. switch (load_code) {
  776. case FW_MSG_CODE_DRV_LOAD_ENGINE:
  777. rc = qed_hw_init_common(p_hwfn, p_hwfn->p_main_ptt,
  778. p_hwfn->hw_info.hw_mode);
  779. if (rc)
  780. break;
  781. /* Fall into */
  782. case FW_MSG_CODE_DRV_LOAD_PORT:
  783. rc = qed_hw_init_port(p_hwfn, p_hwfn->p_main_ptt,
  784. p_hwfn->hw_info.hw_mode);
  785. if (rc)
  786. break;
  787. /* Fall into */
  788. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  789. rc = qed_hw_init_pf(p_hwfn, p_hwfn->p_main_ptt,
  790. p_tunn, p_hwfn->hw_info.hw_mode,
  791. b_hw_start, int_mode,
  792. allow_npar_tx_switch);
  793. break;
  794. default:
  795. rc = -EINVAL;
  796. break;
  797. }
  798. if (rc)
  799. DP_NOTICE(p_hwfn,
  800. "init phase failed for loadcode 0x%x (rc %d)\n",
  801. load_code, rc);
  802. /* ACK mfw regardless of success or failure of initialization */
  803. mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
  804. DRV_MSG_CODE_LOAD_DONE,
  805. 0, &load_code, &param);
  806. if (rc)
  807. return rc;
  808. if (mfw_rc) {
  809. DP_NOTICE(p_hwfn, "Failed sending LOAD_DONE command\n");
  810. return mfw_rc;
  811. }
  812. /* send DCBX attention request command */
  813. DP_VERBOSE(p_hwfn,
  814. QED_MSG_DCB,
  815. "sending phony dcbx set command to trigger DCBx attention handling\n");
  816. mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
  817. DRV_MSG_CODE_SET_DCBX,
  818. 1 << DRV_MB_PARAM_DCBX_NOTIFY_SHIFT,
  819. &load_code, &param);
  820. if (mfw_rc) {
  821. DP_NOTICE(p_hwfn,
  822. "Failed to send DCBX attention request\n");
  823. return mfw_rc;
  824. }
  825. p_hwfn->hw_init_done = true;
  826. }
  827. return 0;
  828. }
  829. #define QED_HW_STOP_RETRY_LIMIT (10)
  830. static void qed_hw_timers_stop(struct qed_dev *cdev,
  831. struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  832. {
  833. int i;
  834. /* close timers */
  835. qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x0);
  836. qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_TASK, 0x0);
  837. for (i = 0; i < QED_HW_STOP_RETRY_LIMIT; i++) {
  838. if ((!qed_rd(p_hwfn, p_ptt,
  839. TM_REG_PF_SCAN_ACTIVE_CONN)) &&
  840. (!qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK)))
  841. break;
  842. /* Dependent on number of connection/tasks, possibly
  843. * 1ms sleep is required between polls
  844. */
  845. usleep_range(1000, 2000);
  846. }
  847. if (i < QED_HW_STOP_RETRY_LIMIT)
  848. return;
  849. DP_NOTICE(p_hwfn,
  850. "Timers linear scans are not over [Connection %02x Tasks %02x]\n",
  851. (u8)qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_CONN),
  852. (u8)qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK));
  853. }
  854. void qed_hw_timers_stop_all(struct qed_dev *cdev)
  855. {
  856. int j;
  857. for_each_hwfn(cdev, j) {
  858. struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
  859. struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
  860. qed_hw_timers_stop(cdev, p_hwfn, p_ptt);
  861. }
  862. }
  863. int qed_hw_stop(struct qed_dev *cdev)
  864. {
  865. int rc = 0, t_rc;
  866. int j;
  867. for_each_hwfn(cdev, j) {
  868. struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
  869. struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
  870. DP_VERBOSE(p_hwfn, NETIF_MSG_IFDOWN, "Stopping hw/fw\n");
  871. if (IS_VF(cdev)) {
  872. qed_vf_pf_int_cleanup(p_hwfn);
  873. continue;
  874. }
  875. /* mark the hw as uninitialized... */
  876. p_hwfn->hw_init_done = false;
  877. rc = qed_sp_pf_stop(p_hwfn);
  878. if (rc)
  879. DP_NOTICE(p_hwfn,
  880. "Failed to close PF against FW. Continue to stop HW to prevent illegal host access by the device\n");
  881. qed_wr(p_hwfn, p_ptt,
  882. NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
  883. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
  884. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
  885. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
  886. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
  887. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
  888. qed_hw_timers_stop(cdev, p_hwfn, p_ptt);
  889. /* Disable Attention Generation */
  890. qed_int_igu_disable_int(p_hwfn, p_ptt);
  891. qed_wr(p_hwfn, p_ptt, IGU_REG_LEADING_EDGE_LATCH, 0);
  892. qed_wr(p_hwfn, p_ptt, IGU_REG_TRAILING_EDGE_LATCH, 0);
  893. qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, true);
  894. /* Need to wait 1ms to guarantee SBs are cleared */
  895. usleep_range(1000, 2000);
  896. }
  897. if (IS_PF(cdev)) {
  898. /* Disable DMAE in PXP - in CMT, this should only be done for
  899. * first hw-function, and only after all transactions have
  900. * stopped for all active hw-functions.
  901. */
  902. t_rc = qed_change_pci_hwfn(&cdev->hwfns[0],
  903. cdev->hwfns[0].p_main_ptt, false);
  904. if (t_rc != 0)
  905. rc = t_rc;
  906. }
  907. return rc;
  908. }
  909. void qed_hw_stop_fastpath(struct qed_dev *cdev)
  910. {
  911. int j;
  912. for_each_hwfn(cdev, j) {
  913. struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
  914. struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
  915. if (IS_VF(cdev)) {
  916. qed_vf_pf_int_cleanup(p_hwfn);
  917. continue;
  918. }
  919. DP_VERBOSE(p_hwfn,
  920. NETIF_MSG_IFDOWN, "Shutting down the fastpath\n");
  921. qed_wr(p_hwfn, p_ptt,
  922. NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
  923. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
  924. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
  925. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
  926. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
  927. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
  928. qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, false);
  929. /* Need to wait 1ms to guarantee SBs are cleared */
  930. usleep_range(1000, 2000);
  931. }
  932. }
  933. void qed_hw_start_fastpath(struct qed_hwfn *p_hwfn)
  934. {
  935. if (IS_VF(p_hwfn->cdev))
  936. return;
  937. /* Re-open incoming traffic */
  938. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  939. NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x0);
  940. }
  941. static int qed_reg_assert(struct qed_hwfn *p_hwfn,
  942. struct qed_ptt *p_ptt, u32 reg, bool expected)
  943. {
  944. u32 assert_val = qed_rd(p_hwfn, p_ptt, reg);
  945. if (assert_val != expected) {
  946. DP_NOTICE(p_hwfn, "Value at address 0x%08x != 0x%08x\n",
  947. reg, expected);
  948. return -EINVAL;
  949. }
  950. return 0;
  951. }
  952. int qed_hw_reset(struct qed_dev *cdev)
  953. {
  954. int rc = 0;
  955. u32 unload_resp, unload_param;
  956. int i;
  957. for_each_hwfn(cdev, i) {
  958. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  959. if (IS_VF(cdev)) {
  960. rc = qed_vf_pf_reset(p_hwfn);
  961. if (rc)
  962. return rc;
  963. continue;
  964. }
  965. DP_VERBOSE(p_hwfn, NETIF_MSG_IFDOWN, "Resetting hw/fw\n");
  966. /* Check for incorrect states */
  967. qed_reg_assert(p_hwfn, p_hwfn->p_main_ptt,
  968. QM_REG_USG_CNT_PF_TX, 0);
  969. qed_reg_assert(p_hwfn, p_hwfn->p_main_ptt,
  970. QM_REG_USG_CNT_PF_OTHER, 0);
  971. /* Disable PF in HW blocks */
  972. qed_wr(p_hwfn, p_hwfn->p_main_ptt, DORQ_REG_PF_DB_ENABLE, 0);
  973. qed_wr(p_hwfn, p_hwfn->p_main_ptt, QM_REG_PF_EN, 0);
  974. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  975. TCFC_REG_STRONG_ENABLE_PF, 0);
  976. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  977. CCFC_REG_STRONG_ENABLE_PF, 0);
  978. /* Send unload command to MCP */
  979. rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
  980. DRV_MSG_CODE_UNLOAD_REQ,
  981. DRV_MB_PARAM_UNLOAD_WOL_MCP,
  982. &unload_resp, &unload_param);
  983. if (rc) {
  984. DP_NOTICE(p_hwfn, "qed_hw_reset: UNLOAD_REQ failed\n");
  985. unload_resp = FW_MSG_CODE_DRV_UNLOAD_ENGINE;
  986. }
  987. rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
  988. DRV_MSG_CODE_UNLOAD_DONE,
  989. 0, &unload_resp, &unload_param);
  990. if (rc) {
  991. DP_NOTICE(p_hwfn, "qed_hw_reset: UNLOAD_DONE failed\n");
  992. return rc;
  993. }
  994. }
  995. return rc;
  996. }
  997. /* Free hwfn memory and resources acquired in hw_hwfn_prepare */
  998. static void qed_hw_hwfn_free(struct qed_hwfn *p_hwfn)
  999. {
  1000. qed_ptt_pool_free(p_hwfn);
  1001. kfree(p_hwfn->hw_info.p_igu_info);
  1002. }
  1003. /* Setup bar access */
  1004. static void qed_hw_hwfn_prepare(struct qed_hwfn *p_hwfn)
  1005. {
  1006. /* clear indirect access */
  1007. qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_88_F0, 0);
  1008. qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_8C_F0, 0);
  1009. qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_90_F0, 0);
  1010. qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_94_F0, 0);
  1011. /* Clean Previous errors if such exist */
  1012. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  1013. PGLUE_B_REG_WAS_ERROR_PF_31_0_CLR, 1 << p_hwfn->abs_pf_id);
  1014. /* enable internal target-read */
  1015. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  1016. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1017. }
  1018. static void get_function_id(struct qed_hwfn *p_hwfn)
  1019. {
  1020. /* ME Register */
  1021. p_hwfn->hw_info.opaque_fid = (u16) REG_RD(p_hwfn,
  1022. PXP_PF_ME_OPAQUE_ADDR);
  1023. p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, PXP_PF_ME_CONCRETE_ADDR);
  1024. p_hwfn->abs_pf_id = (p_hwfn->hw_info.concrete_fid >> 16) & 0xf;
  1025. p_hwfn->rel_pf_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
  1026. PXP_CONCRETE_FID_PFID);
  1027. p_hwfn->port_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
  1028. PXP_CONCRETE_FID_PORT);
  1029. DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE,
  1030. "Read ME register: Concrete 0x%08x Opaque 0x%04x\n",
  1031. p_hwfn->hw_info.concrete_fid, p_hwfn->hw_info.opaque_fid);
  1032. }
  1033. static void qed_hw_set_feat(struct qed_hwfn *p_hwfn)
  1034. {
  1035. u32 *feat_num = p_hwfn->hw_info.feat_num;
  1036. int num_features = 1;
  1037. feat_num[QED_PF_L2_QUE] = min_t(u32, RESC_NUM(p_hwfn, QED_SB) /
  1038. num_features,
  1039. RESC_NUM(p_hwfn, QED_L2_QUEUE));
  1040. DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE,
  1041. "#PF_L2_QUEUES=%d #SBS=%d num_features=%d\n",
  1042. feat_num[QED_PF_L2_QUE], RESC_NUM(p_hwfn, QED_SB),
  1043. num_features);
  1044. }
  1045. static int qed_hw_get_resc(struct qed_hwfn *p_hwfn)
  1046. {
  1047. u8 enabled_func_idx = p_hwfn->enabled_func_idx;
  1048. u32 *resc_start = p_hwfn->hw_info.resc_start;
  1049. u8 num_funcs = p_hwfn->num_funcs_on_engine;
  1050. u32 *resc_num = p_hwfn->hw_info.resc_num;
  1051. struct qed_sb_cnt_info sb_cnt_info;
  1052. int i, max_vf_vlan_filters;
  1053. memset(&sb_cnt_info, 0, sizeof(sb_cnt_info));
  1054. #ifdef CONFIG_QED_SRIOV
  1055. max_vf_vlan_filters = QED_ETH_MAX_VF_NUM_VLAN_FILTERS;
  1056. #else
  1057. max_vf_vlan_filters = 0;
  1058. #endif
  1059. qed_int_get_num_sbs(p_hwfn, &sb_cnt_info);
  1060. resc_num[QED_SB] = min_t(u32,
  1061. (MAX_SB_PER_PATH_BB / num_funcs),
  1062. sb_cnt_info.sb_cnt);
  1063. resc_num[QED_L2_QUEUE] = MAX_NUM_L2_QUEUES_BB / num_funcs;
  1064. resc_num[QED_VPORT] = MAX_NUM_VPORTS_BB / num_funcs;
  1065. resc_num[QED_RSS_ENG] = ETH_RSS_ENGINE_NUM_BB / num_funcs;
  1066. resc_num[QED_PQ] = MAX_QM_TX_QUEUES_BB / num_funcs;
  1067. resc_num[QED_RL] = min_t(u32, 64, resc_num[QED_VPORT]);
  1068. resc_num[QED_MAC] = ETH_NUM_MAC_FILTERS / num_funcs;
  1069. resc_num[QED_VLAN] = (ETH_NUM_VLAN_FILTERS - 1 /*For vlan0*/) /
  1070. num_funcs;
  1071. resc_num[QED_ILT] = PXP_NUM_ILT_RECORDS_BB / num_funcs;
  1072. for (i = 0; i < QED_MAX_RESC; i++)
  1073. resc_start[i] = resc_num[i] * enabled_func_idx;
  1074. /* Sanity for ILT */
  1075. if (RESC_END(p_hwfn, QED_ILT) > PXP_NUM_ILT_RECORDS_BB) {
  1076. DP_NOTICE(p_hwfn, "Can't assign ILT pages [%08x,...,%08x]\n",
  1077. RESC_START(p_hwfn, QED_ILT),
  1078. RESC_END(p_hwfn, QED_ILT) - 1);
  1079. return -EINVAL;
  1080. }
  1081. qed_hw_set_feat(p_hwfn);
  1082. DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE,
  1083. "The numbers for each resource are:\n"
  1084. "SB = %d start = %d\n"
  1085. "L2_QUEUE = %d start = %d\n"
  1086. "VPORT = %d start = %d\n"
  1087. "PQ = %d start = %d\n"
  1088. "RL = %d start = %d\n"
  1089. "MAC = %d start = %d\n"
  1090. "VLAN = %d start = %d\n"
  1091. "ILT = %d start = %d\n",
  1092. p_hwfn->hw_info.resc_num[QED_SB],
  1093. p_hwfn->hw_info.resc_start[QED_SB],
  1094. p_hwfn->hw_info.resc_num[QED_L2_QUEUE],
  1095. p_hwfn->hw_info.resc_start[QED_L2_QUEUE],
  1096. p_hwfn->hw_info.resc_num[QED_VPORT],
  1097. p_hwfn->hw_info.resc_start[QED_VPORT],
  1098. p_hwfn->hw_info.resc_num[QED_PQ],
  1099. p_hwfn->hw_info.resc_start[QED_PQ],
  1100. p_hwfn->hw_info.resc_num[QED_RL],
  1101. p_hwfn->hw_info.resc_start[QED_RL],
  1102. p_hwfn->hw_info.resc_num[QED_MAC],
  1103. p_hwfn->hw_info.resc_start[QED_MAC],
  1104. p_hwfn->hw_info.resc_num[QED_VLAN],
  1105. p_hwfn->hw_info.resc_start[QED_VLAN],
  1106. p_hwfn->hw_info.resc_num[QED_ILT],
  1107. p_hwfn->hw_info.resc_start[QED_ILT]);
  1108. return 0;
  1109. }
  1110. static int qed_hw_get_nvm_info(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  1111. {
  1112. u32 nvm_cfg1_offset, mf_mode, addr, generic_cont0, core_cfg;
  1113. u32 port_cfg_addr, link_temp, nvm_cfg_addr, device_capabilities;
  1114. struct qed_mcp_link_params *link;
  1115. /* Read global nvm_cfg address */
  1116. nvm_cfg_addr = qed_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0);
  1117. /* Verify MCP has initialized it */
  1118. if (!nvm_cfg_addr) {
  1119. DP_NOTICE(p_hwfn, "Shared memory not initialized\n");
  1120. return -EINVAL;
  1121. }
  1122. /* Read nvm_cfg1 (Notice this is just offset, and not offsize (TBD) */
  1123. nvm_cfg1_offset = qed_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4);
  1124. addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
  1125. offsetof(struct nvm_cfg1, glob) +
  1126. offsetof(struct nvm_cfg1_glob, core_cfg);
  1127. core_cfg = qed_rd(p_hwfn, p_ptt, addr);
  1128. switch ((core_cfg & NVM_CFG1_GLOB_NETWORK_PORT_MODE_MASK) >>
  1129. NVM_CFG1_GLOB_NETWORK_PORT_MODE_OFFSET) {
  1130. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_2X40G:
  1131. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X40G;
  1132. break;
  1133. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X50G:
  1134. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X50G;
  1135. break;
  1136. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_1X100G:
  1137. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X100G;
  1138. break;
  1139. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X10G_F:
  1140. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_F;
  1141. break;
  1142. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X10G_E:
  1143. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_E;
  1144. break;
  1145. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X20G:
  1146. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X20G;
  1147. break;
  1148. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X40G:
  1149. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X40G;
  1150. break;
  1151. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X25G:
  1152. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X25G;
  1153. break;
  1154. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X25G:
  1155. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X25G;
  1156. break;
  1157. default:
  1158. DP_NOTICE(p_hwfn, "Unknown port mode in 0x%08x\n", core_cfg);
  1159. break;
  1160. }
  1161. /* Read default link configuration */
  1162. link = &p_hwfn->mcp_info->link_input;
  1163. port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
  1164. offsetof(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
  1165. link_temp = qed_rd(p_hwfn, p_ptt,
  1166. port_cfg_addr +
  1167. offsetof(struct nvm_cfg1_port, speed_cap_mask));
  1168. link_temp &= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_MASK;
  1169. link->speed.advertised_speeds = link_temp;
  1170. link_temp = link->speed.advertised_speeds;
  1171. p_hwfn->mcp_info->link_capabilities.speed_capabilities = link_temp;
  1172. link_temp = qed_rd(p_hwfn, p_ptt,
  1173. port_cfg_addr +
  1174. offsetof(struct nvm_cfg1_port, link_settings));
  1175. switch ((link_temp & NVM_CFG1_PORT_DRV_LINK_SPEED_MASK) >>
  1176. NVM_CFG1_PORT_DRV_LINK_SPEED_OFFSET) {
  1177. case NVM_CFG1_PORT_DRV_LINK_SPEED_AUTONEG:
  1178. link->speed.autoneg = true;
  1179. break;
  1180. case NVM_CFG1_PORT_DRV_LINK_SPEED_1G:
  1181. link->speed.forced_speed = 1000;
  1182. break;
  1183. case NVM_CFG1_PORT_DRV_LINK_SPEED_10G:
  1184. link->speed.forced_speed = 10000;
  1185. break;
  1186. case NVM_CFG1_PORT_DRV_LINK_SPEED_25G:
  1187. link->speed.forced_speed = 25000;
  1188. break;
  1189. case NVM_CFG1_PORT_DRV_LINK_SPEED_40G:
  1190. link->speed.forced_speed = 40000;
  1191. break;
  1192. case NVM_CFG1_PORT_DRV_LINK_SPEED_50G:
  1193. link->speed.forced_speed = 50000;
  1194. break;
  1195. case NVM_CFG1_PORT_DRV_LINK_SPEED_BB_100G:
  1196. link->speed.forced_speed = 100000;
  1197. break;
  1198. default:
  1199. DP_NOTICE(p_hwfn, "Unknown Speed in 0x%08x\n", link_temp);
  1200. }
  1201. link_temp &= NVM_CFG1_PORT_DRV_FLOW_CONTROL_MASK;
  1202. link_temp >>= NVM_CFG1_PORT_DRV_FLOW_CONTROL_OFFSET;
  1203. link->pause.autoneg = !!(link_temp &
  1204. NVM_CFG1_PORT_DRV_FLOW_CONTROL_AUTONEG);
  1205. link->pause.forced_rx = !!(link_temp &
  1206. NVM_CFG1_PORT_DRV_FLOW_CONTROL_RX);
  1207. link->pause.forced_tx = !!(link_temp &
  1208. NVM_CFG1_PORT_DRV_FLOW_CONTROL_TX);
  1209. link->loopback_mode = 0;
  1210. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  1211. "Read default link: Speed 0x%08x, Adv. Speed 0x%08x, AN: 0x%02x, PAUSE AN: 0x%02x\n",
  1212. link->speed.forced_speed, link->speed.advertised_speeds,
  1213. link->speed.autoneg, link->pause.autoneg);
  1214. /* Read Multi-function information from shmem */
  1215. addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
  1216. offsetof(struct nvm_cfg1, glob) +
  1217. offsetof(struct nvm_cfg1_glob, generic_cont0);
  1218. generic_cont0 = qed_rd(p_hwfn, p_ptt, addr);
  1219. mf_mode = (generic_cont0 & NVM_CFG1_GLOB_MF_MODE_MASK) >>
  1220. NVM_CFG1_GLOB_MF_MODE_OFFSET;
  1221. switch (mf_mode) {
  1222. case NVM_CFG1_GLOB_MF_MODE_MF_ALLOWED:
  1223. p_hwfn->cdev->mf_mode = QED_MF_OVLAN;
  1224. break;
  1225. case NVM_CFG1_GLOB_MF_MODE_NPAR1_0:
  1226. p_hwfn->cdev->mf_mode = QED_MF_NPAR;
  1227. break;
  1228. case NVM_CFG1_GLOB_MF_MODE_DEFAULT:
  1229. p_hwfn->cdev->mf_mode = QED_MF_DEFAULT;
  1230. break;
  1231. }
  1232. DP_INFO(p_hwfn, "Multi function mode is %08x\n",
  1233. p_hwfn->cdev->mf_mode);
  1234. /* Read Multi-function information from shmem */
  1235. addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
  1236. offsetof(struct nvm_cfg1, glob) +
  1237. offsetof(struct nvm_cfg1_glob, device_capabilities);
  1238. device_capabilities = qed_rd(p_hwfn, p_ptt, addr);
  1239. if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ETHERNET)
  1240. __set_bit(QED_DEV_CAP_ETH,
  1241. &p_hwfn->hw_info.device_capabilities);
  1242. if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ISCSI)
  1243. __set_bit(QED_DEV_CAP_ISCSI,
  1244. &p_hwfn->hw_info.device_capabilities);
  1245. if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ROCE)
  1246. __set_bit(QED_DEV_CAP_ROCE,
  1247. &p_hwfn->hw_info.device_capabilities);
  1248. return qed_mcp_fill_shmem_func_info(p_hwfn, p_ptt);
  1249. }
  1250. static void qed_get_num_funcs(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  1251. {
  1252. u8 num_funcs, enabled_func_idx = p_hwfn->rel_pf_id;
  1253. u32 reg_function_hide, tmp, eng_mask, low_pfs_mask;
  1254. num_funcs = MAX_NUM_PFS_BB;
  1255. /* Bit 0 of MISCS_REG_FUNCTION_HIDE indicates whether the bypass values
  1256. * in the other bits are selected.
  1257. * Bits 1-15 are for functions 1-15, respectively, and their value is
  1258. * '0' only for enabled functions (function 0 always exists and
  1259. * enabled).
  1260. * In case of CMT, only the "even" functions are enabled, and thus the
  1261. * number of functions for both hwfns is learnt from the same bits.
  1262. */
  1263. reg_function_hide = qed_rd(p_hwfn, p_ptt, MISCS_REG_FUNCTION_HIDE);
  1264. if (reg_function_hide & 0x1) {
  1265. if (QED_PATH_ID(p_hwfn) && p_hwfn->cdev->num_hwfns == 1) {
  1266. num_funcs = 0;
  1267. eng_mask = 0xaaaa;
  1268. } else {
  1269. num_funcs = 1;
  1270. eng_mask = 0x5554;
  1271. }
  1272. /* Get the number of the enabled functions on the engine */
  1273. tmp = (reg_function_hide ^ 0xffffffff) & eng_mask;
  1274. while (tmp) {
  1275. if (tmp & 0x1)
  1276. num_funcs++;
  1277. tmp >>= 0x1;
  1278. }
  1279. /* Get the PF index within the enabled functions */
  1280. low_pfs_mask = (0x1 << p_hwfn->abs_pf_id) - 1;
  1281. tmp = reg_function_hide & eng_mask & low_pfs_mask;
  1282. while (tmp) {
  1283. if (tmp & 0x1)
  1284. enabled_func_idx--;
  1285. tmp >>= 0x1;
  1286. }
  1287. }
  1288. p_hwfn->num_funcs_on_engine = num_funcs;
  1289. p_hwfn->enabled_func_idx = enabled_func_idx;
  1290. DP_VERBOSE(p_hwfn,
  1291. NETIF_MSG_PROBE,
  1292. "PF [rel_id %d, abs_id %d] occupies index %d within the %d enabled functions on the engine\n",
  1293. p_hwfn->rel_pf_id,
  1294. p_hwfn->abs_pf_id,
  1295. p_hwfn->enabled_func_idx, p_hwfn->num_funcs_on_engine);
  1296. }
  1297. static int
  1298. qed_get_hw_info(struct qed_hwfn *p_hwfn,
  1299. struct qed_ptt *p_ptt,
  1300. enum qed_pci_personality personality)
  1301. {
  1302. u32 port_mode;
  1303. int rc;
  1304. /* Since all information is common, only first hwfns should do this */
  1305. if (IS_LEAD_HWFN(p_hwfn)) {
  1306. rc = qed_iov_hw_info(p_hwfn);
  1307. if (rc)
  1308. return rc;
  1309. }
  1310. /* Read the port mode */
  1311. port_mode = qed_rd(p_hwfn, p_ptt,
  1312. CNIG_REG_NW_PORT_MODE_BB_B0);
  1313. if (port_mode < 3) {
  1314. p_hwfn->cdev->num_ports_in_engines = 1;
  1315. } else if (port_mode <= 5) {
  1316. p_hwfn->cdev->num_ports_in_engines = 2;
  1317. } else {
  1318. DP_NOTICE(p_hwfn, "PORT MODE: %d not supported\n",
  1319. p_hwfn->cdev->num_ports_in_engines);
  1320. /* Default num_ports_in_engines to something */
  1321. p_hwfn->cdev->num_ports_in_engines = 1;
  1322. }
  1323. qed_hw_get_nvm_info(p_hwfn, p_ptt);
  1324. rc = qed_int_igu_read_cam(p_hwfn, p_ptt);
  1325. if (rc)
  1326. return rc;
  1327. if (qed_mcp_is_init(p_hwfn))
  1328. ether_addr_copy(p_hwfn->hw_info.hw_mac_addr,
  1329. p_hwfn->mcp_info->func_info.mac);
  1330. else
  1331. eth_random_addr(p_hwfn->hw_info.hw_mac_addr);
  1332. if (qed_mcp_is_init(p_hwfn)) {
  1333. if (p_hwfn->mcp_info->func_info.ovlan != QED_MCP_VLAN_UNSET)
  1334. p_hwfn->hw_info.ovlan =
  1335. p_hwfn->mcp_info->func_info.ovlan;
  1336. qed_mcp_cmd_port_init(p_hwfn, p_ptt);
  1337. }
  1338. if (qed_mcp_is_init(p_hwfn)) {
  1339. enum qed_pci_personality protocol;
  1340. protocol = p_hwfn->mcp_info->func_info.protocol;
  1341. p_hwfn->hw_info.personality = protocol;
  1342. }
  1343. qed_get_num_funcs(p_hwfn, p_ptt);
  1344. return qed_hw_get_resc(p_hwfn);
  1345. }
  1346. static int qed_get_dev_info(struct qed_dev *cdev)
  1347. {
  1348. struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
  1349. u32 tmp;
  1350. /* Read Vendor Id / Device Id */
  1351. pci_read_config_word(cdev->pdev, PCI_VENDOR_ID, &cdev->vendor_id);
  1352. pci_read_config_word(cdev->pdev, PCI_DEVICE_ID, &cdev->device_id);
  1353. cdev->chip_num = (u16)qed_rd(p_hwfn, p_hwfn->p_main_ptt,
  1354. MISCS_REG_CHIP_NUM);
  1355. cdev->chip_rev = (u16)qed_rd(p_hwfn, p_hwfn->p_main_ptt,
  1356. MISCS_REG_CHIP_REV);
  1357. MASK_FIELD(CHIP_REV, cdev->chip_rev);
  1358. cdev->type = QED_DEV_TYPE_BB;
  1359. /* Learn number of HW-functions */
  1360. tmp = qed_rd(p_hwfn, p_hwfn->p_main_ptt,
  1361. MISCS_REG_CMT_ENABLED_FOR_PAIR);
  1362. if (tmp & (1 << p_hwfn->rel_pf_id)) {
  1363. DP_NOTICE(cdev->hwfns, "device in CMT mode\n");
  1364. cdev->num_hwfns = 2;
  1365. } else {
  1366. cdev->num_hwfns = 1;
  1367. }
  1368. cdev->chip_bond_id = qed_rd(p_hwfn, p_hwfn->p_main_ptt,
  1369. MISCS_REG_CHIP_TEST_REG) >> 4;
  1370. MASK_FIELD(CHIP_BOND_ID, cdev->chip_bond_id);
  1371. cdev->chip_metal = (u16)qed_rd(p_hwfn, p_hwfn->p_main_ptt,
  1372. MISCS_REG_CHIP_METAL);
  1373. MASK_FIELD(CHIP_METAL, cdev->chip_metal);
  1374. DP_INFO(cdev->hwfns,
  1375. "Chip details - Num: %04x Rev: %04x Bond id: %04x Metal: %04x\n",
  1376. cdev->chip_num, cdev->chip_rev,
  1377. cdev->chip_bond_id, cdev->chip_metal);
  1378. if (QED_IS_BB(cdev) && CHIP_REV_IS_A0(cdev)) {
  1379. DP_NOTICE(cdev->hwfns,
  1380. "The chip type/rev (BB A0) is not supported!\n");
  1381. return -EINVAL;
  1382. }
  1383. return 0;
  1384. }
  1385. static int qed_hw_prepare_single(struct qed_hwfn *p_hwfn,
  1386. void __iomem *p_regview,
  1387. void __iomem *p_doorbells,
  1388. enum qed_pci_personality personality)
  1389. {
  1390. int rc = 0;
  1391. /* Split PCI bars evenly between hwfns */
  1392. p_hwfn->regview = p_regview;
  1393. p_hwfn->doorbells = p_doorbells;
  1394. if (IS_VF(p_hwfn->cdev))
  1395. return qed_vf_hw_prepare(p_hwfn);
  1396. /* Validate that chip access is feasible */
  1397. if (REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR) == 0xffffffff) {
  1398. DP_ERR(p_hwfn,
  1399. "Reading the ME register returns all Fs; Preventing further chip access\n");
  1400. return -EINVAL;
  1401. }
  1402. get_function_id(p_hwfn);
  1403. /* Allocate PTT pool */
  1404. rc = qed_ptt_pool_alloc(p_hwfn);
  1405. if (rc)
  1406. goto err0;
  1407. /* Allocate the main PTT */
  1408. p_hwfn->p_main_ptt = qed_get_reserved_ptt(p_hwfn, RESERVED_PTT_MAIN);
  1409. /* First hwfn learns basic information, e.g., number of hwfns */
  1410. if (!p_hwfn->my_id) {
  1411. rc = qed_get_dev_info(p_hwfn->cdev);
  1412. if (rc)
  1413. goto err1;
  1414. }
  1415. qed_hw_hwfn_prepare(p_hwfn);
  1416. /* Initialize MCP structure */
  1417. rc = qed_mcp_cmd_init(p_hwfn, p_hwfn->p_main_ptt);
  1418. if (rc) {
  1419. DP_NOTICE(p_hwfn, "Failed initializing mcp command\n");
  1420. goto err1;
  1421. }
  1422. /* Read the device configuration information from the HW and SHMEM */
  1423. rc = qed_get_hw_info(p_hwfn, p_hwfn->p_main_ptt, personality);
  1424. if (rc) {
  1425. DP_NOTICE(p_hwfn, "Failed to get HW information\n");
  1426. goto err2;
  1427. }
  1428. /* Allocate the init RT array and initialize the init-ops engine */
  1429. rc = qed_init_alloc(p_hwfn);
  1430. if (rc)
  1431. goto err2;
  1432. return rc;
  1433. err2:
  1434. if (IS_LEAD_HWFN(p_hwfn))
  1435. qed_iov_free_hw_info(p_hwfn->cdev);
  1436. qed_mcp_free(p_hwfn);
  1437. err1:
  1438. qed_hw_hwfn_free(p_hwfn);
  1439. err0:
  1440. return rc;
  1441. }
  1442. int qed_hw_prepare(struct qed_dev *cdev,
  1443. int personality)
  1444. {
  1445. struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
  1446. int rc;
  1447. /* Store the precompiled init data ptrs */
  1448. if (IS_PF(cdev))
  1449. qed_init_iro_array(cdev);
  1450. /* Initialize the first hwfn - will learn number of hwfns */
  1451. rc = qed_hw_prepare_single(p_hwfn,
  1452. cdev->regview,
  1453. cdev->doorbells, personality);
  1454. if (rc)
  1455. return rc;
  1456. personality = p_hwfn->hw_info.personality;
  1457. /* Initialize the rest of the hwfns */
  1458. if (cdev->num_hwfns > 1) {
  1459. void __iomem *p_regview, *p_doorbell;
  1460. u8 __iomem *addr;
  1461. /* adjust bar offset for second engine */
  1462. addr = cdev->regview + qed_hw_bar_size(p_hwfn, BAR_ID_0) / 2;
  1463. p_regview = addr;
  1464. /* adjust doorbell bar offset for second engine */
  1465. addr = cdev->doorbells + qed_hw_bar_size(p_hwfn, BAR_ID_1) / 2;
  1466. p_doorbell = addr;
  1467. /* prepare second hw function */
  1468. rc = qed_hw_prepare_single(&cdev->hwfns[1], p_regview,
  1469. p_doorbell, personality);
  1470. /* in case of error, need to free the previously
  1471. * initiliazed hwfn 0.
  1472. */
  1473. if (rc) {
  1474. if (IS_PF(cdev)) {
  1475. qed_init_free(p_hwfn);
  1476. qed_mcp_free(p_hwfn);
  1477. qed_hw_hwfn_free(p_hwfn);
  1478. }
  1479. }
  1480. }
  1481. return rc;
  1482. }
  1483. void qed_hw_remove(struct qed_dev *cdev)
  1484. {
  1485. int i;
  1486. for_each_hwfn(cdev, i) {
  1487. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1488. if (IS_VF(cdev)) {
  1489. qed_vf_pf_release(p_hwfn);
  1490. continue;
  1491. }
  1492. qed_init_free(p_hwfn);
  1493. qed_hw_hwfn_free(p_hwfn);
  1494. qed_mcp_free(p_hwfn);
  1495. }
  1496. qed_iov_free_hw_info(cdev);
  1497. }
  1498. static void qed_chain_free_next_ptr(struct qed_dev *cdev,
  1499. struct qed_chain *p_chain)
  1500. {
  1501. void *p_virt = p_chain->p_virt_addr, *p_virt_next = NULL;
  1502. dma_addr_t p_phys = p_chain->p_phys_addr, p_phys_next = 0;
  1503. struct qed_chain_next *p_next;
  1504. u32 size, i;
  1505. if (!p_virt)
  1506. return;
  1507. size = p_chain->elem_size * p_chain->usable_per_page;
  1508. for (i = 0; i < p_chain->page_cnt; i++) {
  1509. if (!p_virt)
  1510. break;
  1511. p_next = (struct qed_chain_next *)((u8 *)p_virt + size);
  1512. p_virt_next = p_next->next_virt;
  1513. p_phys_next = HILO_DMA_REGPAIR(p_next->next_phys);
  1514. dma_free_coherent(&cdev->pdev->dev,
  1515. QED_CHAIN_PAGE_SIZE, p_virt, p_phys);
  1516. p_virt = p_virt_next;
  1517. p_phys = p_phys_next;
  1518. }
  1519. }
  1520. static void qed_chain_free_single(struct qed_dev *cdev,
  1521. struct qed_chain *p_chain)
  1522. {
  1523. if (!p_chain->p_virt_addr)
  1524. return;
  1525. dma_free_coherent(&cdev->pdev->dev,
  1526. QED_CHAIN_PAGE_SIZE,
  1527. p_chain->p_virt_addr, p_chain->p_phys_addr);
  1528. }
  1529. static void qed_chain_free_pbl(struct qed_dev *cdev, struct qed_chain *p_chain)
  1530. {
  1531. void **pp_virt_addr_tbl = p_chain->pbl.pp_virt_addr_tbl;
  1532. u32 page_cnt = p_chain->page_cnt, i, pbl_size;
  1533. u8 *p_pbl_virt = p_chain->pbl.p_virt_table;
  1534. if (!pp_virt_addr_tbl)
  1535. return;
  1536. if (!p_chain->pbl.p_virt_table)
  1537. goto out;
  1538. for (i = 0; i < page_cnt; i++) {
  1539. if (!pp_virt_addr_tbl[i])
  1540. break;
  1541. dma_free_coherent(&cdev->pdev->dev,
  1542. QED_CHAIN_PAGE_SIZE,
  1543. pp_virt_addr_tbl[i],
  1544. *(dma_addr_t *)p_pbl_virt);
  1545. p_pbl_virt += QED_CHAIN_PBL_ENTRY_SIZE;
  1546. }
  1547. pbl_size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
  1548. dma_free_coherent(&cdev->pdev->dev,
  1549. pbl_size,
  1550. p_chain->pbl.p_virt_table, p_chain->pbl.p_phys_table);
  1551. out:
  1552. vfree(p_chain->pbl.pp_virt_addr_tbl);
  1553. }
  1554. void qed_chain_free(struct qed_dev *cdev, struct qed_chain *p_chain)
  1555. {
  1556. switch (p_chain->mode) {
  1557. case QED_CHAIN_MODE_NEXT_PTR:
  1558. qed_chain_free_next_ptr(cdev, p_chain);
  1559. break;
  1560. case QED_CHAIN_MODE_SINGLE:
  1561. qed_chain_free_single(cdev, p_chain);
  1562. break;
  1563. case QED_CHAIN_MODE_PBL:
  1564. qed_chain_free_pbl(cdev, p_chain);
  1565. break;
  1566. }
  1567. }
  1568. static int
  1569. qed_chain_alloc_sanity_check(struct qed_dev *cdev,
  1570. enum qed_chain_cnt_type cnt_type,
  1571. size_t elem_size, u32 page_cnt)
  1572. {
  1573. u64 chain_size = ELEMS_PER_PAGE(elem_size) * page_cnt;
  1574. /* The actual chain size can be larger than the maximal possible value
  1575. * after rounding up the requested elements number to pages, and after
  1576. * taking into acount the unusuable elements (next-ptr elements).
  1577. * The size of a "u16" chain can be (U16_MAX + 1) since the chain
  1578. * size/capacity fields are of a u32 type.
  1579. */
  1580. if ((cnt_type == QED_CHAIN_CNT_TYPE_U16 &&
  1581. chain_size > 0x10000) ||
  1582. (cnt_type == QED_CHAIN_CNT_TYPE_U32 &&
  1583. chain_size > 0x100000000ULL)) {
  1584. DP_NOTICE(cdev,
  1585. "The actual chain size (0x%llx) is larger than the maximal possible value\n",
  1586. chain_size);
  1587. return -EINVAL;
  1588. }
  1589. return 0;
  1590. }
  1591. static int
  1592. qed_chain_alloc_next_ptr(struct qed_dev *cdev, struct qed_chain *p_chain)
  1593. {
  1594. void *p_virt = NULL, *p_virt_prev = NULL;
  1595. dma_addr_t p_phys = 0;
  1596. u32 i;
  1597. for (i = 0; i < p_chain->page_cnt; i++) {
  1598. p_virt = dma_alloc_coherent(&cdev->pdev->dev,
  1599. QED_CHAIN_PAGE_SIZE,
  1600. &p_phys, GFP_KERNEL);
  1601. if (!p_virt)
  1602. return -ENOMEM;
  1603. if (i == 0) {
  1604. qed_chain_init_mem(p_chain, p_virt, p_phys);
  1605. qed_chain_reset(p_chain);
  1606. } else {
  1607. qed_chain_init_next_ptr_elem(p_chain, p_virt_prev,
  1608. p_virt, p_phys);
  1609. }
  1610. p_virt_prev = p_virt;
  1611. }
  1612. /* Last page's next element should point to the beginning of the
  1613. * chain.
  1614. */
  1615. qed_chain_init_next_ptr_elem(p_chain, p_virt_prev,
  1616. p_chain->p_virt_addr,
  1617. p_chain->p_phys_addr);
  1618. return 0;
  1619. }
  1620. static int
  1621. qed_chain_alloc_single(struct qed_dev *cdev, struct qed_chain *p_chain)
  1622. {
  1623. dma_addr_t p_phys = 0;
  1624. void *p_virt = NULL;
  1625. p_virt = dma_alloc_coherent(&cdev->pdev->dev,
  1626. QED_CHAIN_PAGE_SIZE, &p_phys, GFP_KERNEL);
  1627. if (!p_virt)
  1628. return -ENOMEM;
  1629. qed_chain_init_mem(p_chain, p_virt, p_phys);
  1630. qed_chain_reset(p_chain);
  1631. return 0;
  1632. }
  1633. static int qed_chain_alloc_pbl(struct qed_dev *cdev, struct qed_chain *p_chain)
  1634. {
  1635. u32 page_cnt = p_chain->page_cnt, size, i;
  1636. dma_addr_t p_phys = 0, p_pbl_phys = 0;
  1637. void **pp_virt_addr_tbl = NULL;
  1638. u8 *p_pbl_virt = NULL;
  1639. void *p_virt = NULL;
  1640. size = page_cnt * sizeof(*pp_virt_addr_tbl);
  1641. pp_virt_addr_tbl = vzalloc(size);
  1642. if (!pp_virt_addr_tbl)
  1643. return -ENOMEM;
  1644. /* The allocation of the PBL table is done with its full size, since it
  1645. * is expected to be successive.
  1646. * qed_chain_init_pbl_mem() is called even in a case of an allocation
  1647. * failure, since pp_virt_addr_tbl was previously allocated, and it
  1648. * should be saved to allow its freeing during the error flow.
  1649. */
  1650. size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
  1651. p_pbl_virt = dma_alloc_coherent(&cdev->pdev->dev,
  1652. size, &p_pbl_phys, GFP_KERNEL);
  1653. qed_chain_init_pbl_mem(p_chain, p_pbl_virt, p_pbl_phys,
  1654. pp_virt_addr_tbl);
  1655. if (!p_pbl_virt)
  1656. return -ENOMEM;
  1657. for (i = 0; i < page_cnt; i++) {
  1658. p_virt = dma_alloc_coherent(&cdev->pdev->dev,
  1659. QED_CHAIN_PAGE_SIZE,
  1660. &p_phys, GFP_KERNEL);
  1661. if (!p_virt)
  1662. return -ENOMEM;
  1663. if (i == 0) {
  1664. qed_chain_init_mem(p_chain, p_virt, p_phys);
  1665. qed_chain_reset(p_chain);
  1666. }
  1667. /* Fill the PBL table with the physical address of the page */
  1668. *(dma_addr_t *)p_pbl_virt = p_phys;
  1669. /* Keep the virtual address of the page */
  1670. p_chain->pbl.pp_virt_addr_tbl[i] = p_virt;
  1671. p_pbl_virt += QED_CHAIN_PBL_ENTRY_SIZE;
  1672. }
  1673. return 0;
  1674. }
  1675. int qed_chain_alloc(struct qed_dev *cdev,
  1676. enum qed_chain_use_mode intended_use,
  1677. enum qed_chain_mode mode,
  1678. enum qed_chain_cnt_type cnt_type,
  1679. u32 num_elems, size_t elem_size, struct qed_chain *p_chain)
  1680. {
  1681. u32 page_cnt;
  1682. int rc = 0;
  1683. if (mode == QED_CHAIN_MODE_SINGLE)
  1684. page_cnt = 1;
  1685. else
  1686. page_cnt = QED_CHAIN_PAGE_CNT(num_elems, elem_size, mode);
  1687. rc = qed_chain_alloc_sanity_check(cdev, cnt_type, elem_size, page_cnt);
  1688. if (rc) {
  1689. DP_NOTICE(cdev,
  1690. "Cannot allocate a chain with the given arguments:\n");
  1691. DP_NOTICE(cdev,
  1692. "[use_mode %d, mode %d, cnt_type %d, num_elems %d, elem_size %zu]\n",
  1693. intended_use, mode, cnt_type, num_elems, elem_size);
  1694. return rc;
  1695. }
  1696. qed_chain_init_params(p_chain, page_cnt, (u8) elem_size, intended_use,
  1697. mode, cnt_type);
  1698. switch (mode) {
  1699. case QED_CHAIN_MODE_NEXT_PTR:
  1700. rc = qed_chain_alloc_next_ptr(cdev, p_chain);
  1701. break;
  1702. case QED_CHAIN_MODE_SINGLE:
  1703. rc = qed_chain_alloc_single(cdev, p_chain);
  1704. break;
  1705. case QED_CHAIN_MODE_PBL:
  1706. rc = qed_chain_alloc_pbl(cdev, p_chain);
  1707. break;
  1708. }
  1709. if (rc)
  1710. goto nomem;
  1711. return 0;
  1712. nomem:
  1713. qed_chain_free(cdev, p_chain);
  1714. return rc;
  1715. }
  1716. int qed_fw_l2_queue(struct qed_hwfn *p_hwfn, u16 src_id, u16 *dst_id)
  1717. {
  1718. if (src_id >= RESC_NUM(p_hwfn, QED_L2_QUEUE)) {
  1719. u16 min, max;
  1720. min = (u16) RESC_START(p_hwfn, QED_L2_QUEUE);
  1721. max = min + RESC_NUM(p_hwfn, QED_L2_QUEUE);
  1722. DP_NOTICE(p_hwfn,
  1723. "l2_queue id [%d] is not valid, available indices [%d - %d]\n",
  1724. src_id, min, max);
  1725. return -EINVAL;
  1726. }
  1727. *dst_id = RESC_START(p_hwfn, QED_L2_QUEUE) + src_id;
  1728. return 0;
  1729. }
  1730. int qed_fw_vport(struct qed_hwfn *p_hwfn, u8 src_id, u8 *dst_id)
  1731. {
  1732. if (src_id >= RESC_NUM(p_hwfn, QED_VPORT)) {
  1733. u8 min, max;
  1734. min = (u8)RESC_START(p_hwfn, QED_VPORT);
  1735. max = min + RESC_NUM(p_hwfn, QED_VPORT);
  1736. DP_NOTICE(p_hwfn,
  1737. "vport id [%d] is not valid, available indices [%d - %d]\n",
  1738. src_id, min, max);
  1739. return -EINVAL;
  1740. }
  1741. *dst_id = RESC_START(p_hwfn, QED_VPORT) + src_id;
  1742. return 0;
  1743. }
  1744. int qed_fw_rss_eng(struct qed_hwfn *p_hwfn, u8 src_id, u8 *dst_id)
  1745. {
  1746. if (src_id >= RESC_NUM(p_hwfn, QED_RSS_ENG)) {
  1747. u8 min, max;
  1748. min = (u8)RESC_START(p_hwfn, QED_RSS_ENG);
  1749. max = min + RESC_NUM(p_hwfn, QED_RSS_ENG);
  1750. DP_NOTICE(p_hwfn,
  1751. "rss_eng id [%d] is not valid, available indices [%d - %d]\n",
  1752. src_id, min, max);
  1753. return -EINVAL;
  1754. }
  1755. *dst_id = RESC_START(p_hwfn, QED_RSS_ENG) + src_id;
  1756. return 0;
  1757. }
  1758. static int qed_set_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
  1759. u32 hw_addr, void *p_eth_qzone,
  1760. size_t eth_qzone_size, u8 timeset)
  1761. {
  1762. struct coalescing_timeset *p_coal_timeset;
  1763. if (p_hwfn->cdev->int_coalescing_mode != QED_COAL_MODE_ENABLE) {
  1764. DP_NOTICE(p_hwfn, "Coalescing configuration not enabled\n");
  1765. return -EINVAL;
  1766. }
  1767. p_coal_timeset = p_eth_qzone;
  1768. memset(p_coal_timeset, 0, eth_qzone_size);
  1769. SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_TIMESET, timeset);
  1770. SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_VALID, 1);
  1771. qed_memcpy_to(p_hwfn, p_ptt, hw_addr, p_eth_qzone, eth_qzone_size);
  1772. return 0;
  1773. }
  1774. int qed_set_rxq_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
  1775. u16 coalesce, u8 qid, u16 sb_id)
  1776. {
  1777. struct ustorm_eth_queue_zone eth_qzone;
  1778. u8 timeset, timer_res;
  1779. u16 fw_qid = 0;
  1780. u32 address;
  1781. int rc;
  1782. /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
  1783. if (coalesce <= 0x7F) {
  1784. timer_res = 0;
  1785. } else if (coalesce <= 0xFF) {
  1786. timer_res = 1;
  1787. } else if (coalesce <= 0x1FF) {
  1788. timer_res = 2;
  1789. } else {
  1790. DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
  1791. return -EINVAL;
  1792. }
  1793. timeset = (u8)(coalesce >> timer_res);
  1794. rc = qed_fw_l2_queue(p_hwfn, (u16)qid, &fw_qid);
  1795. if (rc)
  1796. return rc;
  1797. rc = qed_int_set_timer_res(p_hwfn, p_ptt, timer_res, sb_id, false);
  1798. if (rc)
  1799. goto out;
  1800. address = BAR0_MAP_REG_USDM_RAM + USTORM_ETH_QUEUE_ZONE_OFFSET(fw_qid);
  1801. rc = qed_set_coalesce(p_hwfn, p_ptt, address, &eth_qzone,
  1802. sizeof(struct ustorm_eth_queue_zone), timeset);
  1803. if (rc)
  1804. goto out;
  1805. p_hwfn->cdev->rx_coalesce_usecs = coalesce;
  1806. out:
  1807. return rc;
  1808. }
  1809. int qed_set_txq_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
  1810. u16 coalesce, u8 qid, u16 sb_id)
  1811. {
  1812. struct xstorm_eth_queue_zone eth_qzone;
  1813. u8 timeset, timer_res;
  1814. u16 fw_qid = 0;
  1815. u32 address;
  1816. int rc;
  1817. /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
  1818. if (coalesce <= 0x7F) {
  1819. timer_res = 0;
  1820. } else if (coalesce <= 0xFF) {
  1821. timer_res = 1;
  1822. } else if (coalesce <= 0x1FF) {
  1823. timer_res = 2;
  1824. } else {
  1825. DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
  1826. return -EINVAL;
  1827. }
  1828. timeset = (u8)(coalesce >> timer_res);
  1829. rc = qed_fw_l2_queue(p_hwfn, (u16)qid, &fw_qid);
  1830. if (rc)
  1831. return rc;
  1832. rc = qed_int_set_timer_res(p_hwfn, p_ptt, timer_res, sb_id, true);
  1833. if (rc)
  1834. goto out;
  1835. address = BAR0_MAP_REG_XSDM_RAM + XSTORM_ETH_QUEUE_ZONE_OFFSET(fw_qid);
  1836. rc = qed_set_coalesce(p_hwfn, p_ptt, address, &eth_qzone,
  1837. sizeof(struct xstorm_eth_queue_zone), timeset);
  1838. if (rc)
  1839. goto out;
  1840. p_hwfn->cdev->tx_coalesce_usecs = coalesce;
  1841. out:
  1842. return rc;
  1843. }
  1844. /* Calculate final WFQ values for all vports and configure them.
  1845. * After this configuration each vport will have
  1846. * approx min rate = min_pf_rate * (vport_wfq / QED_WFQ_UNIT)
  1847. */
  1848. static void qed_configure_wfq_for_all_vports(struct qed_hwfn *p_hwfn,
  1849. struct qed_ptt *p_ptt,
  1850. u32 min_pf_rate)
  1851. {
  1852. struct init_qm_vport_params *vport_params;
  1853. int i;
  1854. vport_params = p_hwfn->qm_info.qm_vport_params;
  1855. for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
  1856. u32 wfq_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
  1857. vport_params[i].vport_wfq = (wfq_speed * QED_WFQ_UNIT) /
  1858. min_pf_rate;
  1859. qed_init_vport_wfq(p_hwfn, p_ptt,
  1860. vport_params[i].first_tx_pq_id,
  1861. vport_params[i].vport_wfq);
  1862. }
  1863. }
  1864. static void qed_init_wfq_default_param(struct qed_hwfn *p_hwfn,
  1865. u32 min_pf_rate)
  1866. {
  1867. int i;
  1868. for (i = 0; i < p_hwfn->qm_info.num_vports; i++)
  1869. p_hwfn->qm_info.qm_vport_params[i].vport_wfq = 1;
  1870. }
  1871. static void qed_disable_wfq_for_all_vports(struct qed_hwfn *p_hwfn,
  1872. struct qed_ptt *p_ptt,
  1873. u32 min_pf_rate)
  1874. {
  1875. struct init_qm_vport_params *vport_params;
  1876. int i;
  1877. vport_params = p_hwfn->qm_info.qm_vport_params;
  1878. for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
  1879. qed_init_wfq_default_param(p_hwfn, min_pf_rate);
  1880. qed_init_vport_wfq(p_hwfn, p_ptt,
  1881. vport_params[i].first_tx_pq_id,
  1882. vport_params[i].vport_wfq);
  1883. }
  1884. }
  1885. /* This function performs several validations for WFQ
  1886. * configuration and required min rate for a given vport
  1887. * 1. req_rate must be greater than one percent of min_pf_rate.
  1888. * 2. req_rate should not cause other vports [not configured for WFQ explicitly]
  1889. * rates to get less than one percent of min_pf_rate.
  1890. * 3. total_req_min_rate [all vports min rate sum] shouldn't exceed min_pf_rate.
  1891. */
  1892. static int qed_init_wfq_param(struct qed_hwfn *p_hwfn,
  1893. u16 vport_id, u32 req_rate, u32 min_pf_rate)
  1894. {
  1895. u32 total_req_min_rate = 0, total_left_rate = 0, left_rate_per_vp = 0;
  1896. int non_requested_count = 0, req_count = 0, i, num_vports;
  1897. num_vports = p_hwfn->qm_info.num_vports;
  1898. /* Accounting for the vports which are configured for WFQ explicitly */
  1899. for (i = 0; i < num_vports; i++) {
  1900. u32 tmp_speed;
  1901. if ((i != vport_id) &&
  1902. p_hwfn->qm_info.wfq_data[i].configured) {
  1903. req_count++;
  1904. tmp_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
  1905. total_req_min_rate += tmp_speed;
  1906. }
  1907. }
  1908. /* Include current vport data as well */
  1909. req_count++;
  1910. total_req_min_rate += req_rate;
  1911. non_requested_count = num_vports - req_count;
  1912. if (req_rate < min_pf_rate / QED_WFQ_UNIT) {
  1913. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  1914. "Vport [%d] - Requested rate[%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
  1915. vport_id, req_rate, min_pf_rate);
  1916. return -EINVAL;
  1917. }
  1918. if (num_vports > QED_WFQ_UNIT) {
  1919. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  1920. "Number of vports is greater than %d\n",
  1921. QED_WFQ_UNIT);
  1922. return -EINVAL;
  1923. }
  1924. if (total_req_min_rate > min_pf_rate) {
  1925. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  1926. "Total requested min rate for all vports[%d Mbps] is greater than configured PF min rate[%d Mbps]\n",
  1927. total_req_min_rate, min_pf_rate);
  1928. return -EINVAL;
  1929. }
  1930. total_left_rate = min_pf_rate - total_req_min_rate;
  1931. left_rate_per_vp = total_left_rate / non_requested_count;
  1932. if (left_rate_per_vp < min_pf_rate / QED_WFQ_UNIT) {
  1933. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  1934. "Non WFQ configured vports rate [%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
  1935. left_rate_per_vp, min_pf_rate);
  1936. return -EINVAL;
  1937. }
  1938. p_hwfn->qm_info.wfq_data[vport_id].min_speed = req_rate;
  1939. p_hwfn->qm_info.wfq_data[vport_id].configured = true;
  1940. for (i = 0; i < num_vports; i++) {
  1941. if (p_hwfn->qm_info.wfq_data[i].configured)
  1942. continue;
  1943. p_hwfn->qm_info.wfq_data[i].min_speed = left_rate_per_vp;
  1944. }
  1945. return 0;
  1946. }
  1947. static int __qed_configure_vport_wfq(struct qed_hwfn *p_hwfn,
  1948. struct qed_ptt *p_ptt, u16 vp_id, u32 rate)
  1949. {
  1950. struct qed_mcp_link_state *p_link;
  1951. int rc = 0;
  1952. p_link = &p_hwfn->cdev->hwfns[0].mcp_info->link_output;
  1953. if (!p_link->min_pf_rate) {
  1954. p_hwfn->qm_info.wfq_data[vp_id].min_speed = rate;
  1955. p_hwfn->qm_info.wfq_data[vp_id].configured = true;
  1956. return rc;
  1957. }
  1958. rc = qed_init_wfq_param(p_hwfn, vp_id, rate, p_link->min_pf_rate);
  1959. if (!rc)
  1960. qed_configure_wfq_for_all_vports(p_hwfn, p_ptt,
  1961. p_link->min_pf_rate);
  1962. else
  1963. DP_NOTICE(p_hwfn,
  1964. "Validation failed while configuring min rate\n");
  1965. return rc;
  1966. }
  1967. static int __qed_configure_vp_wfq_on_link_change(struct qed_hwfn *p_hwfn,
  1968. struct qed_ptt *p_ptt,
  1969. u32 min_pf_rate)
  1970. {
  1971. bool use_wfq = false;
  1972. int rc = 0;
  1973. u16 i;
  1974. /* Validate all pre configured vports for wfq */
  1975. for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
  1976. u32 rate;
  1977. if (!p_hwfn->qm_info.wfq_data[i].configured)
  1978. continue;
  1979. rate = p_hwfn->qm_info.wfq_data[i].min_speed;
  1980. use_wfq = true;
  1981. rc = qed_init_wfq_param(p_hwfn, i, rate, min_pf_rate);
  1982. if (rc) {
  1983. DP_NOTICE(p_hwfn,
  1984. "WFQ validation failed while configuring min rate\n");
  1985. break;
  1986. }
  1987. }
  1988. if (!rc && use_wfq)
  1989. qed_configure_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
  1990. else
  1991. qed_disable_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
  1992. return rc;
  1993. }
  1994. /* Main API for qed clients to configure vport min rate.
  1995. * vp_id - vport id in PF Range[0 - (total_num_vports_per_pf - 1)]
  1996. * rate - Speed in Mbps needs to be assigned to a given vport.
  1997. */
  1998. int qed_configure_vport_wfq(struct qed_dev *cdev, u16 vp_id, u32 rate)
  1999. {
  2000. int i, rc = -EINVAL;
  2001. /* Currently not supported; Might change in future */
  2002. if (cdev->num_hwfns > 1) {
  2003. DP_NOTICE(cdev,
  2004. "WFQ configuration is not supported for this device\n");
  2005. return rc;
  2006. }
  2007. for_each_hwfn(cdev, i) {
  2008. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  2009. struct qed_ptt *p_ptt;
  2010. p_ptt = qed_ptt_acquire(p_hwfn);
  2011. if (!p_ptt)
  2012. return -EBUSY;
  2013. rc = __qed_configure_vport_wfq(p_hwfn, p_ptt, vp_id, rate);
  2014. if (rc) {
  2015. qed_ptt_release(p_hwfn, p_ptt);
  2016. return rc;
  2017. }
  2018. qed_ptt_release(p_hwfn, p_ptt);
  2019. }
  2020. return rc;
  2021. }
  2022. /* API to configure WFQ from mcp link change */
  2023. void qed_configure_vp_wfq_on_link_change(struct qed_dev *cdev, u32 min_pf_rate)
  2024. {
  2025. int i;
  2026. if (cdev->num_hwfns > 1) {
  2027. DP_VERBOSE(cdev,
  2028. NETIF_MSG_LINK,
  2029. "WFQ configuration is not supported for this device\n");
  2030. return;
  2031. }
  2032. for_each_hwfn(cdev, i) {
  2033. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  2034. __qed_configure_vp_wfq_on_link_change(p_hwfn,
  2035. p_hwfn->p_dpc_ptt,
  2036. min_pf_rate);
  2037. }
  2038. }
  2039. int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
  2040. struct qed_ptt *p_ptt,
  2041. struct qed_mcp_link_state *p_link,
  2042. u8 max_bw)
  2043. {
  2044. int rc = 0;
  2045. p_hwfn->mcp_info->func_info.bandwidth_max = max_bw;
  2046. if (!p_link->line_speed && (max_bw != 100))
  2047. return rc;
  2048. p_link->speed = (p_link->line_speed * max_bw) / 100;
  2049. p_hwfn->qm_info.pf_rl = p_link->speed;
  2050. /* Since the limiter also affects Tx-switched traffic, we don't want it
  2051. * to limit such traffic in case there's no actual limit.
  2052. * In that case, set limit to imaginary high boundary.
  2053. */
  2054. if (max_bw == 100)
  2055. p_hwfn->qm_info.pf_rl = 100000;
  2056. rc = qed_init_pf_rl(p_hwfn, p_ptt, p_hwfn->rel_pf_id,
  2057. p_hwfn->qm_info.pf_rl);
  2058. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  2059. "Configured MAX bandwidth to be %08x Mb/sec\n",
  2060. p_link->speed);
  2061. return rc;
  2062. }
  2063. /* Main API to configure PF max bandwidth where bw range is [1 - 100] */
  2064. int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw)
  2065. {
  2066. int i, rc = -EINVAL;
  2067. if (max_bw < 1 || max_bw > 100) {
  2068. DP_NOTICE(cdev, "PF max bw valid range is [1-100]\n");
  2069. return rc;
  2070. }
  2071. for_each_hwfn(cdev, i) {
  2072. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  2073. struct qed_hwfn *p_lead = QED_LEADING_HWFN(cdev);
  2074. struct qed_mcp_link_state *p_link;
  2075. struct qed_ptt *p_ptt;
  2076. p_link = &p_lead->mcp_info->link_output;
  2077. p_ptt = qed_ptt_acquire(p_hwfn);
  2078. if (!p_ptt)
  2079. return -EBUSY;
  2080. rc = __qed_configure_pf_max_bandwidth(p_hwfn, p_ptt,
  2081. p_link, max_bw);
  2082. qed_ptt_release(p_hwfn, p_ptt);
  2083. if (rc)
  2084. break;
  2085. }
  2086. return rc;
  2087. }
  2088. int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn,
  2089. struct qed_ptt *p_ptt,
  2090. struct qed_mcp_link_state *p_link,
  2091. u8 min_bw)
  2092. {
  2093. int rc = 0;
  2094. p_hwfn->mcp_info->func_info.bandwidth_min = min_bw;
  2095. p_hwfn->qm_info.pf_wfq = min_bw;
  2096. if (!p_link->line_speed)
  2097. return rc;
  2098. p_link->min_pf_rate = (p_link->line_speed * min_bw) / 100;
  2099. rc = qed_init_pf_wfq(p_hwfn, p_ptt, p_hwfn->rel_pf_id, min_bw);
  2100. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  2101. "Configured MIN bandwidth to be %d Mb/sec\n",
  2102. p_link->min_pf_rate);
  2103. return rc;
  2104. }
  2105. /* Main API to configure PF min bandwidth where bw range is [1-100] */
  2106. int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw)
  2107. {
  2108. int i, rc = -EINVAL;
  2109. if (min_bw < 1 || min_bw > 100) {
  2110. DP_NOTICE(cdev, "PF min bw valid range is [1-100]\n");
  2111. return rc;
  2112. }
  2113. for_each_hwfn(cdev, i) {
  2114. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  2115. struct qed_hwfn *p_lead = QED_LEADING_HWFN(cdev);
  2116. struct qed_mcp_link_state *p_link;
  2117. struct qed_ptt *p_ptt;
  2118. p_link = &p_lead->mcp_info->link_output;
  2119. p_ptt = qed_ptt_acquire(p_hwfn);
  2120. if (!p_ptt)
  2121. return -EBUSY;
  2122. rc = __qed_configure_pf_min_bandwidth(p_hwfn, p_ptt,
  2123. p_link, min_bw);
  2124. if (rc) {
  2125. qed_ptt_release(p_hwfn, p_ptt);
  2126. return rc;
  2127. }
  2128. if (p_link->min_pf_rate) {
  2129. u32 min_rate = p_link->min_pf_rate;
  2130. rc = __qed_configure_vp_wfq_on_link_change(p_hwfn,
  2131. p_ptt,
  2132. min_rate);
  2133. }
  2134. qed_ptt_release(p_hwfn, p_ptt);
  2135. }
  2136. return rc;
  2137. }
  2138. void qed_clean_wfq_db(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  2139. {
  2140. struct qed_mcp_link_state *p_link;
  2141. p_link = &p_hwfn->mcp_info->link_output;
  2142. if (p_link->min_pf_rate)
  2143. qed_disable_wfq_for_all_vports(p_hwfn, p_ptt,
  2144. p_link->min_pf_rate);
  2145. memset(p_hwfn->qm_info.wfq_data, 0,
  2146. sizeof(*p_hwfn->qm_info.wfq_data) * p_hwfn->qm_info.num_vports);
  2147. }