qed_dev.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814
  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/etherdevice.h>
  20. #include <linux/qed/qed_chain.h>
  21. #include <linux/qed/qed_if.h>
  22. #include "qed.h"
  23. #include "qed_cxt.h"
  24. #include "qed_dev_api.h"
  25. #include "qed_hsi.h"
  26. #include "qed_hw.h"
  27. #include "qed_init_ops.h"
  28. #include "qed_int.h"
  29. #include "qed_mcp.h"
  30. #include "qed_reg_addr.h"
  31. #include "qed_sp.h"
  32. /* API common to all protocols */
  33. void qed_init_dp(struct qed_dev *cdev,
  34. u32 dp_module, u8 dp_level)
  35. {
  36. u32 i;
  37. cdev->dp_level = dp_level;
  38. cdev->dp_module = dp_module;
  39. for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
  40. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  41. p_hwfn->dp_level = dp_level;
  42. p_hwfn->dp_module = dp_module;
  43. }
  44. }
  45. void qed_init_struct(struct qed_dev *cdev)
  46. {
  47. u8 i;
  48. for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
  49. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  50. p_hwfn->cdev = cdev;
  51. p_hwfn->my_id = i;
  52. p_hwfn->b_active = false;
  53. mutex_init(&p_hwfn->dmae_info.mutex);
  54. }
  55. /* hwfn 0 is always active */
  56. cdev->hwfns[0].b_active = true;
  57. /* set the default cache alignment to 128 */
  58. cdev->cache_shift = 7;
  59. }
  60. static void qed_qm_info_free(struct qed_hwfn *p_hwfn)
  61. {
  62. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  63. kfree(qm_info->qm_pq_params);
  64. qm_info->qm_pq_params = NULL;
  65. kfree(qm_info->qm_vport_params);
  66. qm_info->qm_vport_params = NULL;
  67. kfree(qm_info->qm_port_params);
  68. qm_info->qm_port_params = NULL;
  69. }
  70. void qed_resc_free(struct qed_dev *cdev)
  71. {
  72. int i;
  73. kfree(cdev->fw_data);
  74. cdev->fw_data = NULL;
  75. kfree(cdev->reset_stats);
  76. for_each_hwfn(cdev, i) {
  77. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  78. kfree(p_hwfn->p_tx_cids);
  79. p_hwfn->p_tx_cids = NULL;
  80. kfree(p_hwfn->p_rx_cids);
  81. p_hwfn->p_rx_cids = NULL;
  82. }
  83. for_each_hwfn(cdev, i) {
  84. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  85. qed_cxt_mngr_free(p_hwfn);
  86. qed_qm_info_free(p_hwfn);
  87. qed_spq_free(p_hwfn);
  88. qed_eq_free(p_hwfn, p_hwfn->p_eq);
  89. qed_consq_free(p_hwfn, p_hwfn->p_consq);
  90. qed_int_free(p_hwfn);
  91. qed_dmae_info_free(p_hwfn);
  92. }
  93. }
  94. static int qed_init_qm_info(struct qed_hwfn *p_hwfn)
  95. {
  96. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  97. struct init_qm_port_params *p_qm_port;
  98. u8 num_vports, i, vport_id, num_ports;
  99. u16 num_pqs, multi_cos_tcs = 1;
  100. memset(qm_info, 0, sizeof(*qm_info));
  101. num_pqs = multi_cos_tcs + 1; /* The '1' is for pure-LB */
  102. num_vports = (u8)RESC_NUM(p_hwfn, QED_VPORT);
  103. /* Sanity checking that setup requires legal number of resources */
  104. if (num_pqs > RESC_NUM(p_hwfn, QED_PQ)) {
  105. DP_ERR(p_hwfn,
  106. "Need too many Physical queues - 0x%04x when only %04x are available\n",
  107. num_pqs, RESC_NUM(p_hwfn, QED_PQ));
  108. return -EINVAL;
  109. }
  110. /* PQs will be arranged as follows: First per-TC PQ then pure-LB quete.
  111. */
  112. qm_info->qm_pq_params = kzalloc(sizeof(*qm_info->qm_pq_params) *
  113. num_pqs, GFP_ATOMIC);
  114. if (!qm_info->qm_pq_params)
  115. goto alloc_err;
  116. qm_info->qm_vport_params = kzalloc(sizeof(*qm_info->qm_vport_params) *
  117. num_vports, GFP_ATOMIC);
  118. if (!qm_info->qm_vport_params)
  119. goto alloc_err;
  120. qm_info->qm_port_params = kzalloc(sizeof(*qm_info->qm_port_params) *
  121. MAX_NUM_PORTS, GFP_ATOMIC);
  122. if (!qm_info->qm_port_params)
  123. goto alloc_err;
  124. vport_id = (u8)RESC_START(p_hwfn, QED_VPORT);
  125. /* First init per-TC PQs */
  126. for (i = 0; i < multi_cos_tcs; i++) {
  127. struct init_qm_pq_params *params = &qm_info->qm_pq_params[i];
  128. params->vport_id = vport_id;
  129. params->tc_id = p_hwfn->hw_info.non_offload_tc;
  130. params->wrr_group = 1;
  131. }
  132. /* Then init pure-LB PQ */
  133. qm_info->pure_lb_pq = i;
  134. qm_info->qm_pq_params[i].vport_id = (u8)RESC_START(p_hwfn, QED_VPORT);
  135. qm_info->qm_pq_params[i].tc_id = PURE_LB_TC;
  136. qm_info->qm_pq_params[i].wrr_group = 1;
  137. i++;
  138. qm_info->offload_pq = 0;
  139. qm_info->num_pqs = num_pqs;
  140. qm_info->num_vports = num_vports;
  141. /* Initialize qm port parameters */
  142. num_ports = p_hwfn->cdev->num_ports_in_engines;
  143. for (i = 0; i < num_ports; i++) {
  144. p_qm_port = &qm_info->qm_port_params[i];
  145. p_qm_port->active = 1;
  146. p_qm_port->num_active_phys_tcs = 4;
  147. p_qm_port->num_pbf_cmd_lines = PBF_MAX_CMD_LINES / num_ports;
  148. p_qm_port->num_btb_blocks = BTB_MAX_BLOCKS / num_ports;
  149. }
  150. qm_info->max_phys_tcs_per_port = NUM_OF_PHYS_TCS;
  151. qm_info->start_pq = (u16)RESC_START(p_hwfn, QED_PQ);
  152. qm_info->start_vport = (u8)RESC_START(p_hwfn, QED_VPORT);
  153. qm_info->pf_wfq = 0;
  154. qm_info->pf_rl = 0;
  155. qm_info->vport_rl_en = 1;
  156. return 0;
  157. alloc_err:
  158. DP_NOTICE(p_hwfn, "Failed to allocate memory for QM params\n");
  159. kfree(qm_info->qm_pq_params);
  160. kfree(qm_info->qm_vport_params);
  161. kfree(qm_info->qm_port_params);
  162. return -ENOMEM;
  163. }
  164. int qed_resc_alloc(struct qed_dev *cdev)
  165. {
  166. struct qed_consq *p_consq;
  167. struct qed_eq *p_eq;
  168. int i, rc = 0;
  169. cdev->fw_data = kzalloc(sizeof(*cdev->fw_data), GFP_KERNEL);
  170. if (!cdev->fw_data)
  171. return -ENOMEM;
  172. /* Allocate Memory for the Queue->CID mapping */
  173. for_each_hwfn(cdev, i) {
  174. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  175. int tx_size = sizeof(struct qed_hw_cid_data) *
  176. RESC_NUM(p_hwfn, QED_L2_QUEUE);
  177. int rx_size = sizeof(struct qed_hw_cid_data) *
  178. RESC_NUM(p_hwfn, QED_L2_QUEUE);
  179. p_hwfn->p_tx_cids = kzalloc(tx_size, GFP_KERNEL);
  180. if (!p_hwfn->p_tx_cids) {
  181. DP_NOTICE(p_hwfn,
  182. "Failed to allocate memory for Tx Cids\n");
  183. rc = -ENOMEM;
  184. goto alloc_err;
  185. }
  186. p_hwfn->p_rx_cids = kzalloc(rx_size, GFP_KERNEL);
  187. if (!p_hwfn->p_rx_cids) {
  188. DP_NOTICE(p_hwfn,
  189. "Failed to allocate memory for Rx Cids\n");
  190. rc = -ENOMEM;
  191. goto alloc_err;
  192. }
  193. }
  194. for_each_hwfn(cdev, i) {
  195. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  196. /* First allocate the context manager structure */
  197. rc = qed_cxt_mngr_alloc(p_hwfn);
  198. if (rc)
  199. goto alloc_err;
  200. /* Set the HW cid/tid numbers (in the contest manager)
  201. * Must be done prior to any further computations.
  202. */
  203. rc = qed_cxt_set_pf_params(p_hwfn);
  204. if (rc)
  205. goto alloc_err;
  206. /* Prepare and process QM requirements */
  207. rc = qed_init_qm_info(p_hwfn);
  208. if (rc)
  209. goto alloc_err;
  210. /* Compute the ILT client partition */
  211. rc = qed_cxt_cfg_ilt_compute(p_hwfn);
  212. if (rc)
  213. goto alloc_err;
  214. /* CID map / ILT shadow table / T2
  215. * The talbes sizes are determined by the computations above
  216. */
  217. rc = qed_cxt_tables_alloc(p_hwfn);
  218. if (rc)
  219. goto alloc_err;
  220. /* SPQ, must follow ILT because initializes SPQ context */
  221. rc = qed_spq_alloc(p_hwfn);
  222. if (rc)
  223. goto alloc_err;
  224. /* SP status block allocation */
  225. p_hwfn->p_dpc_ptt = qed_get_reserved_ptt(p_hwfn,
  226. RESERVED_PTT_DPC);
  227. rc = qed_int_alloc(p_hwfn, p_hwfn->p_main_ptt);
  228. if (rc)
  229. goto alloc_err;
  230. /* EQ */
  231. p_eq = qed_eq_alloc(p_hwfn, 256);
  232. if (!p_eq) {
  233. rc = -ENOMEM;
  234. goto alloc_err;
  235. }
  236. p_hwfn->p_eq = p_eq;
  237. p_consq = qed_consq_alloc(p_hwfn);
  238. if (!p_consq) {
  239. rc = -ENOMEM;
  240. goto alloc_err;
  241. }
  242. p_hwfn->p_consq = p_consq;
  243. /* DMA info initialization */
  244. rc = qed_dmae_info_alloc(p_hwfn);
  245. if (rc) {
  246. DP_NOTICE(p_hwfn,
  247. "Failed to allocate memory for dmae_info structure\n");
  248. goto alloc_err;
  249. }
  250. }
  251. cdev->reset_stats = kzalloc(sizeof(*cdev->reset_stats), GFP_KERNEL);
  252. if (!cdev->reset_stats) {
  253. DP_NOTICE(cdev, "Failed to allocate reset statistics\n");
  254. rc = -ENOMEM;
  255. goto alloc_err;
  256. }
  257. return 0;
  258. alloc_err:
  259. qed_resc_free(cdev);
  260. return rc;
  261. }
  262. void qed_resc_setup(struct qed_dev *cdev)
  263. {
  264. int i;
  265. for_each_hwfn(cdev, i) {
  266. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  267. qed_cxt_mngr_setup(p_hwfn);
  268. qed_spq_setup(p_hwfn);
  269. qed_eq_setup(p_hwfn, p_hwfn->p_eq);
  270. qed_consq_setup(p_hwfn, p_hwfn->p_consq);
  271. /* Read shadow of current MFW mailbox */
  272. qed_mcp_read_mb(p_hwfn, p_hwfn->p_main_ptt);
  273. memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
  274. p_hwfn->mcp_info->mfw_mb_cur,
  275. p_hwfn->mcp_info->mfw_mb_length);
  276. qed_int_setup(p_hwfn, p_hwfn->p_main_ptt);
  277. }
  278. }
  279. #define FINAL_CLEANUP_CMD_OFFSET (0)
  280. #define FINAL_CLEANUP_CMD (0x1)
  281. #define FINAL_CLEANUP_VALID_OFFSET (6)
  282. #define FINAL_CLEANUP_VFPF_ID_SHIFT (7)
  283. #define FINAL_CLEANUP_COMP (0x2)
  284. #define FINAL_CLEANUP_POLL_CNT (100)
  285. #define FINAL_CLEANUP_POLL_TIME (10)
  286. int qed_final_cleanup(struct qed_hwfn *p_hwfn,
  287. struct qed_ptt *p_ptt,
  288. u16 id)
  289. {
  290. u32 command = 0, addr, count = FINAL_CLEANUP_POLL_CNT;
  291. int rc = -EBUSY;
  292. addr = GTT_BAR0_MAP_REG_USDM_RAM + USTORM_FLR_FINAL_ACK_OFFSET;
  293. command |= FINAL_CLEANUP_CMD << FINAL_CLEANUP_CMD_OFFSET;
  294. command |= 1 << FINAL_CLEANUP_VALID_OFFSET;
  295. command |= id << FINAL_CLEANUP_VFPF_ID_SHIFT;
  296. command |= FINAL_CLEANUP_COMP << SDM_OP_GEN_COMP_TYPE_SHIFT;
  297. /* Make sure notification is not set before initiating final cleanup */
  298. if (REG_RD(p_hwfn, addr)) {
  299. DP_NOTICE(
  300. p_hwfn,
  301. "Unexpected; Found final cleanup notification before initiating final cleanup\n");
  302. REG_WR(p_hwfn, addr, 0);
  303. }
  304. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  305. "Sending final cleanup for PFVF[%d] [Command %08x\n]",
  306. id, command);
  307. qed_wr(p_hwfn, p_ptt, XSDM_REG_OPERATION_GEN, command);
  308. /* Poll until completion */
  309. while (!REG_RD(p_hwfn, addr) && count--)
  310. msleep(FINAL_CLEANUP_POLL_TIME);
  311. if (REG_RD(p_hwfn, addr))
  312. rc = 0;
  313. else
  314. DP_NOTICE(p_hwfn,
  315. "Failed to receive FW final cleanup notification\n");
  316. /* Cleanup afterwards */
  317. REG_WR(p_hwfn, addr, 0);
  318. return rc;
  319. }
  320. static void qed_calc_hw_mode(struct qed_hwfn *p_hwfn)
  321. {
  322. int hw_mode = 0;
  323. hw_mode = (1 << MODE_BB_A0);
  324. switch (p_hwfn->cdev->num_ports_in_engines) {
  325. case 1:
  326. hw_mode |= 1 << MODE_PORTS_PER_ENG_1;
  327. break;
  328. case 2:
  329. hw_mode |= 1 << MODE_PORTS_PER_ENG_2;
  330. break;
  331. case 4:
  332. hw_mode |= 1 << MODE_PORTS_PER_ENG_4;
  333. break;
  334. default:
  335. DP_NOTICE(p_hwfn, "num_ports_in_engine = %d not supported\n",
  336. p_hwfn->cdev->num_ports_in_engines);
  337. return;
  338. }
  339. switch (p_hwfn->cdev->mf_mode) {
  340. case SF:
  341. hw_mode |= 1 << MODE_SF;
  342. break;
  343. case MF_OVLAN:
  344. hw_mode |= 1 << MODE_MF_SD;
  345. break;
  346. case MF_NPAR:
  347. hw_mode |= 1 << MODE_MF_SI;
  348. break;
  349. default:
  350. DP_NOTICE(p_hwfn, "Unsupported MF mode, init as SF\n");
  351. hw_mode |= 1 << MODE_SF;
  352. }
  353. hw_mode |= 1 << MODE_ASIC;
  354. p_hwfn->hw_info.hw_mode = hw_mode;
  355. }
  356. /* Init run time data for all PFs on an engine. */
  357. static void qed_init_cau_rt_data(struct qed_dev *cdev)
  358. {
  359. u32 offset = CAU_REG_SB_VAR_MEMORY_RT_OFFSET;
  360. int i, sb_id;
  361. for_each_hwfn(cdev, i) {
  362. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  363. struct qed_igu_info *p_igu_info;
  364. struct qed_igu_block *p_block;
  365. struct cau_sb_entry sb_entry;
  366. p_igu_info = p_hwfn->hw_info.p_igu_info;
  367. for (sb_id = 0; sb_id < QED_MAPPING_MEMORY_SIZE(cdev);
  368. sb_id++) {
  369. p_block = &p_igu_info->igu_map.igu_blocks[sb_id];
  370. if (!p_block->is_pf)
  371. continue;
  372. qed_init_cau_sb_entry(p_hwfn, &sb_entry,
  373. p_block->function_id,
  374. 0, 0);
  375. STORE_RT_REG_AGG(p_hwfn, offset + sb_id * 2,
  376. sb_entry);
  377. }
  378. }
  379. }
  380. static int qed_hw_init_common(struct qed_hwfn *p_hwfn,
  381. struct qed_ptt *p_ptt,
  382. int hw_mode)
  383. {
  384. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  385. struct qed_qm_common_rt_init_params params;
  386. struct qed_dev *cdev = p_hwfn->cdev;
  387. int rc = 0;
  388. qed_init_cau_rt_data(cdev);
  389. /* Program GTT windows */
  390. qed_gtt_init(p_hwfn);
  391. if (p_hwfn->mcp_info) {
  392. if (p_hwfn->mcp_info->func_info.bandwidth_max)
  393. qm_info->pf_rl_en = 1;
  394. if (p_hwfn->mcp_info->func_info.bandwidth_min)
  395. qm_info->pf_wfq_en = 1;
  396. }
  397. memset(&params, 0, sizeof(params));
  398. params.max_ports_per_engine = p_hwfn->cdev->num_ports_in_engines;
  399. params.max_phys_tcs_per_port = qm_info->max_phys_tcs_per_port;
  400. params.pf_rl_en = qm_info->pf_rl_en;
  401. params.pf_wfq_en = qm_info->pf_wfq_en;
  402. params.vport_rl_en = qm_info->vport_rl_en;
  403. params.vport_wfq_en = qm_info->vport_wfq_en;
  404. params.port_params = qm_info->qm_port_params;
  405. qed_qm_common_rt_init(p_hwfn, &params);
  406. qed_cxt_hw_init_common(p_hwfn);
  407. /* Close gate from NIG to BRB/Storm; By default they are open, but
  408. * we close them to prevent NIG from passing data to reset blocks.
  409. * Should have been done in the ENGINE phase, but init-tool lacks
  410. * proper port-pretend capabilities.
  411. */
  412. qed_wr(p_hwfn, p_ptt, NIG_REG_RX_BRB_OUT_EN, 0);
  413. qed_wr(p_hwfn, p_ptt, NIG_REG_STORM_OUT_EN, 0);
  414. qed_port_pretend(p_hwfn, p_ptt, p_hwfn->port_id ^ 1);
  415. qed_wr(p_hwfn, p_ptt, NIG_REG_RX_BRB_OUT_EN, 0);
  416. qed_wr(p_hwfn, p_ptt, NIG_REG_STORM_OUT_EN, 0);
  417. qed_port_unpretend(p_hwfn, p_ptt);
  418. rc = qed_init_run(p_hwfn, p_ptt, PHASE_ENGINE, ANY_PHASE_ID, hw_mode);
  419. if (rc != 0)
  420. return rc;
  421. qed_wr(p_hwfn, p_ptt, PSWRQ2_REG_L2P_VALIDATE_VFID, 0);
  422. qed_wr(p_hwfn, p_ptt, PGLUE_B_REG_USE_CLIENTID_IN_TAG, 1);
  423. /* Disable relaxed ordering in the PCI config space */
  424. qed_wr(p_hwfn, p_ptt, 0x20b4,
  425. qed_rd(p_hwfn, p_ptt, 0x20b4) & ~0x10);
  426. return rc;
  427. }
  428. static int qed_hw_init_port(struct qed_hwfn *p_hwfn,
  429. struct qed_ptt *p_ptt,
  430. int hw_mode)
  431. {
  432. int rc = 0;
  433. rc = qed_init_run(p_hwfn, p_ptt, PHASE_PORT, p_hwfn->port_id,
  434. hw_mode);
  435. return rc;
  436. }
  437. static int qed_hw_init_pf(struct qed_hwfn *p_hwfn,
  438. struct qed_ptt *p_ptt,
  439. int hw_mode,
  440. bool b_hw_start,
  441. enum qed_int_mode int_mode,
  442. bool allow_npar_tx_switch)
  443. {
  444. u8 rel_pf_id = p_hwfn->rel_pf_id;
  445. int rc = 0;
  446. if (p_hwfn->mcp_info) {
  447. struct qed_mcp_function_info *p_info;
  448. p_info = &p_hwfn->mcp_info->func_info;
  449. if (p_info->bandwidth_min)
  450. p_hwfn->qm_info.pf_wfq = p_info->bandwidth_min;
  451. /* Update rate limit once we'll actually have a link */
  452. p_hwfn->qm_info.pf_rl = 100;
  453. }
  454. qed_cxt_hw_init_pf(p_hwfn);
  455. qed_int_igu_init_rt(p_hwfn);
  456. /* Set VLAN in NIG if needed */
  457. if (hw_mode & (1 << MODE_MF_SD)) {
  458. DP_VERBOSE(p_hwfn, NETIF_MSG_HW, "Configuring LLH_FUNC_TAG\n");
  459. STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_EN_RT_OFFSET, 1);
  460. STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_VALUE_RT_OFFSET,
  461. p_hwfn->hw_info.ovlan);
  462. }
  463. /* Enable classification by MAC if needed */
  464. if (hw_mode & (1 << MODE_MF_SI)) {
  465. DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
  466. "Configuring TAGMAC_CLS_TYPE\n");
  467. STORE_RT_REG(p_hwfn,
  468. NIG_REG_LLH_FUNC_TAGMAC_CLS_TYPE_RT_OFFSET, 1);
  469. }
  470. /* Protocl Configuration */
  471. STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_TCP_RT_OFFSET, 0);
  472. STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_FCOE_RT_OFFSET, 0);
  473. STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_ROCE_RT_OFFSET, 0);
  474. /* Cleanup chip from previous driver if such remains exist */
  475. rc = qed_final_cleanup(p_hwfn, p_ptt, rel_pf_id);
  476. if (rc != 0)
  477. return rc;
  478. /* PF Init sequence */
  479. rc = qed_init_run(p_hwfn, p_ptt, PHASE_PF, rel_pf_id, hw_mode);
  480. if (rc)
  481. return rc;
  482. /* QM_PF Init sequence (may be invoked separately e.g. for DCB) */
  483. rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, rel_pf_id, hw_mode);
  484. if (rc)
  485. return rc;
  486. /* Pure runtime initializations - directly to the HW */
  487. qed_int_igu_init_pure_rt(p_hwfn, p_ptt, true, true);
  488. if (b_hw_start) {
  489. /* enable interrupts */
  490. qed_int_igu_enable(p_hwfn, p_ptt, int_mode);
  491. /* send function start command */
  492. rc = qed_sp_pf_start(p_hwfn, p_hwfn->cdev->mf_mode);
  493. if (rc)
  494. DP_NOTICE(p_hwfn, "Function start ramrod failed\n");
  495. }
  496. return rc;
  497. }
  498. static int qed_change_pci_hwfn(struct qed_hwfn *p_hwfn,
  499. struct qed_ptt *p_ptt,
  500. u8 enable)
  501. {
  502. u32 delay_idx = 0, val, set_val = enable ? 1 : 0;
  503. /* Change PF in PXP */
  504. qed_wr(p_hwfn, p_ptt,
  505. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, set_val);
  506. /* wait until value is set - try for 1 second every 50us */
  507. for (delay_idx = 0; delay_idx < 20000; delay_idx++) {
  508. val = qed_rd(p_hwfn, p_ptt,
  509. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  510. if (val == set_val)
  511. break;
  512. usleep_range(50, 60);
  513. }
  514. if (val != set_val) {
  515. DP_NOTICE(p_hwfn,
  516. "PFID_ENABLE_MASTER wasn't changed after a second\n");
  517. return -EAGAIN;
  518. }
  519. return 0;
  520. }
  521. static void qed_reset_mb_shadow(struct qed_hwfn *p_hwfn,
  522. struct qed_ptt *p_main_ptt)
  523. {
  524. /* Read shadow of current MFW mailbox */
  525. qed_mcp_read_mb(p_hwfn, p_main_ptt);
  526. memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
  527. p_hwfn->mcp_info->mfw_mb_cur,
  528. p_hwfn->mcp_info->mfw_mb_length);
  529. }
  530. int qed_hw_init(struct qed_dev *cdev,
  531. bool b_hw_start,
  532. enum qed_int_mode int_mode,
  533. bool allow_npar_tx_switch,
  534. const u8 *bin_fw_data)
  535. {
  536. struct qed_storm_stats *p_stat;
  537. u32 load_code, param, *p_address;
  538. int rc, mfw_rc, i;
  539. u8 fw_vport = 0;
  540. rc = qed_init_fw_data(cdev, bin_fw_data);
  541. if (rc != 0)
  542. return rc;
  543. for_each_hwfn(cdev, i) {
  544. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  545. rc = qed_fw_vport(p_hwfn, 0, &fw_vport);
  546. if (rc != 0)
  547. return rc;
  548. /* Enable DMAE in PXP */
  549. rc = qed_change_pci_hwfn(p_hwfn, p_hwfn->p_main_ptt, true);
  550. qed_calc_hw_mode(p_hwfn);
  551. rc = qed_mcp_load_req(p_hwfn, p_hwfn->p_main_ptt,
  552. &load_code);
  553. if (rc) {
  554. DP_NOTICE(p_hwfn, "Failed sending LOAD_REQ command\n");
  555. return rc;
  556. }
  557. qed_reset_mb_shadow(p_hwfn, p_hwfn->p_main_ptt);
  558. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  559. "Load request was sent. Resp:0x%x, Load code: 0x%x\n",
  560. rc, load_code);
  561. p_hwfn->first_on_engine = (load_code ==
  562. FW_MSG_CODE_DRV_LOAD_ENGINE);
  563. switch (load_code) {
  564. case FW_MSG_CODE_DRV_LOAD_ENGINE:
  565. rc = qed_hw_init_common(p_hwfn, p_hwfn->p_main_ptt,
  566. p_hwfn->hw_info.hw_mode);
  567. if (rc)
  568. break;
  569. /* Fall into */
  570. case FW_MSG_CODE_DRV_LOAD_PORT:
  571. rc = qed_hw_init_port(p_hwfn, p_hwfn->p_main_ptt,
  572. p_hwfn->hw_info.hw_mode);
  573. if (rc)
  574. break;
  575. /* Fall into */
  576. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  577. rc = qed_hw_init_pf(p_hwfn, p_hwfn->p_main_ptt,
  578. p_hwfn->hw_info.hw_mode,
  579. b_hw_start, int_mode,
  580. allow_npar_tx_switch);
  581. break;
  582. default:
  583. rc = -EINVAL;
  584. break;
  585. }
  586. if (rc)
  587. DP_NOTICE(p_hwfn,
  588. "init phase failed for loadcode 0x%x (rc %d)\n",
  589. load_code, rc);
  590. /* ACK mfw regardless of success or failure of initialization */
  591. mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
  592. DRV_MSG_CODE_LOAD_DONE,
  593. 0, &load_code, &param);
  594. if (rc)
  595. return rc;
  596. if (mfw_rc) {
  597. DP_NOTICE(p_hwfn, "Failed sending LOAD_DONE command\n");
  598. return mfw_rc;
  599. }
  600. p_hwfn->hw_init_done = true;
  601. /* init PF stats */
  602. p_stat = &p_hwfn->storm_stats;
  603. p_stat->mstats.address = BAR0_MAP_REG_MSDM_RAM +
  604. MSTORM_QUEUE_STAT_OFFSET(fw_vport);
  605. p_stat->mstats.len = sizeof(struct eth_mstorm_per_queue_stat);
  606. p_stat->ustats.address = BAR0_MAP_REG_USDM_RAM +
  607. USTORM_QUEUE_STAT_OFFSET(fw_vport);
  608. p_stat->ustats.len = sizeof(struct eth_ustorm_per_queue_stat);
  609. p_stat->pstats.address = BAR0_MAP_REG_PSDM_RAM +
  610. PSTORM_QUEUE_STAT_OFFSET(fw_vport);
  611. p_stat->pstats.len = sizeof(struct eth_pstorm_per_queue_stat);
  612. p_address = &p_stat->tstats.address;
  613. *p_address = BAR0_MAP_REG_TSDM_RAM +
  614. TSTORM_PORT_STAT_OFFSET(MFW_PORT(p_hwfn));
  615. p_stat->tstats.len = sizeof(struct tstorm_per_port_stat);
  616. }
  617. return 0;
  618. }
  619. #define QED_HW_STOP_RETRY_LIMIT (10)
  620. int qed_hw_stop(struct qed_dev *cdev)
  621. {
  622. int rc = 0, t_rc;
  623. int i, j;
  624. for_each_hwfn(cdev, j) {
  625. struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
  626. struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
  627. DP_VERBOSE(p_hwfn, NETIF_MSG_IFDOWN, "Stopping hw/fw\n");
  628. /* mark the hw as uninitialized... */
  629. p_hwfn->hw_init_done = false;
  630. rc = qed_sp_pf_stop(p_hwfn);
  631. if (rc)
  632. return rc;
  633. qed_wr(p_hwfn, p_ptt,
  634. NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
  635. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
  636. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
  637. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
  638. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
  639. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
  640. qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x0);
  641. qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_TASK, 0x0);
  642. for (i = 0; i < QED_HW_STOP_RETRY_LIMIT; i++) {
  643. if ((!qed_rd(p_hwfn, p_ptt,
  644. TM_REG_PF_SCAN_ACTIVE_CONN)) &&
  645. (!qed_rd(p_hwfn, p_ptt,
  646. TM_REG_PF_SCAN_ACTIVE_TASK)))
  647. break;
  648. usleep_range(1000, 2000);
  649. }
  650. if (i == QED_HW_STOP_RETRY_LIMIT)
  651. DP_NOTICE(p_hwfn,
  652. "Timers linear scans are not over [Connection %02x Tasks %02x]\n",
  653. (u8)qed_rd(p_hwfn, p_ptt,
  654. TM_REG_PF_SCAN_ACTIVE_CONN),
  655. (u8)qed_rd(p_hwfn, p_ptt,
  656. TM_REG_PF_SCAN_ACTIVE_TASK));
  657. /* Disable Attention Generation */
  658. qed_int_igu_disable_int(p_hwfn, p_ptt);
  659. qed_wr(p_hwfn, p_ptt, IGU_REG_LEADING_EDGE_LATCH, 0);
  660. qed_wr(p_hwfn, p_ptt, IGU_REG_TRAILING_EDGE_LATCH, 0);
  661. qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, true);
  662. /* Need to wait 1ms to guarantee SBs are cleared */
  663. usleep_range(1000, 2000);
  664. }
  665. /* Disable DMAE in PXP - in CMT, this should only be done for
  666. * first hw-function, and only after all transactions have
  667. * stopped for all active hw-functions.
  668. */
  669. t_rc = qed_change_pci_hwfn(&cdev->hwfns[0],
  670. cdev->hwfns[0].p_main_ptt,
  671. false);
  672. if (t_rc != 0)
  673. rc = t_rc;
  674. return rc;
  675. }
  676. void qed_hw_stop_fastpath(struct qed_dev *cdev)
  677. {
  678. int i, j;
  679. for_each_hwfn(cdev, j) {
  680. struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
  681. struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
  682. DP_VERBOSE(p_hwfn,
  683. NETIF_MSG_IFDOWN,
  684. "Shutting down the fastpath\n");
  685. qed_wr(p_hwfn, p_ptt,
  686. NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
  687. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
  688. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
  689. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
  690. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
  691. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
  692. qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x0);
  693. qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_TASK, 0x0);
  694. for (i = 0; i < QED_HW_STOP_RETRY_LIMIT; i++) {
  695. if ((!qed_rd(p_hwfn, p_ptt,
  696. TM_REG_PF_SCAN_ACTIVE_CONN)) &&
  697. (!qed_rd(p_hwfn, p_ptt,
  698. TM_REG_PF_SCAN_ACTIVE_TASK)))
  699. break;
  700. usleep_range(1000, 2000);
  701. }
  702. if (i == QED_HW_STOP_RETRY_LIMIT)
  703. DP_NOTICE(p_hwfn,
  704. "Timers linear scans are not over [Connection %02x Tasks %02x]\n",
  705. (u8)qed_rd(p_hwfn, p_ptt,
  706. TM_REG_PF_SCAN_ACTIVE_CONN),
  707. (u8)qed_rd(p_hwfn, p_ptt,
  708. TM_REG_PF_SCAN_ACTIVE_TASK));
  709. qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, false);
  710. /* Need to wait 1ms to guarantee SBs are cleared */
  711. usleep_range(1000, 2000);
  712. }
  713. }
  714. void qed_hw_start_fastpath(struct qed_hwfn *p_hwfn)
  715. {
  716. /* Re-open incoming traffic */
  717. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  718. NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x0);
  719. }
  720. static int qed_reg_assert(struct qed_hwfn *hwfn,
  721. struct qed_ptt *ptt, u32 reg,
  722. bool expected)
  723. {
  724. u32 assert_val = qed_rd(hwfn, ptt, reg);
  725. if (assert_val != expected) {
  726. DP_NOTICE(hwfn, "Value at address 0x%x != 0x%08x\n",
  727. reg, expected);
  728. return -EINVAL;
  729. }
  730. return 0;
  731. }
  732. int qed_hw_reset(struct qed_dev *cdev)
  733. {
  734. int rc = 0;
  735. u32 unload_resp, unload_param;
  736. int i;
  737. for_each_hwfn(cdev, i) {
  738. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  739. DP_VERBOSE(p_hwfn, NETIF_MSG_IFDOWN, "Resetting hw/fw\n");
  740. /* Check for incorrect states */
  741. qed_reg_assert(p_hwfn, p_hwfn->p_main_ptt,
  742. QM_REG_USG_CNT_PF_TX, 0);
  743. qed_reg_assert(p_hwfn, p_hwfn->p_main_ptt,
  744. QM_REG_USG_CNT_PF_OTHER, 0);
  745. /* Disable PF in HW blocks */
  746. qed_wr(p_hwfn, p_hwfn->p_main_ptt, DORQ_REG_PF_DB_ENABLE, 0);
  747. qed_wr(p_hwfn, p_hwfn->p_main_ptt, QM_REG_PF_EN, 0);
  748. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  749. TCFC_REG_STRONG_ENABLE_PF, 0);
  750. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  751. CCFC_REG_STRONG_ENABLE_PF, 0);
  752. /* Send unload command to MCP */
  753. rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
  754. DRV_MSG_CODE_UNLOAD_REQ,
  755. DRV_MB_PARAM_UNLOAD_WOL_MCP,
  756. &unload_resp, &unload_param);
  757. if (rc) {
  758. DP_NOTICE(p_hwfn, "qed_hw_reset: UNLOAD_REQ failed\n");
  759. unload_resp = FW_MSG_CODE_DRV_UNLOAD_ENGINE;
  760. }
  761. rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
  762. DRV_MSG_CODE_UNLOAD_DONE,
  763. 0, &unload_resp, &unload_param);
  764. if (rc) {
  765. DP_NOTICE(p_hwfn, "qed_hw_reset: UNLOAD_DONE failed\n");
  766. return rc;
  767. }
  768. }
  769. return rc;
  770. }
  771. /* Free hwfn memory and resources acquired in hw_hwfn_prepare */
  772. static void qed_hw_hwfn_free(struct qed_hwfn *p_hwfn)
  773. {
  774. qed_ptt_pool_free(p_hwfn);
  775. kfree(p_hwfn->hw_info.p_igu_info);
  776. }
  777. /* Setup bar access */
  778. static int qed_hw_hwfn_prepare(struct qed_hwfn *p_hwfn)
  779. {
  780. int rc;
  781. /* Allocate PTT pool */
  782. rc = qed_ptt_pool_alloc(p_hwfn);
  783. if (rc)
  784. return rc;
  785. /* Allocate the main PTT */
  786. p_hwfn->p_main_ptt = qed_get_reserved_ptt(p_hwfn, RESERVED_PTT_MAIN);
  787. /* clear indirect access */
  788. qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_88_F0, 0);
  789. qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_8C_F0, 0);
  790. qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_90_F0, 0);
  791. qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_94_F0, 0);
  792. /* Clean Previous errors if such exist */
  793. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  794. PGLUE_B_REG_WAS_ERROR_PF_31_0_CLR,
  795. 1 << p_hwfn->abs_pf_id);
  796. /* enable internal target-read */
  797. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  798. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  799. return 0;
  800. }
  801. static void get_function_id(struct qed_hwfn *p_hwfn)
  802. {
  803. /* ME Register */
  804. p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR);
  805. p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, PXP_PF_ME_CONCRETE_ADDR);
  806. p_hwfn->abs_pf_id = (p_hwfn->hw_info.concrete_fid >> 16) & 0xf;
  807. p_hwfn->rel_pf_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
  808. PXP_CONCRETE_FID_PFID);
  809. p_hwfn->port_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
  810. PXP_CONCRETE_FID_PORT);
  811. }
  812. static void qed_hw_set_feat(struct qed_hwfn *p_hwfn)
  813. {
  814. u32 *feat_num = p_hwfn->hw_info.feat_num;
  815. int num_features = 1;
  816. feat_num[QED_PF_L2_QUE] = min_t(u32, RESC_NUM(p_hwfn, QED_SB) /
  817. num_features,
  818. RESC_NUM(p_hwfn, QED_L2_QUEUE));
  819. DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE,
  820. "#PF_L2_QUEUES=%d #SBS=%d num_features=%d\n",
  821. feat_num[QED_PF_L2_QUE], RESC_NUM(p_hwfn, QED_SB),
  822. num_features);
  823. }
  824. static void qed_hw_get_resc(struct qed_hwfn *p_hwfn)
  825. {
  826. u32 *resc_start = p_hwfn->hw_info.resc_start;
  827. u32 *resc_num = p_hwfn->hw_info.resc_num;
  828. int num_funcs, i;
  829. num_funcs = IS_MF(p_hwfn) ? MAX_NUM_PFS_BB
  830. : p_hwfn->cdev->num_ports_in_engines;
  831. resc_num[QED_SB] = min_t(u32,
  832. (MAX_SB_PER_PATH_BB / num_funcs),
  833. qed_int_get_num_sbs(p_hwfn, NULL));
  834. resc_num[QED_L2_QUEUE] = MAX_NUM_L2_QUEUES_BB / num_funcs;
  835. resc_num[QED_VPORT] = MAX_NUM_VPORTS_BB / num_funcs;
  836. resc_num[QED_RSS_ENG] = ETH_RSS_ENGINE_NUM_BB / num_funcs;
  837. resc_num[QED_PQ] = MAX_QM_TX_QUEUES_BB / num_funcs;
  838. resc_num[QED_RL] = 8;
  839. resc_num[QED_MAC] = ETH_NUM_MAC_FILTERS / num_funcs;
  840. resc_num[QED_VLAN] = (ETH_NUM_VLAN_FILTERS - 1 /*For vlan0*/) /
  841. num_funcs;
  842. resc_num[QED_ILT] = 950;
  843. for (i = 0; i < QED_MAX_RESC; i++)
  844. resc_start[i] = resc_num[i] * p_hwfn->rel_pf_id;
  845. qed_hw_set_feat(p_hwfn);
  846. DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE,
  847. "The numbers for each resource are:\n"
  848. "SB = %d start = %d\n"
  849. "L2_QUEUE = %d start = %d\n"
  850. "VPORT = %d start = %d\n"
  851. "PQ = %d start = %d\n"
  852. "RL = %d start = %d\n"
  853. "MAC = %d start = %d\n"
  854. "VLAN = %d start = %d\n"
  855. "ILT = %d start = %d\n",
  856. p_hwfn->hw_info.resc_num[QED_SB],
  857. p_hwfn->hw_info.resc_start[QED_SB],
  858. p_hwfn->hw_info.resc_num[QED_L2_QUEUE],
  859. p_hwfn->hw_info.resc_start[QED_L2_QUEUE],
  860. p_hwfn->hw_info.resc_num[QED_VPORT],
  861. p_hwfn->hw_info.resc_start[QED_VPORT],
  862. p_hwfn->hw_info.resc_num[QED_PQ],
  863. p_hwfn->hw_info.resc_start[QED_PQ],
  864. p_hwfn->hw_info.resc_num[QED_RL],
  865. p_hwfn->hw_info.resc_start[QED_RL],
  866. p_hwfn->hw_info.resc_num[QED_MAC],
  867. p_hwfn->hw_info.resc_start[QED_MAC],
  868. p_hwfn->hw_info.resc_num[QED_VLAN],
  869. p_hwfn->hw_info.resc_start[QED_VLAN],
  870. p_hwfn->hw_info.resc_num[QED_ILT],
  871. p_hwfn->hw_info.resc_start[QED_ILT]);
  872. }
  873. static int qed_hw_get_nvm_info(struct qed_hwfn *p_hwfn,
  874. struct qed_ptt *p_ptt)
  875. {
  876. u32 nvm_cfg1_offset, mf_mode, addr, generic_cont0, core_cfg;
  877. u32 port_cfg_addr, link_temp, val, nvm_cfg_addr;
  878. struct qed_mcp_link_params *link;
  879. /* Read global nvm_cfg address */
  880. nvm_cfg_addr = qed_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0);
  881. /* Verify MCP has initialized it */
  882. if (!nvm_cfg_addr) {
  883. DP_NOTICE(p_hwfn, "Shared memory not initialized\n");
  884. return -EINVAL;
  885. }
  886. /* Read nvm_cfg1 (Notice this is just offset, and not offsize (TBD) */
  887. nvm_cfg1_offset = qed_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4);
  888. /* Read Vendor Id / Device Id */
  889. addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
  890. offsetof(struct nvm_cfg1, glob) +
  891. offsetof(struct nvm_cfg1_glob, pci_id);
  892. p_hwfn->hw_info.vendor_id = qed_rd(p_hwfn, p_ptt, addr) &
  893. NVM_CFG1_GLOB_VENDOR_ID_MASK;
  894. addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
  895. offsetof(struct nvm_cfg1, glob) +
  896. offsetof(struct nvm_cfg1_glob, core_cfg);
  897. core_cfg = qed_rd(p_hwfn, p_ptt, addr);
  898. switch ((core_cfg & NVM_CFG1_GLOB_NETWORK_PORT_MODE_MASK) >>
  899. NVM_CFG1_GLOB_NETWORK_PORT_MODE_OFFSET) {
  900. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_2X40G:
  901. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X40G;
  902. break;
  903. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_2X50G:
  904. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X50G;
  905. break;
  906. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_1X100G:
  907. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X100G;
  908. break;
  909. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_4X10G_F:
  910. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_F;
  911. break;
  912. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_4X10G_E:
  913. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_E;
  914. break;
  915. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_4X20G:
  916. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X20G;
  917. break;
  918. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_1X40G:
  919. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X40G;
  920. break;
  921. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_2X25G:
  922. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X25G;
  923. break;
  924. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_1X25G:
  925. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X25G;
  926. break;
  927. default:
  928. DP_NOTICE(p_hwfn, "Unknown port mode in 0x%08x\n",
  929. core_cfg);
  930. break;
  931. }
  932. addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
  933. offsetof(struct nvm_cfg1, func[MCP_PF_ID(p_hwfn)]) +
  934. offsetof(struct nvm_cfg1_func, device_id);
  935. val = qed_rd(p_hwfn, p_ptt, addr);
  936. if (IS_MF(p_hwfn)) {
  937. p_hwfn->hw_info.device_id =
  938. (val & NVM_CFG1_FUNC_MF_VENDOR_DEVICE_ID_MASK) >>
  939. NVM_CFG1_FUNC_MF_VENDOR_DEVICE_ID_OFFSET;
  940. } else {
  941. p_hwfn->hw_info.device_id =
  942. (val & NVM_CFG1_FUNC_VENDOR_DEVICE_ID_MASK) >>
  943. NVM_CFG1_FUNC_VENDOR_DEVICE_ID_OFFSET;
  944. }
  945. /* Read default link configuration */
  946. link = &p_hwfn->mcp_info->link_input;
  947. port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
  948. offsetof(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
  949. link_temp = qed_rd(p_hwfn, p_ptt,
  950. port_cfg_addr +
  951. offsetof(struct nvm_cfg1_port, speed_cap_mask));
  952. link->speed.advertised_speeds =
  953. link_temp & NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_MASK;
  954. p_hwfn->mcp_info->link_capabilities.speed_capabilities =
  955. link->speed.advertised_speeds;
  956. link_temp = qed_rd(p_hwfn, p_ptt,
  957. port_cfg_addr +
  958. offsetof(struct nvm_cfg1_port, link_settings));
  959. switch ((link_temp & NVM_CFG1_PORT_DRV_LINK_SPEED_MASK) >>
  960. NVM_CFG1_PORT_DRV_LINK_SPEED_OFFSET) {
  961. case NVM_CFG1_PORT_DRV_LINK_SPEED_AUTONEG:
  962. link->speed.autoneg = true;
  963. break;
  964. case NVM_CFG1_PORT_DRV_LINK_SPEED_1G:
  965. link->speed.forced_speed = 1000;
  966. break;
  967. case NVM_CFG1_PORT_DRV_LINK_SPEED_10G:
  968. link->speed.forced_speed = 10000;
  969. break;
  970. case NVM_CFG1_PORT_DRV_LINK_SPEED_25G:
  971. link->speed.forced_speed = 25000;
  972. break;
  973. case NVM_CFG1_PORT_DRV_LINK_SPEED_40G:
  974. link->speed.forced_speed = 40000;
  975. break;
  976. case NVM_CFG1_PORT_DRV_LINK_SPEED_50G:
  977. link->speed.forced_speed = 50000;
  978. break;
  979. case NVM_CFG1_PORT_DRV_LINK_SPEED_100G:
  980. link->speed.forced_speed = 100000;
  981. break;
  982. default:
  983. DP_NOTICE(p_hwfn, "Unknown Speed in 0x%08x\n",
  984. link_temp);
  985. }
  986. link_temp &= NVM_CFG1_PORT_DRV_FLOW_CONTROL_MASK;
  987. link_temp >>= NVM_CFG1_PORT_DRV_FLOW_CONTROL_OFFSET;
  988. link->pause.autoneg = !!(link_temp &
  989. NVM_CFG1_PORT_DRV_FLOW_CONTROL_AUTONEG);
  990. link->pause.forced_rx = !!(link_temp &
  991. NVM_CFG1_PORT_DRV_FLOW_CONTROL_RX);
  992. link->pause.forced_tx = !!(link_temp &
  993. NVM_CFG1_PORT_DRV_FLOW_CONTROL_TX);
  994. link->loopback_mode = 0;
  995. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  996. "Read default link: Speed 0x%08x, Adv. Speed 0x%08x, AN: 0x%02x, PAUSE AN: 0x%02x\n",
  997. link->speed.forced_speed, link->speed.advertised_speeds,
  998. link->speed.autoneg, link->pause.autoneg);
  999. /* Read Multi-function information from shmem */
  1000. addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
  1001. offsetof(struct nvm_cfg1, glob) +
  1002. offsetof(struct nvm_cfg1_glob, generic_cont0);
  1003. generic_cont0 = qed_rd(p_hwfn, p_ptt, addr);
  1004. mf_mode = (generic_cont0 & NVM_CFG1_GLOB_MF_MODE_MASK) >>
  1005. NVM_CFG1_GLOB_MF_MODE_OFFSET;
  1006. switch (mf_mode) {
  1007. case NVM_CFG1_GLOB_MF_MODE_MF_ALLOWED:
  1008. p_hwfn->cdev->mf_mode = MF_OVLAN;
  1009. break;
  1010. case NVM_CFG1_GLOB_MF_MODE_NPAR1_0:
  1011. p_hwfn->cdev->mf_mode = MF_NPAR;
  1012. break;
  1013. case NVM_CFG1_GLOB_MF_MODE_FORCED_SF:
  1014. p_hwfn->cdev->mf_mode = SF;
  1015. break;
  1016. }
  1017. DP_INFO(p_hwfn, "Multi function mode is %08x\n",
  1018. p_hwfn->cdev->mf_mode);
  1019. return qed_mcp_fill_shmem_func_info(p_hwfn, p_ptt);
  1020. }
  1021. static int
  1022. qed_get_hw_info(struct qed_hwfn *p_hwfn,
  1023. struct qed_ptt *p_ptt,
  1024. enum qed_pci_personality personality)
  1025. {
  1026. u32 port_mode;
  1027. int rc;
  1028. /* Read the port mode */
  1029. port_mode = qed_rd(p_hwfn, p_ptt,
  1030. CNIG_REG_NW_PORT_MODE_BB_B0);
  1031. if (port_mode < 3) {
  1032. p_hwfn->cdev->num_ports_in_engines = 1;
  1033. } else if (port_mode <= 5) {
  1034. p_hwfn->cdev->num_ports_in_engines = 2;
  1035. } else {
  1036. DP_NOTICE(p_hwfn, "PORT MODE: %d not supported\n",
  1037. p_hwfn->cdev->num_ports_in_engines);
  1038. /* Default num_ports_in_engines to something */
  1039. p_hwfn->cdev->num_ports_in_engines = 1;
  1040. }
  1041. qed_hw_get_nvm_info(p_hwfn, p_ptt);
  1042. rc = qed_int_igu_read_cam(p_hwfn, p_ptt);
  1043. if (rc)
  1044. return rc;
  1045. if (qed_mcp_is_init(p_hwfn))
  1046. ether_addr_copy(p_hwfn->hw_info.hw_mac_addr,
  1047. p_hwfn->mcp_info->func_info.mac);
  1048. else
  1049. eth_random_addr(p_hwfn->hw_info.hw_mac_addr);
  1050. if (qed_mcp_is_init(p_hwfn)) {
  1051. if (p_hwfn->mcp_info->func_info.ovlan != QED_MCP_VLAN_UNSET)
  1052. p_hwfn->hw_info.ovlan =
  1053. p_hwfn->mcp_info->func_info.ovlan;
  1054. qed_mcp_cmd_port_init(p_hwfn, p_ptt);
  1055. }
  1056. if (qed_mcp_is_init(p_hwfn)) {
  1057. enum qed_pci_personality protocol;
  1058. protocol = p_hwfn->mcp_info->func_info.protocol;
  1059. p_hwfn->hw_info.personality = protocol;
  1060. }
  1061. qed_hw_get_resc(p_hwfn);
  1062. return rc;
  1063. }
  1064. static void qed_get_dev_info(struct qed_dev *cdev)
  1065. {
  1066. u32 tmp;
  1067. cdev->chip_num = (u16)qed_rd(cdev->hwfns, cdev->hwfns[0].p_main_ptt,
  1068. MISCS_REG_CHIP_NUM);
  1069. cdev->chip_rev = (u16)qed_rd(cdev->hwfns, cdev->hwfns[0].p_main_ptt,
  1070. MISCS_REG_CHIP_REV);
  1071. MASK_FIELD(CHIP_REV, cdev->chip_rev);
  1072. /* Learn number of HW-functions */
  1073. tmp = qed_rd(cdev->hwfns, cdev->hwfns[0].p_main_ptt,
  1074. MISCS_REG_CMT_ENABLED_FOR_PAIR);
  1075. if (tmp & (1 << cdev->hwfns[0].rel_pf_id)) {
  1076. DP_NOTICE(cdev->hwfns, "device in CMT mode\n");
  1077. cdev->num_hwfns = 2;
  1078. } else {
  1079. cdev->num_hwfns = 1;
  1080. }
  1081. cdev->chip_bond_id = qed_rd(cdev->hwfns, cdev->hwfns[0].p_main_ptt,
  1082. MISCS_REG_CHIP_TEST_REG) >> 4;
  1083. MASK_FIELD(CHIP_BOND_ID, cdev->chip_bond_id);
  1084. cdev->chip_metal = (u16)qed_rd(cdev->hwfns, cdev->hwfns[0].p_main_ptt,
  1085. MISCS_REG_CHIP_METAL);
  1086. MASK_FIELD(CHIP_METAL, cdev->chip_metal);
  1087. DP_INFO(cdev->hwfns,
  1088. "Chip details - Num: %04x Rev: %04x Bond id: %04x Metal: %04x\n",
  1089. cdev->chip_num, cdev->chip_rev,
  1090. cdev->chip_bond_id, cdev->chip_metal);
  1091. }
  1092. static int qed_hw_prepare_single(struct qed_hwfn *p_hwfn,
  1093. void __iomem *p_regview,
  1094. void __iomem *p_doorbells,
  1095. enum qed_pci_personality personality)
  1096. {
  1097. int rc = 0;
  1098. /* Split PCI bars evenly between hwfns */
  1099. p_hwfn->regview = p_regview;
  1100. p_hwfn->doorbells = p_doorbells;
  1101. /* Validate that chip access is feasible */
  1102. if (REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR) == 0xffffffff) {
  1103. DP_ERR(p_hwfn,
  1104. "Reading the ME register returns all Fs; Preventing further chip access\n");
  1105. return -EINVAL;
  1106. }
  1107. get_function_id(p_hwfn);
  1108. rc = qed_hw_hwfn_prepare(p_hwfn);
  1109. if (rc) {
  1110. DP_NOTICE(p_hwfn, "Failed to prepare hwfn's hw\n");
  1111. goto err0;
  1112. }
  1113. /* First hwfn learns basic information, e.g., number of hwfns */
  1114. if (!p_hwfn->my_id)
  1115. qed_get_dev_info(p_hwfn->cdev);
  1116. /* Initialize MCP structure */
  1117. rc = qed_mcp_cmd_init(p_hwfn, p_hwfn->p_main_ptt);
  1118. if (rc) {
  1119. DP_NOTICE(p_hwfn, "Failed initializing mcp command\n");
  1120. goto err1;
  1121. }
  1122. /* Read the device configuration information from the HW and SHMEM */
  1123. rc = qed_get_hw_info(p_hwfn, p_hwfn->p_main_ptt, personality);
  1124. if (rc) {
  1125. DP_NOTICE(p_hwfn, "Failed to get HW information\n");
  1126. goto err2;
  1127. }
  1128. /* Allocate the init RT array and initialize the init-ops engine */
  1129. rc = qed_init_alloc(p_hwfn);
  1130. if (rc) {
  1131. DP_NOTICE(p_hwfn, "Failed to allocate the init array\n");
  1132. goto err2;
  1133. }
  1134. return rc;
  1135. err2:
  1136. qed_mcp_free(p_hwfn);
  1137. err1:
  1138. qed_hw_hwfn_free(p_hwfn);
  1139. err0:
  1140. return rc;
  1141. }
  1142. static u32 qed_hw_bar_size(struct qed_hwfn *p_hwfn,
  1143. u8 bar_id)
  1144. {
  1145. u32 bar_reg = (bar_id == 0 ? PGLUE_B_REG_PF_BAR0_SIZE
  1146. : PGLUE_B_REG_PF_BAR1_SIZE);
  1147. u32 val = qed_rd(p_hwfn, p_hwfn->p_main_ptt, bar_reg);
  1148. /* Get the BAR size(in KB) from hardware given val */
  1149. return 1 << (val + 15);
  1150. }
  1151. int qed_hw_prepare(struct qed_dev *cdev,
  1152. int personality)
  1153. {
  1154. struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
  1155. int rc;
  1156. /* Store the precompiled init data ptrs */
  1157. qed_init_iro_array(cdev);
  1158. /* Initialize the first hwfn - will learn number of hwfns */
  1159. rc = qed_hw_prepare_single(p_hwfn,
  1160. cdev->regview,
  1161. cdev->doorbells, personality);
  1162. if (rc)
  1163. return rc;
  1164. personality = p_hwfn->hw_info.personality;
  1165. /* Initialize the rest of the hwfns */
  1166. if (cdev->num_hwfns > 1) {
  1167. void __iomem *p_regview, *p_doorbell;
  1168. u8 __iomem *addr;
  1169. /* adjust bar offset for second engine */
  1170. addr = cdev->regview + qed_hw_bar_size(p_hwfn, 0) / 2;
  1171. p_regview = addr;
  1172. /* adjust doorbell bar offset for second engine */
  1173. addr = cdev->doorbells + qed_hw_bar_size(p_hwfn, 1) / 2;
  1174. p_doorbell = addr;
  1175. /* prepare second hw function */
  1176. rc = qed_hw_prepare_single(&cdev->hwfns[1], p_regview,
  1177. p_doorbell, personality);
  1178. /* in case of error, need to free the previously
  1179. * initiliazed hwfn 0.
  1180. */
  1181. if (rc) {
  1182. qed_init_free(p_hwfn);
  1183. qed_mcp_free(p_hwfn);
  1184. qed_hw_hwfn_free(p_hwfn);
  1185. }
  1186. }
  1187. return rc;
  1188. }
  1189. void qed_hw_remove(struct qed_dev *cdev)
  1190. {
  1191. int i;
  1192. for_each_hwfn(cdev, i) {
  1193. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1194. qed_init_free(p_hwfn);
  1195. qed_hw_hwfn_free(p_hwfn);
  1196. qed_mcp_free(p_hwfn);
  1197. }
  1198. }
  1199. int qed_chain_alloc(struct qed_dev *cdev,
  1200. enum qed_chain_use_mode intended_use,
  1201. enum qed_chain_mode mode,
  1202. u16 num_elems,
  1203. size_t elem_size,
  1204. struct qed_chain *p_chain)
  1205. {
  1206. dma_addr_t p_pbl_phys = 0;
  1207. void *p_pbl_virt = NULL;
  1208. dma_addr_t p_phys = 0;
  1209. void *p_virt = NULL;
  1210. u16 page_cnt = 0;
  1211. size_t size;
  1212. if (mode == QED_CHAIN_MODE_SINGLE)
  1213. page_cnt = 1;
  1214. else
  1215. page_cnt = QED_CHAIN_PAGE_CNT(num_elems, elem_size, mode);
  1216. size = page_cnt * QED_CHAIN_PAGE_SIZE;
  1217. p_virt = dma_alloc_coherent(&cdev->pdev->dev,
  1218. size, &p_phys, GFP_KERNEL);
  1219. if (!p_virt) {
  1220. DP_NOTICE(cdev, "Failed to allocate chain mem\n");
  1221. goto nomem;
  1222. }
  1223. if (mode == QED_CHAIN_MODE_PBL) {
  1224. size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
  1225. p_pbl_virt = dma_alloc_coherent(&cdev->pdev->dev,
  1226. size, &p_pbl_phys,
  1227. GFP_KERNEL);
  1228. if (!p_pbl_virt) {
  1229. DP_NOTICE(cdev, "Failed to allocate chain pbl mem\n");
  1230. goto nomem;
  1231. }
  1232. qed_chain_pbl_init(p_chain, p_virt, p_phys, page_cnt,
  1233. (u8)elem_size, intended_use,
  1234. p_pbl_phys, p_pbl_virt);
  1235. } else {
  1236. qed_chain_init(p_chain, p_virt, p_phys, page_cnt,
  1237. (u8)elem_size, intended_use, mode);
  1238. }
  1239. return 0;
  1240. nomem:
  1241. dma_free_coherent(&cdev->pdev->dev,
  1242. page_cnt * QED_CHAIN_PAGE_SIZE,
  1243. p_virt, p_phys);
  1244. dma_free_coherent(&cdev->pdev->dev,
  1245. page_cnt * QED_CHAIN_PBL_ENTRY_SIZE,
  1246. p_pbl_virt, p_pbl_phys);
  1247. return -ENOMEM;
  1248. }
  1249. void qed_chain_free(struct qed_dev *cdev,
  1250. struct qed_chain *p_chain)
  1251. {
  1252. size_t size;
  1253. if (!p_chain->p_virt_addr)
  1254. return;
  1255. if (p_chain->mode == QED_CHAIN_MODE_PBL) {
  1256. size = p_chain->page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
  1257. dma_free_coherent(&cdev->pdev->dev, size,
  1258. p_chain->pbl.p_virt_table,
  1259. p_chain->pbl.p_phys_table);
  1260. }
  1261. size = p_chain->page_cnt * QED_CHAIN_PAGE_SIZE;
  1262. dma_free_coherent(&cdev->pdev->dev, size,
  1263. p_chain->p_virt_addr,
  1264. p_chain->p_phys_addr);
  1265. }
  1266. static void __qed_get_vport_stats(struct qed_dev *cdev,
  1267. struct qed_eth_stats *stats)
  1268. {
  1269. int i, j;
  1270. memset(stats, 0, sizeof(*stats));
  1271. for_each_hwfn(cdev, i) {
  1272. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1273. struct eth_mstorm_per_queue_stat mstats;
  1274. struct eth_ustorm_per_queue_stat ustats;
  1275. struct eth_pstorm_per_queue_stat pstats;
  1276. struct tstorm_per_port_stat tstats;
  1277. struct port_stats port_stats;
  1278. struct qed_ptt *p_ptt = qed_ptt_acquire(p_hwfn);
  1279. if (!p_ptt) {
  1280. DP_ERR(p_hwfn, "Failed to acquire ptt\n");
  1281. continue;
  1282. }
  1283. memset(&mstats, 0, sizeof(mstats));
  1284. qed_memcpy_from(p_hwfn, p_ptt, &mstats,
  1285. p_hwfn->storm_stats.mstats.address,
  1286. p_hwfn->storm_stats.mstats.len);
  1287. memset(&ustats, 0, sizeof(ustats));
  1288. qed_memcpy_from(p_hwfn, p_ptt, &ustats,
  1289. p_hwfn->storm_stats.ustats.address,
  1290. p_hwfn->storm_stats.ustats.len);
  1291. memset(&pstats, 0, sizeof(pstats));
  1292. qed_memcpy_from(p_hwfn, p_ptt, &pstats,
  1293. p_hwfn->storm_stats.pstats.address,
  1294. p_hwfn->storm_stats.pstats.len);
  1295. memset(&tstats, 0, sizeof(tstats));
  1296. qed_memcpy_from(p_hwfn, p_ptt, &tstats,
  1297. p_hwfn->storm_stats.tstats.address,
  1298. p_hwfn->storm_stats.tstats.len);
  1299. memset(&port_stats, 0, sizeof(port_stats));
  1300. if (p_hwfn->mcp_info)
  1301. qed_memcpy_from(p_hwfn, p_ptt, &port_stats,
  1302. p_hwfn->mcp_info->port_addr +
  1303. offsetof(struct public_port, stats),
  1304. sizeof(port_stats));
  1305. qed_ptt_release(p_hwfn, p_ptt);
  1306. stats->no_buff_discards +=
  1307. HILO_64_REGPAIR(mstats.no_buff_discard);
  1308. stats->packet_too_big_discard +=
  1309. HILO_64_REGPAIR(mstats.packet_too_big_discard);
  1310. stats->ttl0_discard +=
  1311. HILO_64_REGPAIR(mstats.ttl0_discard);
  1312. stats->tpa_coalesced_pkts +=
  1313. HILO_64_REGPAIR(mstats.tpa_coalesced_pkts);
  1314. stats->tpa_coalesced_events +=
  1315. HILO_64_REGPAIR(mstats.tpa_coalesced_events);
  1316. stats->tpa_aborts_num +=
  1317. HILO_64_REGPAIR(mstats.tpa_aborts_num);
  1318. stats->tpa_coalesced_bytes +=
  1319. HILO_64_REGPAIR(mstats.tpa_coalesced_bytes);
  1320. stats->rx_ucast_bytes +=
  1321. HILO_64_REGPAIR(ustats.rcv_ucast_bytes);
  1322. stats->rx_mcast_bytes +=
  1323. HILO_64_REGPAIR(ustats.rcv_mcast_bytes);
  1324. stats->rx_bcast_bytes +=
  1325. HILO_64_REGPAIR(ustats.rcv_bcast_bytes);
  1326. stats->rx_ucast_pkts +=
  1327. HILO_64_REGPAIR(ustats.rcv_ucast_pkts);
  1328. stats->rx_mcast_pkts +=
  1329. HILO_64_REGPAIR(ustats.rcv_mcast_pkts);
  1330. stats->rx_bcast_pkts +=
  1331. HILO_64_REGPAIR(ustats.rcv_bcast_pkts);
  1332. stats->mftag_filter_discards +=
  1333. HILO_64_REGPAIR(tstats.mftag_filter_discard);
  1334. stats->mac_filter_discards +=
  1335. HILO_64_REGPAIR(tstats.eth_mac_filter_discard);
  1336. stats->tx_ucast_bytes +=
  1337. HILO_64_REGPAIR(pstats.sent_ucast_bytes);
  1338. stats->tx_mcast_bytes +=
  1339. HILO_64_REGPAIR(pstats.sent_mcast_bytes);
  1340. stats->tx_bcast_bytes +=
  1341. HILO_64_REGPAIR(pstats.sent_bcast_bytes);
  1342. stats->tx_ucast_pkts +=
  1343. HILO_64_REGPAIR(pstats.sent_ucast_pkts);
  1344. stats->tx_mcast_pkts +=
  1345. HILO_64_REGPAIR(pstats.sent_mcast_pkts);
  1346. stats->tx_bcast_pkts +=
  1347. HILO_64_REGPAIR(pstats.sent_bcast_pkts);
  1348. stats->tx_err_drop_pkts +=
  1349. HILO_64_REGPAIR(pstats.error_drop_pkts);
  1350. stats->rx_64_byte_packets += port_stats.pmm.r64;
  1351. stats->rx_127_byte_packets += port_stats.pmm.r127;
  1352. stats->rx_255_byte_packets += port_stats.pmm.r255;
  1353. stats->rx_511_byte_packets += port_stats.pmm.r511;
  1354. stats->rx_1023_byte_packets += port_stats.pmm.r1023;
  1355. stats->rx_1518_byte_packets += port_stats.pmm.r1518;
  1356. stats->rx_1522_byte_packets += port_stats.pmm.r1522;
  1357. stats->rx_2047_byte_packets += port_stats.pmm.r2047;
  1358. stats->rx_4095_byte_packets += port_stats.pmm.r4095;
  1359. stats->rx_9216_byte_packets += port_stats.pmm.r9216;
  1360. stats->rx_16383_byte_packets += port_stats.pmm.r16383;
  1361. stats->rx_crc_errors += port_stats.pmm.rfcs;
  1362. stats->rx_mac_crtl_frames += port_stats.pmm.rxcf;
  1363. stats->rx_pause_frames += port_stats.pmm.rxpf;
  1364. stats->rx_pfc_frames += port_stats.pmm.rxpp;
  1365. stats->rx_align_errors += port_stats.pmm.raln;
  1366. stats->rx_carrier_errors += port_stats.pmm.rfcr;
  1367. stats->rx_oversize_packets += port_stats.pmm.rovr;
  1368. stats->rx_jabbers += port_stats.pmm.rjbr;
  1369. stats->rx_undersize_packets += port_stats.pmm.rund;
  1370. stats->rx_fragments += port_stats.pmm.rfrg;
  1371. stats->tx_64_byte_packets += port_stats.pmm.t64;
  1372. stats->tx_65_to_127_byte_packets += port_stats.pmm.t127;
  1373. stats->tx_128_to_255_byte_packets += port_stats.pmm.t255;
  1374. stats->tx_256_to_511_byte_packets += port_stats.pmm.t511;
  1375. stats->tx_512_to_1023_byte_packets += port_stats.pmm.t1023;
  1376. stats->tx_1024_to_1518_byte_packets += port_stats.pmm.t1518;
  1377. stats->tx_1519_to_2047_byte_packets += port_stats.pmm.t2047;
  1378. stats->tx_2048_to_4095_byte_packets += port_stats.pmm.t4095;
  1379. stats->tx_4096_to_9216_byte_packets += port_stats.pmm.t9216;
  1380. stats->tx_9217_to_16383_byte_packets += port_stats.pmm.t16383;
  1381. stats->tx_pause_frames += port_stats.pmm.txpf;
  1382. stats->tx_pfc_frames += port_stats.pmm.txpp;
  1383. stats->tx_lpi_entry_count += port_stats.pmm.tlpiec;
  1384. stats->tx_total_collisions += port_stats.pmm.tncl;
  1385. stats->rx_mac_bytes += port_stats.pmm.rbyte;
  1386. stats->rx_mac_uc_packets += port_stats.pmm.rxuca;
  1387. stats->rx_mac_mc_packets += port_stats.pmm.rxmca;
  1388. stats->rx_mac_bc_packets += port_stats.pmm.rxbca;
  1389. stats->rx_mac_frames_ok += port_stats.pmm.rxpok;
  1390. stats->tx_mac_bytes += port_stats.pmm.tbyte;
  1391. stats->tx_mac_uc_packets += port_stats.pmm.txuca;
  1392. stats->tx_mac_mc_packets += port_stats.pmm.txmca;
  1393. stats->tx_mac_bc_packets += port_stats.pmm.txbca;
  1394. stats->tx_mac_ctrl_frames += port_stats.pmm.txcf;
  1395. for (j = 0; j < 8; j++) {
  1396. stats->brb_truncates += port_stats.brb.brb_truncate[j];
  1397. stats->brb_discards += port_stats.brb.brb_discard[j];
  1398. }
  1399. }
  1400. }
  1401. void qed_get_vport_stats(struct qed_dev *cdev,
  1402. struct qed_eth_stats *stats)
  1403. {
  1404. u32 i;
  1405. if (!cdev) {
  1406. memset(stats, 0, sizeof(*stats));
  1407. return;
  1408. }
  1409. __qed_get_vport_stats(cdev, stats);
  1410. if (!cdev->reset_stats)
  1411. return;
  1412. /* Reduce the statistics baseline */
  1413. for (i = 0; i < sizeof(struct qed_eth_stats) / sizeof(u64); i++)
  1414. ((u64 *)stats)[i] -= ((u64 *)cdev->reset_stats)[i];
  1415. }
  1416. /* zeroes V-PORT specific portion of stats (Port stats remains untouched) */
  1417. void qed_reset_vport_stats(struct qed_dev *cdev)
  1418. {
  1419. int i;
  1420. for_each_hwfn(cdev, i) {
  1421. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1422. struct eth_mstorm_per_queue_stat mstats;
  1423. struct eth_ustorm_per_queue_stat ustats;
  1424. struct eth_pstorm_per_queue_stat pstats;
  1425. struct qed_ptt *p_ptt = qed_ptt_acquire(p_hwfn);
  1426. if (!p_ptt) {
  1427. DP_ERR(p_hwfn, "Failed to acquire ptt\n");
  1428. continue;
  1429. }
  1430. memset(&mstats, 0, sizeof(mstats));
  1431. qed_memcpy_to(p_hwfn, p_ptt,
  1432. p_hwfn->storm_stats.mstats.address,
  1433. &mstats,
  1434. p_hwfn->storm_stats.mstats.len);
  1435. memset(&ustats, 0, sizeof(ustats));
  1436. qed_memcpy_to(p_hwfn, p_ptt,
  1437. p_hwfn->storm_stats.ustats.address,
  1438. &ustats,
  1439. p_hwfn->storm_stats.ustats.len);
  1440. memset(&pstats, 0, sizeof(pstats));
  1441. qed_memcpy_to(p_hwfn, p_ptt,
  1442. p_hwfn->storm_stats.pstats.address,
  1443. &pstats,
  1444. p_hwfn->storm_stats.pstats.len);
  1445. qed_ptt_release(p_hwfn, p_ptt);
  1446. }
  1447. /* PORT statistics are not necessarily reset, so we need to
  1448. * read and create a baseline for future statistics.
  1449. */
  1450. if (!cdev->reset_stats)
  1451. DP_INFO(cdev, "Reset stats not allocated\n");
  1452. else
  1453. __qed_get_vport_stats(cdev, cdev->reset_stats);
  1454. }
  1455. int qed_fw_l2_queue(struct qed_hwfn *p_hwfn,
  1456. u16 src_id, u16 *dst_id)
  1457. {
  1458. if (src_id >= RESC_NUM(p_hwfn, QED_L2_QUEUE)) {
  1459. u16 min, max;
  1460. min = (u16)RESC_START(p_hwfn, QED_L2_QUEUE);
  1461. max = min + RESC_NUM(p_hwfn, QED_L2_QUEUE);
  1462. DP_NOTICE(p_hwfn,
  1463. "l2_queue id [%d] is not valid, available indices [%d - %d]\n",
  1464. src_id, min, max);
  1465. return -EINVAL;
  1466. }
  1467. *dst_id = RESC_START(p_hwfn, QED_L2_QUEUE) + src_id;
  1468. return 0;
  1469. }
  1470. int qed_fw_vport(struct qed_hwfn *p_hwfn,
  1471. u8 src_id, u8 *dst_id)
  1472. {
  1473. if (src_id >= RESC_NUM(p_hwfn, QED_VPORT)) {
  1474. u8 min, max;
  1475. min = (u8)RESC_START(p_hwfn, QED_VPORT);
  1476. max = min + RESC_NUM(p_hwfn, QED_VPORT);
  1477. DP_NOTICE(p_hwfn,
  1478. "vport id [%d] is not valid, available indices [%d - %d]\n",
  1479. src_id, min, max);
  1480. return -EINVAL;
  1481. }
  1482. *dst_id = RESC_START(p_hwfn, QED_VPORT) + src_id;
  1483. return 0;
  1484. }
  1485. int qed_fw_rss_eng(struct qed_hwfn *p_hwfn,
  1486. u8 src_id, u8 *dst_id)
  1487. {
  1488. if (src_id >= RESC_NUM(p_hwfn, QED_RSS_ENG)) {
  1489. u8 min, max;
  1490. min = (u8)RESC_START(p_hwfn, QED_RSS_ENG);
  1491. max = min + RESC_NUM(p_hwfn, QED_RSS_ENG);
  1492. DP_NOTICE(p_hwfn,
  1493. "rss_eng id [%d] is not valid, available indices [%d - %d]\n",
  1494. src_id, min, max);
  1495. return -EINVAL;
  1496. }
  1497. *dst_id = RESC_START(p_hwfn, QED_RSS_ENG) + src_id;
  1498. return 0;
  1499. }