qed_l2.c 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371
  1. /* QLogic qed NIC Driver
  2. * Copyright (c) 2015-2017 QLogic Corporation
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and /or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/types.h>
  33. #include <asm/byteorder.h>
  34. #include <asm/param.h>
  35. #include <linux/delay.h>
  36. #include <linux/dma-mapping.h>
  37. #include <linux/etherdevice.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/kernel.h>
  40. #include <linux/module.h>
  41. #include <linux/pci.h>
  42. #include <linux/slab.h>
  43. #include <linux/stddef.h>
  44. #include <linux/string.h>
  45. #include <linux/version.h>
  46. #include <linux/workqueue.h>
  47. #include <linux/bitops.h>
  48. #include <linux/bug.h>
  49. #include <linux/vmalloc.h>
  50. #include "qed.h"
  51. #include <linux/qed/qed_chain.h>
  52. #include "qed_cxt.h"
  53. #include "qed_dev_api.h"
  54. #include <linux/qed/qed_eth_if.h>
  55. #include "qed_hsi.h"
  56. #include "qed_hw.h"
  57. #include "qed_int.h"
  58. #include "qed_l2.h"
  59. #include "qed_mcp.h"
  60. #include "qed_reg_addr.h"
  61. #include "qed_sp.h"
  62. #include "qed_sriov.h"
  63. #define QED_MAX_SGES_NUM 16
  64. #define CRC32_POLY 0x1edc6f41
  65. void qed_eth_queue_cid_release(struct qed_hwfn *p_hwfn,
  66. struct qed_queue_cid *p_cid)
  67. {
  68. /* VFs' CIDs are 0-based in PF-view, and uninitialized on VF */
  69. if (!p_cid->is_vf && IS_PF(p_hwfn->cdev))
  70. qed_cxt_release_cid(p_hwfn, p_cid->cid);
  71. vfree(p_cid);
  72. }
  73. /* The internal is only meant to be directly called by PFs initializeing CIDs
  74. * for their VFs.
  75. */
  76. struct qed_queue_cid *
  77. _qed_eth_queue_to_cid(struct qed_hwfn *p_hwfn,
  78. u16 opaque_fid,
  79. u32 cid,
  80. u8 vf_qid,
  81. struct qed_queue_start_common_params *p_params)
  82. {
  83. bool b_is_same = (p_hwfn->hw_info.opaque_fid == opaque_fid);
  84. struct qed_queue_cid *p_cid;
  85. int rc;
  86. p_cid = vmalloc(sizeof(*p_cid));
  87. if (!p_cid)
  88. return NULL;
  89. memset(p_cid, 0, sizeof(*p_cid));
  90. p_cid->opaque_fid = opaque_fid;
  91. p_cid->cid = cid;
  92. p_cid->vf_qid = vf_qid;
  93. p_cid->rel = *p_params;
  94. p_cid->p_owner = p_hwfn;
  95. /* Don't try calculating the absolute indices for VFs */
  96. if (IS_VF(p_hwfn->cdev)) {
  97. p_cid->abs = p_cid->rel;
  98. goto out;
  99. }
  100. /* Calculate the engine-absolute indices of the resources.
  101. * This would guarantee they're valid later on.
  102. * In some cases [SBs] we already have the right values.
  103. */
  104. rc = qed_fw_vport(p_hwfn, p_cid->rel.vport_id, &p_cid->abs.vport_id);
  105. if (rc)
  106. goto fail;
  107. rc = qed_fw_l2_queue(p_hwfn, p_cid->rel.queue_id, &p_cid->abs.queue_id);
  108. if (rc)
  109. goto fail;
  110. /* In case of a PF configuring its VF's queues, the stats-id is already
  111. * absolute [since there's a single index that's suitable per-VF].
  112. */
  113. if (b_is_same) {
  114. rc = qed_fw_vport(p_hwfn, p_cid->rel.stats_id,
  115. &p_cid->abs.stats_id);
  116. if (rc)
  117. goto fail;
  118. } else {
  119. p_cid->abs.stats_id = p_cid->rel.stats_id;
  120. }
  121. /* SBs relevant information was already provided as absolute */
  122. p_cid->abs.sb = p_cid->rel.sb;
  123. p_cid->abs.sb_idx = p_cid->rel.sb_idx;
  124. /* This is tricky - we're actually interested in whehter this is a PF
  125. * entry meant for the VF.
  126. */
  127. if (!b_is_same)
  128. p_cid->is_vf = true;
  129. out:
  130. DP_VERBOSE(p_hwfn,
  131. QED_MSG_SP,
  132. "opaque_fid: %04x CID %08x vport %02x [%02x] qzone %04x [%04x] stats %02x [%02x] SB %04x PI %02x\n",
  133. p_cid->opaque_fid,
  134. p_cid->cid,
  135. p_cid->rel.vport_id,
  136. p_cid->abs.vport_id,
  137. p_cid->rel.queue_id,
  138. p_cid->abs.queue_id,
  139. p_cid->rel.stats_id,
  140. p_cid->abs.stats_id, p_cid->abs.sb, p_cid->abs.sb_idx);
  141. return p_cid;
  142. fail:
  143. vfree(p_cid);
  144. return NULL;
  145. }
  146. static struct qed_queue_cid *qed_eth_queue_to_cid(struct qed_hwfn *p_hwfn,
  147. u16 opaque_fid, struct
  148. qed_queue_start_common_params
  149. *p_params)
  150. {
  151. struct qed_queue_cid *p_cid;
  152. u32 cid = 0;
  153. /* Get a unique firmware CID for this queue, in case it's a PF.
  154. * VF's don't need a CID as the queue configuration will be done
  155. * by PF.
  156. */
  157. if (IS_PF(p_hwfn->cdev)) {
  158. if (qed_cxt_acquire_cid(p_hwfn, PROTOCOLID_ETH, &cid)) {
  159. DP_NOTICE(p_hwfn, "Failed to acquire cid\n");
  160. return NULL;
  161. }
  162. }
  163. p_cid = _qed_eth_queue_to_cid(p_hwfn, opaque_fid, cid, 0, p_params);
  164. if (!p_cid && IS_PF(p_hwfn->cdev))
  165. qed_cxt_release_cid(p_hwfn, cid);
  166. return p_cid;
  167. }
  168. int qed_sp_eth_vport_start(struct qed_hwfn *p_hwfn,
  169. struct qed_sp_vport_start_params *p_params)
  170. {
  171. struct vport_start_ramrod_data *p_ramrod = NULL;
  172. struct qed_spq_entry *p_ent = NULL;
  173. struct qed_sp_init_data init_data;
  174. u8 abs_vport_id = 0;
  175. int rc = -EINVAL;
  176. u16 rx_mode = 0;
  177. rc = qed_fw_vport(p_hwfn, p_params->vport_id, &abs_vport_id);
  178. if (rc)
  179. return rc;
  180. memset(&init_data, 0, sizeof(init_data));
  181. init_data.cid = qed_spq_get_cid(p_hwfn);
  182. init_data.opaque_fid = p_params->opaque_fid;
  183. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  184. rc = qed_sp_init_request(p_hwfn, &p_ent,
  185. ETH_RAMROD_VPORT_START,
  186. PROTOCOLID_ETH, &init_data);
  187. if (rc)
  188. return rc;
  189. p_ramrod = &p_ent->ramrod.vport_start;
  190. p_ramrod->vport_id = abs_vport_id;
  191. p_ramrod->mtu = cpu_to_le16(p_params->mtu);
  192. p_ramrod->handle_ptp_pkts = p_params->handle_ptp_pkts;
  193. p_ramrod->inner_vlan_removal_en = p_params->remove_inner_vlan;
  194. p_ramrod->drop_ttl0_en = p_params->drop_ttl0;
  195. p_ramrod->untagged = p_params->only_untagged;
  196. SET_FIELD(rx_mode, ETH_VPORT_RX_MODE_UCAST_DROP_ALL, 1);
  197. SET_FIELD(rx_mode, ETH_VPORT_RX_MODE_MCAST_DROP_ALL, 1);
  198. p_ramrod->rx_mode.state = cpu_to_le16(rx_mode);
  199. /* TPA related fields */
  200. memset(&p_ramrod->tpa_param, 0, sizeof(struct eth_vport_tpa_param));
  201. p_ramrod->tpa_param.max_buff_num = p_params->max_buffers_per_cqe;
  202. switch (p_params->tpa_mode) {
  203. case QED_TPA_MODE_GRO:
  204. p_ramrod->tpa_param.tpa_max_aggs_num = ETH_TPA_MAX_AGGS_NUM;
  205. p_ramrod->tpa_param.tpa_max_size = (u16)-1;
  206. p_ramrod->tpa_param.tpa_min_size_to_cont = p_params->mtu / 2;
  207. p_ramrod->tpa_param.tpa_min_size_to_start = p_params->mtu / 2;
  208. p_ramrod->tpa_param.tpa_ipv4_en_flg = 1;
  209. p_ramrod->tpa_param.tpa_ipv6_en_flg = 1;
  210. p_ramrod->tpa_param.tpa_pkt_split_flg = 1;
  211. p_ramrod->tpa_param.tpa_gro_consistent_flg = 1;
  212. break;
  213. default:
  214. break;
  215. }
  216. p_ramrod->tx_switching_en = p_params->tx_switching;
  217. p_ramrod->ctl_frame_mac_check_en = !!p_params->check_mac;
  218. p_ramrod->ctl_frame_ethtype_check_en = !!p_params->check_ethtype;
  219. /* Software Function ID in hwfn (PFs are 0 - 15, VFs are 16 - 135) */
  220. p_ramrod->sw_fid = qed_concrete_to_sw_fid(p_hwfn->cdev,
  221. p_params->concrete_fid);
  222. return qed_spq_post(p_hwfn, p_ent, NULL);
  223. }
  224. static int qed_sp_vport_start(struct qed_hwfn *p_hwfn,
  225. struct qed_sp_vport_start_params *p_params)
  226. {
  227. if (IS_VF(p_hwfn->cdev)) {
  228. return qed_vf_pf_vport_start(p_hwfn, p_params->vport_id,
  229. p_params->mtu,
  230. p_params->remove_inner_vlan,
  231. p_params->tpa_mode,
  232. p_params->max_buffers_per_cqe,
  233. p_params->only_untagged);
  234. }
  235. return qed_sp_eth_vport_start(p_hwfn, p_params);
  236. }
  237. static int
  238. qed_sp_vport_update_rss(struct qed_hwfn *p_hwfn,
  239. struct vport_update_ramrod_data *p_ramrod,
  240. struct qed_rss_params *p_rss)
  241. {
  242. struct eth_vport_rss_config *p_config;
  243. u16 capabilities = 0;
  244. int i, table_size;
  245. int rc = 0;
  246. if (!p_rss) {
  247. p_ramrod->common.update_rss_flg = 0;
  248. return rc;
  249. }
  250. p_config = &p_ramrod->rss_config;
  251. BUILD_BUG_ON(QED_RSS_IND_TABLE_SIZE != ETH_RSS_IND_TABLE_ENTRIES_NUM);
  252. rc = qed_fw_rss_eng(p_hwfn, p_rss->rss_eng_id, &p_config->rss_id);
  253. if (rc)
  254. return rc;
  255. p_ramrod->common.update_rss_flg = p_rss->update_rss_config;
  256. p_config->update_rss_capabilities = p_rss->update_rss_capabilities;
  257. p_config->update_rss_ind_table = p_rss->update_rss_ind_table;
  258. p_config->update_rss_key = p_rss->update_rss_key;
  259. p_config->rss_mode = p_rss->rss_enable ?
  260. ETH_VPORT_RSS_MODE_REGULAR :
  261. ETH_VPORT_RSS_MODE_DISABLED;
  262. SET_FIELD(capabilities,
  263. ETH_VPORT_RSS_CONFIG_IPV4_CAPABILITY,
  264. !!(p_rss->rss_caps & QED_RSS_IPV4));
  265. SET_FIELD(capabilities,
  266. ETH_VPORT_RSS_CONFIG_IPV6_CAPABILITY,
  267. !!(p_rss->rss_caps & QED_RSS_IPV6));
  268. SET_FIELD(capabilities,
  269. ETH_VPORT_RSS_CONFIG_IPV4_TCP_CAPABILITY,
  270. !!(p_rss->rss_caps & QED_RSS_IPV4_TCP));
  271. SET_FIELD(capabilities,
  272. ETH_VPORT_RSS_CONFIG_IPV6_TCP_CAPABILITY,
  273. !!(p_rss->rss_caps & QED_RSS_IPV6_TCP));
  274. SET_FIELD(capabilities,
  275. ETH_VPORT_RSS_CONFIG_IPV4_UDP_CAPABILITY,
  276. !!(p_rss->rss_caps & QED_RSS_IPV4_UDP));
  277. SET_FIELD(capabilities,
  278. ETH_VPORT_RSS_CONFIG_IPV6_UDP_CAPABILITY,
  279. !!(p_rss->rss_caps & QED_RSS_IPV6_UDP));
  280. p_config->tbl_size = p_rss->rss_table_size_log;
  281. p_config->capabilities = cpu_to_le16(capabilities);
  282. DP_VERBOSE(p_hwfn, NETIF_MSG_IFUP,
  283. "update rss flag %d, rss_mode = %d, update_caps = %d, capabilities = %d, update_ind = %d, update_rss_key = %d\n",
  284. p_ramrod->common.update_rss_flg,
  285. p_config->rss_mode,
  286. p_config->update_rss_capabilities,
  287. p_config->capabilities,
  288. p_config->update_rss_ind_table, p_config->update_rss_key);
  289. table_size = min_t(int, QED_RSS_IND_TABLE_SIZE,
  290. 1 << p_config->tbl_size);
  291. for (i = 0; i < table_size; i++) {
  292. struct qed_queue_cid *p_queue = p_rss->rss_ind_table[i];
  293. if (!p_queue)
  294. return -EINVAL;
  295. p_config->indirection_table[i] =
  296. cpu_to_le16(p_queue->abs.queue_id);
  297. }
  298. DP_VERBOSE(p_hwfn, NETIF_MSG_IFUP,
  299. "Configured RSS indirection table [%d entries]:\n",
  300. table_size);
  301. for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i += 0x10) {
  302. DP_VERBOSE(p_hwfn,
  303. NETIF_MSG_IFUP,
  304. "%04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x\n",
  305. le16_to_cpu(p_config->indirection_table[i]),
  306. le16_to_cpu(p_config->indirection_table[i + 1]),
  307. le16_to_cpu(p_config->indirection_table[i + 2]),
  308. le16_to_cpu(p_config->indirection_table[i + 3]),
  309. le16_to_cpu(p_config->indirection_table[i + 4]),
  310. le16_to_cpu(p_config->indirection_table[i + 5]),
  311. le16_to_cpu(p_config->indirection_table[i + 6]),
  312. le16_to_cpu(p_config->indirection_table[i + 7]),
  313. le16_to_cpu(p_config->indirection_table[i + 8]),
  314. le16_to_cpu(p_config->indirection_table[i + 9]),
  315. le16_to_cpu(p_config->indirection_table[i + 10]),
  316. le16_to_cpu(p_config->indirection_table[i + 11]),
  317. le16_to_cpu(p_config->indirection_table[i + 12]),
  318. le16_to_cpu(p_config->indirection_table[i + 13]),
  319. le16_to_cpu(p_config->indirection_table[i + 14]),
  320. le16_to_cpu(p_config->indirection_table[i + 15]));
  321. }
  322. for (i = 0; i < 10; i++)
  323. p_config->rss_key[i] = cpu_to_le32(p_rss->rss_key[i]);
  324. return rc;
  325. }
  326. static void
  327. qed_sp_update_accept_mode(struct qed_hwfn *p_hwfn,
  328. struct vport_update_ramrod_data *p_ramrod,
  329. struct qed_filter_accept_flags accept_flags)
  330. {
  331. p_ramrod->common.update_rx_mode_flg =
  332. accept_flags.update_rx_mode_config;
  333. p_ramrod->common.update_tx_mode_flg =
  334. accept_flags.update_tx_mode_config;
  335. /* Set Rx mode accept flags */
  336. if (p_ramrod->common.update_rx_mode_flg) {
  337. u8 accept_filter = accept_flags.rx_accept_filter;
  338. u16 state = 0;
  339. SET_FIELD(state, ETH_VPORT_RX_MODE_UCAST_DROP_ALL,
  340. !(!!(accept_filter & QED_ACCEPT_UCAST_MATCHED) ||
  341. !!(accept_filter & QED_ACCEPT_UCAST_UNMATCHED)));
  342. SET_FIELD(state, ETH_VPORT_RX_MODE_UCAST_ACCEPT_UNMATCHED,
  343. !!(accept_filter & QED_ACCEPT_UCAST_UNMATCHED));
  344. SET_FIELD(state, ETH_VPORT_RX_MODE_MCAST_DROP_ALL,
  345. !(!!(accept_filter & QED_ACCEPT_MCAST_MATCHED) ||
  346. !!(accept_filter & QED_ACCEPT_MCAST_UNMATCHED)));
  347. SET_FIELD(state, ETH_VPORT_RX_MODE_MCAST_ACCEPT_ALL,
  348. (!!(accept_filter & QED_ACCEPT_MCAST_MATCHED) &&
  349. !!(accept_filter & QED_ACCEPT_MCAST_UNMATCHED)));
  350. SET_FIELD(state, ETH_VPORT_RX_MODE_BCAST_ACCEPT_ALL,
  351. !!(accept_filter & QED_ACCEPT_BCAST));
  352. p_ramrod->rx_mode.state = cpu_to_le16(state);
  353. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  354. "p_ramrod->rx_mode.state = 0x%x\n", state);
  355. }
  356. /* Set Tx mode accept flags */
  357. if (p_ramrod->common.update_tx_mode_flg) {
  358. u8 accept_filter = accept_flags.tx_accept_filter;
  359. u16 state = 0;
  360. SET_FIELD(state, ETH_VPORT_TX_MODE_UCAST_DROP_ALL,
  361. !!(accept_filter & QED_ACCEPT_NONE));
  362. SET_FIELD(state, ETH_VPORT_TX_MODE_MCAST_DROP_ALL,
  363. !!(accept_filter & QED_ACCEPT_NONE));
  364. SET_FIELD(state, ETH_VPORT_TX_MODE_MCAST_ACCEPT_ALL,
  365. (!!(accept_filter & QED_ACCEPT_MCAST_MATCHED) &&
  366. !!(accept_filter & QED_ACCEPT_MCAST_UNMATCHED)));
  367. SET_FIELD(state, ETH_VPORT_TX_MODE_BCAST_ACCEPT_ALL,
  368. !!(accept_filter & QED_ACCEPT_BCAST));
  369. p_ramrod->tx_mode.state = cpu_to_le16(state);
  370. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  371. "p_ramrod->tx_mode.state = 0x%x\n", state);
  372. }
  373. }
  374. static void
  375. qed_sp_vport_update_sge_tpa(struct qed_hwfn *p_hwfn,
  376. struct vport_update_ramrod_data *p_ramrod,
  377. struct qed_sge_tpa_params *p_params)
  378. {
  379. struct eth_vport_tpa_param *p_tpa;
  380. if (!p_params) {
  381. p_ramrod->common.update_tpa_param_flg = 0;
  382. p_ramrod->common.update_tpa_en_flg = 0;
  383. p_ramrod->common.update_tpa_param_flg = 0;
  384. return;
  385. }
  386. p_ramrod->common.update_tpa_en_flg = p_params->update_tpa_en_flg;
  387. p_tpa = &p_ramrod->tpa_param;
  388. p_tpa->tpa_ipv4_en_flg = p_params->tpa_ipv4_en_flg;
  389. p_tpa->tpa_ipv6_en_flg = p_params->tpa_ipv6_en_flg;
  390. p_tpa->tpa_ipv4_tunn_en_flg = p_params->tpa_ipv4_tunn_en_flg;
  391. p_tpa->tpa_ipv6_tunn_en_flg = p_params->tpa_ipv6_tunn_en_flg;
  392. p_ramrod->common.update_tpa_param_flg = p_params->update_tpa_param_flg;
  393. p_tpa->max_buff_num = p_params->max_buffers_per_cqe;
  394. p_tpa->tpa_pkt_split_flg = p_params->tpa_pkt_split_flg;
  395. p_tpa->tpa_hdr_data_split_flg = p_params->tpa_hdr_data_split_flg;
  396. p_tpa->tpa_gro_consistent_flg = p_params->tpa_gro_consistent_flg;
  397. p_tpa->tpa_max_aggs_num = p_params->tpa_max_aggs_num;
  398. p_tpa->tpa_max_size = p_params->tpa_max_size;
  399. p_tpa->tpa_min_size_to_start = p_params->tpa_min_size_to_start;
  400. p_tpa->tpa_min_size_to_cont = p_params->tpa_min_size_to_cont;
  401. }
  402. static void
  403. qed_sp_update_mcast_bin(struct qed_hwfn *p_hwfn,
  404. struct vport_update_ramrod_data *p_ramrod,
  405. struct qed_sp_vport_update_params *p_params)
  406. {
  407. int i;
  408. memset(&p_ramrod->approx_mcast.bins, 0,
  409. sizeof(p_ramrod->approx_mcast.bins));
  410. if (!p_params->update_approx_mcast_flg)
  411. return;
  412. p_ramrod->common.update_approx_mcast_flg = 1;
  413. for (i = 0; i < ETH_MULTICAST_MAC_BINS_IN_REGS; i++) {
  414. u32 *p_bins = (u32 *)p_params->bins;
  415. p_ramrod->approx_mcast.bins[i] = cpu_to_le32(p_bins[i]);
  416. }
  417. }
  418. int qed_sp_vport_update(struct qed_hwfn *p_hwfn,
  419. struct qed_sp_vport_update_params *p_params,
  420. enum spq_mode comp_mode,
  421. struct qed_spq_comp_cb *p_comp_data)
  422. {
  423. struct qed_rss_params *p_rss_params = p_params->rss_params;
  424. struct vport_update_ramrod_data_cmn *p_cmn;
  425. struct qed_sp_init_data init_data;
  426. struct vport_update_ramrod_data *p_ramrod = NULL;
  427. struct qed_spq_entry *p_ent = NULL;
  428. u8 abs_vport_id = 0, val;
  429. int rc = -EINVAL;
  430. if (IS_VF(p_hwfn->cdev)) {
  431. rc = qed_vf_pf_vport_update(p_hwfn, p_params);
  432. return rc;
  433. }
  434. rc = qed_fw_vport(p_hwfn, p_params->vport_id, &abs_vport_id);
  435. if (rc)
  436. return rc;
  437. memset(&init_data, 0, sizeof(init_data));
  438. init_data.cid = qed_spq_get_cid(p_hwfn);
  439. init_data.opaque_fid = p_params->opaque_fid;
  440. init_data.comp_mode = comp_mode;
  441. init_data.p_comp_data = p_comp_data;
  442. rc = qed_sp_init_request(p_hwfn, &p_ent,
  443. ETH_RAMROD_VPORT_UPDATE,
  444. PROTOCOLID_ETH, &init_data);
  445. if (rc)
  446. return rc;
  447. /* Copy input params to ramrod according to FW struct */
  448. p_ramrod = &p_ent->ramrod.vport_update;
  449. p_cmn = &p_ramrod->common;
  450. p_cmn->vport_id = abs_vport_id;
  451. p_cmn->rx_active_flg = p_params->vport_active_rx_flg;
  452. p_cmn->update_rx_active_flg = p_params->update_vport_active_rx_flg;
  453. p_cmn->tx_active_flg = p_params->vport_active_tx_flg;
  454. p_cmn->update_tx_active_flg = p_params->update_vport_active_tx_flg;
  455. p_cmn->accept_any_vlan = p_params->accept_any_vlan;
  456. val = p_params->update_accept_any_vlan_flg;
  457. p_cmn->update_accept_any_vlan_flg = val;
  458. p_cmn->inner_vlan_removal_en = p_params->inner_vlan_removal_flg;
  459. val = p_params->update_inner_vlan_removal_flg;
  460. p_cmn->update_inner_vlan_removal_en_flg = val;
  461. p_cmn->default_vlan_en = p_params->default_vlan_enable_flg;
  462. val = p_params->update_default_vlan_enable_flg;
  463. p_cmn->update_default_vlan_en_flg = val;
  464. p_cmn->default_vlan = cpu_to_le16(p_params->default_vlan);
  465. p_cmn->update_default_vlan_flg = p_params->update_default_vlan_flg;
  466. p_cmn->silent_vlan_removal_en = p_params->silent_vlan_removal_flg;
  467. p_ramrod->common.tx_switching_en = p_params->tx_switching_flg;
  468. p_cmn->update_tx_switching_en_flg = p_params->update_tx_switching_flg;
  469. p_cmn->anti_spoofing_en = p_params->anti_spoofing_en;
  470. val = p_params->update_anti_spoofing_en_flg;
  471. p_ramrod->common.update_anti_spoofing_en_flg = val;
  472. rc = qed_sp_vport_update_rss(p_hwfn, p_ramrod, p_rss_params);
  473. if (rc) {
  474. /* Return spq entry which is taken in qed_sp_init_request()*/
  475. qed_spq_return_entry(p_hwfn, p_ent);
  476. return rc;
  477. }
  478. /* Update mcast bins for VFs, PF doesn't use this functionality */
  479. qed_sp_update_mcast_bin(p_hwfn, p_ramrod, p_params);
  480. qed_sp_update_accept_mode(p_hwfn, p_ramrod, p_params->accept_flags);
  481. qed_sp_vport_update_sge_tpa(p_hwfn, p_ramrod, p_params->sge_tpa_params);
  482. return qed_spq_post(p_hwfn, p_ent, NULL);
  483. }
  484. int qed_sp_vport_stop(struct qed_hwfn *p_hwfn, u16 opaque_fid, u8 vport_id)
  485. {
  486. struct vport_stop_ramrod_data *p_ramrod;
  487. struct qed_sp_init_data init_data;
  488. struct qed_spq_entry *p_ent;
  489. u8 abs_vport_id = 0;
  490. int rc;
  491. if (IS_VF(p_hwfn->cdev))
  492. return qed_vf_pf_vport_stop(p_hwfn);
  493. rc = qed_fw_vport(p_hwfn, vport_id, &abs_vport_id);
  494. if (rc)
  495. return rc;
  496. memset(&init_data, 0, sizeof(init_data));
  497. init_data.cid = qed_spq_get_cid(p_hwfn);
  498. init_data.opaque_fid = opaque_fid;
  499. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  500. rc = qed_sp_init_request(p_hwfn, &p_ent,
  501. ETH_RAMROD_VPORT_STOP,
  502. PROTOCOLID_ETH, &init_data);
  503. if (rc)
  504. return rc;
  505. p_ramrod = &p_ent->ramrod.vport_stop;
  506. p_ramrod->vport_id = abs_vport_id;
  507. return qed_spq_post(p_hwfn, p_ent, NULL);
  508. }
  509. static int
  510. qed_vf_pf_accept_flags(struct qed_hwfn *p_hwfn,
  511. struct qed_filter_accept_flags *p_accept_flags)
  512. {
  513. struct qed_sp_vport_update_params s_params;
  514. memset(&s_params, 0, sizeof(s_params));
  515. memcpy(&s_params.accept_flags, p_accept_flags,
  516. sizeof(struct qed_filter_accept_flags));
  517. return qed_vf_pf_vport_update(p_hwfn, &s_params);
  518. }
  519. static int qed_filter_accept_cmd(struct qed_dev *cdev,
  520. u8 vport,
  521. struct qed_filter_accept_flags accept_flags,
  522. u8 update_accept_any_vlan,
  523. u8 accept_any_vlan,
  524. enum spq_mode comp_mode,
  525. struct qed_spq_comp_cb *p_comp_data)
  526. {
  527. struct qed_sp_vport_update_params vport_update_params;
  528. int i, rc;
  529. /* Prepare and send the vport rx_mode change */
  530. memset(&vport_update_params, 0, sizeof(vport_update_params));
  531. vport_update_params.vport_id = vport;
  532. vport_update_params.accept_flags = accept_flags;
  533. vport_update_params.update_accept_any_vlan_flg = update_accept_any_vlan;
  534. vport_update_params.accept_any_vlan = accept_any_vlan;
  535. for_each_hwfn(cdev, i) {
  536. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  537. vport_update_params.opaque_fid = p_hwfn->hw_info.opaque_fid;
  538. if (IS_VF(cdev)) {
  539. rc = qed_vf_pf_accept_flags(p_hwfn, &accept_flags);
  540. if (rc)
  541. return rc;
  542. continue;
  543. }
  544. rc = qed_sp_vport_update(p_hwfn, &vport_update_params,
  545. comp_mode, p_comp_data);
  546. if (rc) {
  547. DP_ERR(cdev, "Update rx_mode failed %d\n", rc);
  548. return rc;
  549. }
  550. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  551. "Accept filter configured, flags = [Rx]%x [Tx]%x\n",
  552. accept_flags.rx_accept_filter,
  553. accept_flags.tx_accept_filter);
  554. if (update_accept_any_vlan)
  555. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  556. "accept_any_vlan=%d configured\n",
  557. accept_any_vlan);
  558. }
  559. return 0;
  560. }
  561. int qed_eth_rxq_start_ramrod(struct qed_hwfn *p_hwfn,
  562. struct qed_queue_cid *p_cid,
  563. u16 bd_max_bytes,
  564. dma_addr_t bd_chain_phys_addr,
  565. dma_addr_t cqe_pbl_addr, u16 cqe_pbl_size)
  566. {
  567. struct rx_queue_start_ramrod_data *p_ramrod = NULL;
  568. struct qed_spq_entry *p_ent = NULL;
  569. struct qed_sp_init_data init_data;
  570. int rc = -EINVAL;
  571. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  572. "opaque_fid=0x%x, cid=0x%x, rx_qzone=0x%x, vport_id=0x%x, sb_id=0x%x\n",
  573. p_cid->opaque_fid, p_cid->cid,
  574. p_cid->abs.queue_id, p_cid->abs.vport_id, p_cid->abs.sb);
  575. /* Get SPQ entry */
  576. memset(&init_data, 0, sizeof(init_data));
  577. init_data.cid = p_cid->cid;
  578. init_data.opaque_fid = p_cid->opaque_fid;
  579. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  580. rc = qed_sp_init_request(p_hwfn, &p_ent,
  581. ETH_RAMROD_RX_QUEUE_START,
  582. PROTOCOLID_ETH, &init_data);
  583. if (rc)
  584. return rc;
  585. p_ramrod = &p_ent->ramrod.rx_queue_start;
  586. p_ramrod->sb_id = cpu_to_le16(p_cid->abs.sb);
  587. p_ramrod->sb_index = p_cid->abs.sb_idx;
  588. p_ramrod->vport_id = p_cid->abs.vport_id;
  589. p_ramrod->stats_counter_id = p_cid->abs.stats_id;
  590. p_ramrod->rx_queue_id = cpu_to_le16(p_cid->abs.queue_id);
  591. p_ramrod->complete_cqe_flg = 0;
  592. p_ramrod->complete_event_flg = 1;
  593. p_ramrod->bd_max_bytes = cpu_to_le16(bd_max_bytes);
  594. DMA_REGPAIR_LE(p_ramrod->bd_base, bd_chain_phys_addr);
  595. p_ramrod->num_of_pbl_pages = cpu_to_le16(cqe_pbl_size);
  596. DMA_REGPAIR_LE(p_ramrod->cqe_pbl_addr, cqe_pbl_addr);
  597. if (p_cid->is_vf) {
  598. p_ramrod->vf_rx_prod_index = p_cid->vf_qid;
  599. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  600. "Queue%s is meant for VF rxq[%02x]\n",
  601. !!p_cid->b_legacy_vf ? " [legacy]" : "",
  602. p_cid->vf_qid);
  603. p_ramrod->vf_rx_prod_use_zone_a = !!p_cid->b_legacy_vf;
  604. }
  605. return qed_spq_post(p_hwfn, p_ent, NULL);
  606. }
  607. static int
  608. qed_eth_pf_rx_queue_start(struct qed_hwfn *p_hwfn,
  609. struct qed_queue_cid *p_cid,
  610. u16 bd_max_bytes,
  611. dma_addr_t bd_chain_phys_addr,
  612. dma_addr_t cqe_pbl_addr,
  613. u16 cqe_pbl_size, void __iomem **pp_prod)
  614. {
  615. u32 init_prod_val = 0;
  616. *pp_prod = p_hwfn->regview +
  617. GTT_BAR0_MAP_REG_MSDM_RAM +
  618. MSTORM_ETH_PF_PRODS_OFFSET(p_cid->abs.queue_id);
  619. /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
  620. __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
  621. (u32 *)(&init_prod_val));
  622. return qed_eth_rxq_start_ramrod(p_hwfn, p_cid,
  623. bd_max_bytes,
  624. bd_chain_phys_addr,
  625. cqe_pbl_addr, cqe_pbl_size);
  626. }
  627. static int
  628. qed_eth_rx_queue_start(struct qed_hwfn *p_hwfn,
  629. u16 opaque_fid,
  630. struct qed_queue_start_common_params *p_params,
  631. u16 bd_max_bytes,
  632. dma_addr_t bd_chain_phys_addr,
  633. dma_addr_t cqe_pbl_addr,
  634. u16 cqe_pbl_size,
  635. struct qed_rxq_start_ret_params *p_ret_params)
  636. {
  637. struct qed_queue_cid *p_cid;
  638. int rc;
  639. /* Allocate a CID for the queue */
  640. p_cid = qed_eth_queue_to_cid(p_hwfn, opaque_fid, p_params);
  641. if (!p_cid)
  642. return -ENOMEM;
  643. if (IS_PF(p_hwfn->cdev)) {
  644. rc = qed_eth_pf_rx_queue_start(p_hwfn, p_cid,
  645. bd_max_bytes,
  646. bd_chain_phys_addr,
  647. cqe_pbl_addr, cqe_pbl_size,
  648. &p_ret_params->p_prod);
  649. } else {
  650. rc = qed_vf_pf_rxq_start(p_hwfn, p_cid,
  651. bd_max_bytes,
  652. bd_chain_phys_addr,
  653. cqe_pbl_addr,
  654. cqe_pbl_size, &p_ret_params->p_prod);
  655. }
  656. /* Provide the caller with a reference to as handler */
  657. if (rc)
  658. qed_eth_queue_cid_release(p_hwfn, p_cid);
  659. else
  660. p_ret_params->p_handle = (void *)p_cid;
  661. return rc;
  662. }
  663. int qed_sp_eth_rx_queues_update(struct qed_hwfn *p_hwfn,
  664. void **pp_rxq_handles,
  665. u8 num_rxqs,
  666. u8 complete_cqe_flg,
  667. u8 complete_event_flg,
  668. enum spq_mode comp_mode,
  669. struct qed_spq_comp_cb *p_comp_data)
  670. {
  671. struct rx_queue_update_ramrod_data *p_ramrod = NULL;
  672. struct qed_spq_entry *p_ent = NULL;
  673. struct qed_sp_init_data init_data;
  674. struct qed_queue_cid *p_cid;
  675. int rc = -EINVAL;
  676. u8 i;
  677. memset(&init_data, 0, sizeof(init_data));
  678. init_data.comp_mode = comp_mode;
  679. init_data.p_comp_data = p_comp_data;
  680. for (i = 0; i < num_rxqs; i++) {
  681. p_cid = ((struct qed_queue_cid **)pp_rxq_handles)[i];
  682. /* Get SPQ entry */
  683. init_data.cid = p_cid->cid;
  684. init_data.opaque_fid = p_cid->opaque_fid;
  685. rc = qed_sp_init_request(p_hwfn, &p_ent,
  686. ETH_RAMROD_RX_QUEUE_UPDATE,
  687. PROTOCOLID_ETH, &init_data);
  688. if (rc)
  689. return rc;
  690. p_ramrod = &p_ent->ramrod.rx_queue_update;
  691. p_ramrod->vport_id = p_cid->abs.vport_id;
  692. p_ramrod->rx_queue_id = cpu_to_le16(p_cid->abs.queue_id);
  693. p_ramrod->complete_cqe_flg = complete_cqe_flg;
  694. p_ramrod->complete_event_flg = complete_event_flg;
  695. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  696. if (rc)
  697. return rc;
  698. }
  699. return rc;
  700. }
  701. static int
  702. qed_eth_pf_rx_queue_stop(struct qed_hwfn *p_hwfn,
  703. struct qed_queue_cid *p_cid,
  704. bool b_eq_completion_only, bool b_cqe_completion)
  705. {
  706. struct rx_queue_stop_ramrod_data *p_ramrod = NULL;
  707. struct qed_spq_entry *p_ent = NULL;
  708. struct qed_sp_init_data init_data;
  709. int rc;
  710. memset(&init_data, 0, sizeof(init_data));
  711. init_data.cid = p_cid->cid;
  712. init_data.opaque_fid = p_cid->opaque_fid;
  713. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  714. rc = qed_sp_init_request(p_hwfn, &p_ent,
  715. ETH_RAMROD_RX_QUEUE_STOP,
  716. PROTOCOLID_ETH, &init_data);
  717. if (rc)
  718. return rc;
  719. p_ramrod = &p_ent->ramrod.rx_queue_stop;
  720. p_ramrod->vport_id = p_cid->abs.vport_id;
  721. p_ramrod->rx_queue_id = cpu_to_le16(p_cid->abs.queue_id);
  722. /* Cleaning the queue requires the completion to arrive there.
  723. * In addition, VFs require the answer to come as eqe to PF.
  724. */
  725. p_ramrod->complete_cqe_flg = (!p_cid->is_vf &&
  726. !b_eq_completion_only) ||
  727. b_cqe_completion;
  728. p_ramrod->complete_event_flg = p_cid->is_vf || b_eq_completion_only;
  729. return qed_spq_post(p_hwfn, p_ent, NULL);
  730. }
  731. int qed_eth_rx_queue_stop(struct qed_hwfn *p_hwfn,
  732. void *p_rxq,
  733. bool eq_completion_only, bool cqe_completion)
  734. {
  735. struct qed_queue_cid *p_cid = (struct qed_queue_cid *)p_rxq;
  736. int rc = -EINVAL;
  737. if (IS_PF(p_hwfn->cdev))
  738. rc = qed_eth_pf_rx_queue_stop(p_hwfn, p_cid,
  739. eq_completion_only,
  740. cqe_completion);
  741. else
  742. rc = qed_vf_pf_rxq_stop(p_hwfn, p_cid, cqe_completion);
  743. if (!rc)
  744. qed_eth_queue_cid_release(p_hwfn, p_cid);
  745. return rc;
  746. }
  747. int
  748. qed_eth_txq_start_ramrod(struct qed_hwfn *p_hwfn,
  749. struct qed_queue_cid *p_cid,
  750. dma_addr_t pbl_addr, u16 pbl_size, u16 pq_id)
  751. {
  752. struct tx_queue_start_ramrod_data *p_ramrod = NULL;
  753. struct qed_spq_entry *p_ent = NULL;
  754. struct qed_sp_init_data init_data;
  755. int rc = -EINVAL;
  756. /* Get SPQ entry */
  757. memset(&init_data, 0, sizeof(init_data));
  758. init_data.cid = p_cid->cid;
  759. init_data.opaque_fid = p_cid->opaque_fid;
  760. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  761. rc = qed_sp_init_request(p_hwfn, &p_ent,
  762. ETH_RAMROD_TX_QUEUE_START,
  763. PROTOCOLID_ETH, &init_data);
  764. if (rc)
  765. return rc;
  766. p_ramrod = &p_ent->ramrod.tx_queue_start;
  767. p_ramrod->vport_id = p_cid->abs.vport_id;
  768. p_ramrod->sb_id = cpu_to_le16(p_cid->abs.sb);
  769. p_ramrod->sb_index = p_cid->abs.sb_idx;
  770. p_ramrod->stats_counter_id = p_cid->abs.stats_id;
  771. p_ramrod->queue_zone_id = cpu_to_le16(p_cid->abs.queue_id);
  772. p_ramrod->same_as_last_id = cpu_to_le16(p_cid->abs.queue_id);
  773. p_ramrod->pbl_size = cpu_to_le16(pbl_size);
  774. DMA_REGPAIR_LE(p_ramrod->pbl_base_addr, pbl_addr);
  775. p_ramrod->qm_pq_id = cpu_to_le16(pq_id);
  776. return qed_spq_post(p_hwfn, p_ent, NULL);
  777. }
  778. static int
  779. qed_eth_pf_tx_queue_start(struct qed_hwfn *p_hwfn,
  780. struct qed_queue_cid *p_cid,
  781. u8 tc,
  782. dma_addr_t pbl_addr,
  783. u16 pbl_size, void __iomem **pp_doorbell)
  784. {
  785. union qed_qm_pq_params pq_params;
  786. int rc;
  787. memset(&pq_params, 0, sizeof(pq_params));
  788. rc = qed_eth_txq_start_ramrod(p_hwfn, p_cid,
  789. pbl_addr, pbl_size,
  790. qed_get_qm_pq(p_hwfn, PROTOCOLID_ETH,
  791. &pq_params));
  792. if (rc)
  793. return rc;
  794. /* Provide the caller with the necessary return values */
  795. *pp_doorbell = p_hwfn->doorbells +
  796. qed_db_addr(p_cid->cid, DQ_DEMS_LEGACY);
  797. return 0;
  798. }
  799. static int
  800. qed_eth_tx_queue_start(struct qed_hwfn *p_hwfn,
  801. u16 opaque_fid,
  802. struct qed_queue_start_common_params *p_params,
  803. u8 tc,
  804. dma_addr_t pbl_addr,
  805. u16 pbl_size,
  806. struct qed_txq_start_ret_params *p_ret_params)
  807. {
  808. struct qed_queue_cid *p_cid;
  809. int rc;
  810. p_cid = qed_eth_queue_to_cid(p_hwfn, opaque_fid, p_params);
  811. if (!p_cid)
  812. return -EINVAL;
  813. if (IS_PF(p_hwfn->cdev))
  814. rc = qed_eth_pf_tx_queue_start(p_hwfn, p_cid, tc,
  815. pbl_addr, pbl_size,
  816. &p_ret_params->p_doorbell);
  817. else
  818. rc = qed_vf_pf_txq_start(p_hwfn, p_cid,
  819. pbl_addr, pbl_size,
  820. &p_ret_params->p_doorbell);
  821. if (rc)
  822. qed_eth_queue_cid_release(p_hwfn, p_cid);
  823. else
  824. p_ret_params->p_handle = (void *)p_cid;
  825. return rc;
  826. }
  827. static int
  828. qed_eth_pf_tx_queue_stop(struct qed_hwfn *p_hwfn, struct qed_queue_cid *p_cid)
  829. {
  830. struct qed_spq_entry *p_ent = NULL;
  831. struct qed_sp_init_data init_data;
  832. int rc;
  833. memset(&init_data, 0, sizeof(init_data));
  834. init_data.cid = p_cid->cid;
  835. init_data.opaque_fid = p_cid->opaque_fid;
  836. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  837. rc = qed_sp_init_request(p_hwfn, &p_ent,
  838. ETH_RAMROD_TX_QUEUE_STOP,
  839. PROTOCOLID_ETH, &init_data);
  840. if (rc)
  841. return rc;
  842. return qed_spq_post(p_hwfn, p_ent, NULL);
  843. }
  844. int qed_eth_tx_queue_stop(struct qed_hwfn *p_hwfn, void *p_handle)
  845. {
  846. struct qed_queue_cid *p_cid = (struct qed_queue_cid *)p_handle;
  847. int rc;
  848. if (IS_PF(p_hwfn->cdev))
  849. rc = qed_eth_pf_tx_queue_stop(p_hwfn, p_cid);
  850. else
  851. rc = qed_vf_pf_txq_stop(p_hwfn, p_cid);
  852. if (!rc)
  853. qed_eth_queue_cid_release(p_hwfn, p_cid);
  854. return rc;
  855. }
  856. static enum eth_filter_action qed_filter_action(enum qed_filter_opcode opcode)
  857. {
  858. enum eth_filter_action action = MAX_ETH_FILTER_ACTION;
  859. switch (opcode) {
  860. case QED_FILTER_ADD:
  861. action = ETH_FILTER_ACTION_ADD;
  862. break;
  863. case QED_FILTER_REMOVE:
  864. action = ETH_FILTER_ACTION_REMOVE;
  865. break;
  866. case QED_FILTER_FLUSH:
  867. action = ETH_FILTER_ACTION_REMOVE_ALL;
  868. break;
  869. default:
  870. action = MAX_ETH_FILTER_ACTION;
  871. }
  872. return action;
  873. }
  874. static void qed_set_fw_mac_addr(__le16 *fw_msb,
  875. __le16 *fw_mid,
  876. __le16 *fw_lsb,
  877. u8 *mac)
  878. {
  879. ((u8 *)fw_msb)[0] = mac[1];
  880. ((u8 *)fw_msb)[1] = mac[0];
  881. ((u8 *)fw_mid)[0] = mac[3];
  882. ((u8 *)fw_mid)[1] = mac[2];
  883. ((u8 *)fw_lsb)[0] = mac[5];
  884. ((u8 *)fw_lsb)[1] = mac[4];
  885. }
  886. static int
  887. qed_filter_ucast_common(struct qed_hwfn *p_hwfn,
  888. u16 opaque_fid,
  889. struct qed_filter_ucast *p_filter_cmd,
  890. struct vport_filter_update_ramrod_data **pp_ramrod,
  891. struct qed_spq_entry **pp_ent,
  892. enum spq_mode comp_mode,
  893. struct qed_spq_comp_cb *p_comp_data)
  894. {
  895. u8 vport_to_add_to = 0, vport_to_remove_from = 0;
  896. struct vport_filter_update_ramrod_data *p_ramrod;
  897. struct eth_filter_cmd *p_first_filter;
  898. struct eth_filter_cmd *p_second_filter;
  899. struct qed_sp_init_data init_data;
  900. enum eth_filter_action action;
  901. int rc;
  902. rc = qed_fw_vport(p_hwfn, p_filter_cmd->vport_to_remove_from,
  903. &vport_to_remove_from);
  904. if (rc)
  905. return rc;
  906. rc = qed_fw_vport(p_hwfn, p_filter_cmd->vport_to_add_to,
  907. &vport_to_add_to);
  908. if (rc)
  909. return rc;
  910. /* Get SPQ entry */
  911. memset(&init_data, 0, sizeof(init_data));
  912. init_data.cid = qed_spq_get_cid(p_hwfn);
  913. init_data.opaque_fid = opaque_fid;
  914. init_data.comp_mode = comp_mode;
  915. init_data.p_comp_data = p_comp_data;
  916. rc = qed_sp_init_request(p_hwfn, pp_ent,
  917. ETH_RAMROD_FILTERS_UPDATE,
  918. PROTOCOLID_ETH, &init_data);
  919. if (rc)
  920. return rc;
  921. *pp_ramrod = &(*pp_ent)->ramrod.vport_filter_update;
  922. p_ramrod = *pp_ramrod;
  923. p_ramrod->filter_cmd_hdr.rx = p_filter_cmd->is_rx_filter ? 1 : 0;
  924. p_ramrod->filter_cmd_hdr.tx = p_filter_cmd->is_tx_filter ? 1 : 0;
  925. switch (p_filter_cmd->opcode) {
  926. case QED_FILTER_REPLACE:
  927. case QED_FILTER_MOVE:
  928. p_ramrod->filter_cmd_hdr.cmd_cnt = 2; break;
  929. default:
  930. p_ramrod->filter_cmd_hdr.cmd_cnt = 1; break;
  931. }
  932. p_first_filter = &p_ramrod->filter_cmds[0];
  933. p_second_filter = &p_ramrod->filter_cmds[1];
  934. switch (p_filter_cmd->type) {
  935. case QED_FILTER_MAC:
  936. p_first_filter->type = ETH_FILTER_TYPE_MAC; break;
  937. case QED_FILTER_VLAN:
  938. p_first_filter->type = ETH_FILTER_TYPE_VLAN; break;
  939. case QED_FILTER_MAC_VLAN:
  940. p_first_filter->type = ETH_FILTER_TYPE_PAIR; break;
  941. case QED_FILTER_INNER_MAC:
  942. p_first_filter->type = ETH_FILTER_TYPE_INNER_MAC; break;
  943. case QED_FILTER_INNER_VLAN:
  944. p_first_filter->type = ETH_FILTER_TYPE_INNER_VLAN; break;
  945. case QED_FILTER_INNER_PAIR:
  946. p_first_filter->type = ETH_FILTER_TYPE_INNER_PAIR; break;
  947. case QED_FILTER_INNER_MAC_VNI_PAIR:
  948. p_first_filter->type = ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR;
  949. break;
  950. case QED_FILTER_MAC_VNI_PAIR:
  951. p_first_filter->type = ETH_FILTER_TYPE_MAC_VNI_PAIR; break;
  952. case QED_FILTER_VNI:
  953. p_first_filter->type = ETH_FILTER_TYPE_VNI; break;
  954. }
  955. if ((p_first_filter->type == ETH_FILTER_TYPE_MAC) ||
  956. (p_first_filter->type == ETH_FILTER_TYPE_PAIR) ||
  957. (p_first_filter->type == ETH_FILTER_TYPE_INNER_MAC) ||
  958. (p_first_filter->type == ETH_FILTER_TYPE_INNER_PAIR) ||
  959. (p_first_filter->type == ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR) ||
  960. (p_first_filter->type == ETH_FILTER_TYPE_MAC_VNI_PAIR)) {
  961. qed_set_fw_mac_addr(&p_first_filter->mac_msb,
  962. &p_first_filter->mac_mid,
  963. &p_first_filter->mac_lsb,
  964. (u8 *)p_filter_cmd->mac);
  965. }
  966. if ((p_first_filter->type == ETH_FILTER_TYPE_VLAN) ||
  967. (p_first_filter->type == ETH_FILTER_TYPE_PAIR) ||
  968. (p_first_filter->type == ETH_FILTER_TYPE_INNER_VLAN) ||
  969. (p_first_filter->type == ETH_FILTER_TYPE_INNER_PAIR))
  970. p_first_filter->vlan_id = cpu_to_le16(p_filter_cmd->vlan);
  971. if ((p_first_filter->type == ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR) ||
  972. (p_first_filter->type == ETH_FILTER_TYPE_MAC_VNI_PAIR) ||
  973. (p_first_filter->type == ETH_FILTER_TYPE_VNI))
  974. p_first_filter->vni = cpu_to_le32(p_filter_cmd->vni);
  975. if (p_filter_cmd->opcode == QED_FILTER_MOVE) {
  976. p_second_filter->type = p_first_filter->type;
  977. p_second_filter->mac_msb = p_first_filter->mac_msb;
  978. p_second_filter->mac_mid = p_first_filter->mac_mid;
  979. p_second_filter->mac_lsb = p_first_filter->mac_lsb;
  980. p_second_filter->vlan_id = p_first_filter->vlan_id;
  981. p_second_filter->vni = p_first_filter->vni;
  982. p_first_filter->action = ETH_FILTER_ACTION_REMOVE;
  983. p_first_filter->vport_id = vport_to_remove_from;
  984. p_second_filter->action = ETH_FILTER_ACTION_ADD;
  985. p_second_filter->vport_id = vport_to_add_to;
  986. } else if (p_filter_cmd->opcode == QED_FILTER_REPLACE) {
  987. p_first_filter->vport_id = vport_to_add_to;
  988. memcpy(p_second_filter, p_first_filter,
  989. sizeof(*p_second_filter));
  990. p_first_filter->action = ETH_FILTER_ACTION_REMOVE_ALL;
  991. p_second_filter->action = ETH_FILTER_ACTION_ADD;
  992. } else {
  993. action = qed_filter_action(p_filter_cmd->opcode);
  994. if (action == MAX_ETH_FILTER_ACTION) {
  995. DP_NOTICE(p_hwfn,
  996. "%d is not supported yet\n",
  997. p_filter_cmd->opcode);
  998. return -EINVAL;
  999. }
  1000. p_first_filter->action = action;
  1001. p_first_filter->vport_id = (p_filter_cmd->opcode ==
  1002. QED_FILTER_REMOVE) ?
  1003. vport_to_remove_from :
  1004. vport_to_add_to;
  1005. }
  1006. return 0;
  1007. }
  1008. int qed_sp_eth_filter_ucast(struct qed_hwfn *p_hwfn,
  1009. u16 opaque_fid,
  1010. struct qed_filter_ucast *p_filter_cmd,
  1011. enum spq_mode comp_mode,
  1012. struct qed_spq_comp_cb *p_comp_data)
  1013. {
  1014. struct vport_filter_update_ramrod_data *p_ramrod = NULL;
  1015. struct qed_spq_entry *p_ent = NULL;
  1016. struct eth_filter_cmd_header *p_header;
  1017. int rc;
  1018. rc = qed_filter_ucast_common(p_hwfn, opaque_fid, p_filter_cmd,
  1019. &p_ramrod, &p_ent,
  1020. comp_mode, p_comp_data);
  1021. if (rc) {
  1022. DP_ERR(p_hwfn, "Uni. filter command failed %d\n", rc);
  1023. return rc;
  1024. }
  1025. p_header = &p_ramrod->filter_cmd_hdr;
  1026. p_header->assert_on_error = p_filter_cmd->assert_on_error;
  1027. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  1028. if (rc) {
  1029. DP_ERR(p_hwfn, "Unicast filter ADD command failed %d\n", rc);
  1030. return rc;
  1031. }
  1032. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  1033. "Unicast filter configured, opcode = %s, type = %s, cmd_cnt = %d, is_rx_filter = %d, is_tx_filter = %d\n",
  1034. (p_filter_cmd->opcode == QED_FILTER_ADD) ? "ADD" :
  1035. ((p_filter_cmd->opcode == QED_FILTER_REMOVE) ?
  1036. "REMOVE" :
  1037. ((p_filter_cmd->opcode == QED_FILTER_MOVE) ?
  1038. "MOVE" : "REPLACE")),
  1039. (p_filter_cmd->type == QED_FILTER_MAC) ? "MAC" :
  1040. ((p_filter_cmd->type == QED_FILTER_VLAN) ?
  1041. "VLAN" : "MAC & VLAN"),
  1042. p_ramrod->filter_cmd_hdr.cmd_cnt,
  1043. p_filter_cmd->is_rx_filter,
  1044. p_filter_cmd->is_tx_filter);
  1045. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  1046. "vport_to_add_to = %d, vport_to_remove_from = %d, mac = %2x:%2x:%2x:%2x:%2x:%2x, vlan = %d\n",
  1047. p_filter_cmd->vport_to_add_to,
  1048. p_filter_cmd->vport_to_remove_from,
  1049. p_filter_cmd->mac[0],
  1050. p_filter_cmd->mac[1],
  1051. p_filter_cmd->mac[2],
  1052. p_filter_cmd->mac[3],
  1053. p_filter_cmd->mac[4],
  1054. p_filter_cmd->mac[5],
  1055. p_filter_cmd->vlan);
  1056. return 0;
  1057. }
  1058. /*******************************************************************************
  1059. * Description:
  1060. * Calculates crc 32 on a buffer
  1061. * Note: crc32_length MUST be aligned to 8
  1062. * Return:
  1063. ******************************************************************************/
  1064. static u32 qed_calc_crc32c(u8 *crc32_packet,
  1065. u32 crc32_length, u32 crc32_seed, u8 complement)
  1066. {
  1067. u32 byte = 0, bit = 0, crc32_result = crc32_seed;
  1068. u8 msb = 0, current_byte = 0;
  1069. if ((!crc32_packet) ||
  1070. (crc32_length == 0) ||
  1071. ((crc32_length % 8) != 0))
  1072. return crc32_result;
  1073. for (byte = 0; byte < crc32_length; byte++) {
  1074. current_byte = crc32_packet[byte];
  1075. for (bit = 0; bit < 8; bit++) {
  1076. msb = (u8)(crc32_result >> 31);
  1077. crc32_result = crc32_result << 1;
  1078. if (msb != (0x1 & (current_byte >> bit))) {
  1079. crc32_result = crc32_result ^ CRC32_POLY;
  1080. crc32_result |= 1; /*crc32_result[0] = 1;*/
  1081. }
  1082. }
  1083. }
  1084. return crc32_result;
  1085. }
  1086. static u32 qed_crc32c_le(u32 seed, u8 *mac, u32 len)
  1087. {
  1088. u32 packet_buf[2] = { 0 };
  1089. memcpy((u8 *)(&packet_buf[0]), &mac[0], 6);
  1090. return qed_calc_crc32c((u8 *)packet_buf, 8, seed, 0);
  1091. }
  1092. u8 qed_mcast_bin_from_mac(u8 *mac)
  1093. {
  1094. u32 crc = qed_crc32c_le(ETH_MULTICAST_BIN_FROM_MAC_SEED,
  1095. mac, ETH_ALEN);
  1096. return crc & 0xff;
  1097. }
  1098. static int
  1099. qed_sp_eth_filter_mcast(struct qed_hwfn *p_hwfn,
  1100. u16 opaque_fid,
  1101. struct qed_filter_mcast *p_filter_cmd,
  1102. enum spq_mode comp_mode,
  1103. struct qed_spq_comp_cb *p_comp_data)
  1104. {
  1105. unsigned long bins[ETH_MULTICAST_MAC_BINS_IN_REGS];
  1106. struct vport_update_ramrod_data *p_ramrod = NULL;
  1107. struct qed_spq_entry *p_ent = NULL;
  1108. struct qed_sp_init_data init_data;
  1109. u8 abs_vport_id = 0;
  1110. int rc, i;
  1111. if (p_filter_cmd->opcode == QED_FILTER_ADD)
  1112. rc = qed_fw_vport(p_hwfn, p_filter_cmd->vport_to_add_to,
  1113. &abs_vport_id);
  1114. else
  1115. rc = qed_fw_vport(p_hwfn, p_filter_cmd->vport_to_remove_from,
  1116. &abs_vport_id);
  1117. if (rc)
  1118. return rc;
  1119. /* Get SPQ entry */
  1120. memset(&init_data, 0, sizeof(init_data));
  1121. init_data.cid = qed_spq_get_cid(p_hwfn);
  1122. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  1123. init_data.comp_mode = comp_mode;
  1124. init_data.p_comp_data = p_comp_data;
  1125. rc = qed_sp_init_request(p_hwfn, &p_ent,
  1126. ETH_RAMROD_VPORT_UPDATE,
  1127. PROTOCOLID_ETH, &init_data);
  1128. if (rc) {
  1129. DP_ERR(p_hwfn, "Multi-cast command failed %d\n", rc);
  1130. return rc;
  1131. }
  1132. p_ramrod = &p_ent->ramrod.vport_update;
  1133. p_ramrod->common.update_approx_mcast_flg = 1;
  1134. /* explicitly clear out the entire vector */
  1135. memset(&p_ramrod->approx_mcast.bins, 0,
  1136. sizeof(p_ramrod->approx_mcast.bins));
  1137. memset(bins, 0, sizeof(unsigned long) *
  1138. ETH_MULTICAST_MAC_BINS_IN_REGS);
  1139. /* filter ADD op is explicit set op and it removes
  1140. * any existing filters for the vport
  1141. */
  1142. if (p_filter_cmd->opcode == QED_FILTER_ADD) {
  1143. for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) {
  1144. u32 bit;
  1145. bit = qed_mcast_bin_from_mac(p_filter_cmd->mac[i]);
  1146. __set_bit(bit, bins);
  1147. }
  1148. /* Convert to correct endianity */
  1149. for (i = 0; i < ETH_MULTICAST_MAC_BINS_IN_REGS; i++) {
  1150. struct vport_update_ramrod_mcast *p_ramrod_bins;
  1151. u32 *p_bins = (u32 *)bins;
  1152. p_ramrod_bins = &p_ramrod->approx_mcast;
  1153. p_ramrod_bins->bins[i] = cpu_to_le32(p_bins[i]);
  1154. }
  1155. }
  1156. p_ramrod->common.vport_id = abs_vport_id;
  1157. return qed_spq_post(p_hwfn, p_ent, NULL);
  1158. }
  1159. static int qed_filter_mcast_cmd(struct qed_dev *cdev,
  1160. struct qed_filter_mcast *p_filter_cmd,
  1161. enum spq_mode comp_mode,
  1162. struct qed_spq_comp_cb *p_comp_data)
  1163. {
  1164. int rc = 0;
  1165. int i;
  1166. /* only ADD and REMOVE operations are supported for multi-cast */
  1167. if ((p_filter_cmd->opcode != QED_FILTER_ADD &&
  1168. (p_filter_cmd->opcode != QED_FILTER_REMOVE)) ||
  1169. (p_filter_cmd->num_mc_addrs > QED_MAX_MC_ADDRS))
  1170. return -EINVAL;
  1171. for_each_hwfn(cdev, i) {
  1172. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1173. u16 opaque_fid;
  1174. if (IS_VF(cdev)) {
  1175. qed_vf_pf_filter_mcast(p_hwfn, p_filter_cmd);
  1176. continue;
  1177. }
  1178. opaque_fid = p_hwfn->hw_info.opaque_fid;
  1179. rc = qed_sp_eth_filter_mcast(p_hwfn,
  1180. opaque_fid,
  1181. p_filter_cmd,
  1182. comp_mode, p_comp_data);
  1183. }
  1184. return rc;
  1185. }
  1186. static int qed_filter_ucast_cmd(struct qed_dev *cdev,
  1187. struct qed_filter_ucast *p_filter_cmd,
  1188. enum spq_mode comp_mode,
  1189. struct qed_spq_comp_cb *p_comp_data)
  1190. {
  1191. int rc = 0;
  1192. int i;
  1193. for_each_hwfn(cdev, i) {
  1194. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1195. u16 opaque_fid;
  1196. if (IS_VF(cdev)) {
  1197. rc = qed_vf_pf_filter_ucast(p_hwfn, p_filter_cmd);
  1198. continue;
  1199. }
  1200. opaque_fid = p_hwfn->hw_info.opaque_fid;
  1201. rc = qed_sp_eth_filter_ucast(p_hwfn,
  1202. opaque_fid,
  1203. p_filter_cmd,
  1204. comp_mode, p_comp_data);
  1205. if (rc)
  1206. break;
  1207. }
  1208. return rc;
  1209. }
  1210. /* Statistics related code */
  1211. static void __qed_get_vport_pstats_addrlen(struct qed_hwfn *p_hwfn,
  1212. u32 *p_addr,
  1213. u32 *p_len, u16 statistics_bin)
  1214. {
  1215. if (IS_PF(p_hwfn->cdev)) {
  1216. *p_addr = BAR0_MAP_REG_PSDM_RAM +
  1217. PSTORM_QUEUE_STAT_OFFSET(statistics_bin);
  1218. *p_len = sizeof(struct eth_pstorm_per_queue_stat);
  1219. } else {
  1220. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  1221. struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;
  1222. *p_addr = p_resp->pfdev_info.stats_info.pstats.address;
  1223. *p_len = p_resp->pfdev_info.stats_info.pstats.len;
  1224. }
  1225. }
  1226. static void __qed_get_vport_pstats(struct qed_hwfn *p_hwfn,
  1227. struct qed_ptt *p_ptt,
  1228. struct qed_eth_stats *p_stats,
  1229. u16 statistics_bin)
  1230. {
  1231. struct eth_pstorm_per_queue_stat pstats;
  1232. u32 pstats_addr = 0, pstats_len = 0;
  1233. __qed_get_vport_pstats_addrlen(p_hwfn, &pstats_addr, &pstats_len,
  1234. statistics_bin);
  1235. memset(&pstats, 0, sizeof(pstats));
  1236. qed_memcpy_from(p_hwfn, p_ptt, &pstats, pstats_addr, pstats_len);
  1237. p_stats->tx_ucast_bytes += HILO_64_REGPAIR(pstats.sent_ucast_bytes);
  1238. p_stats->tx_mcast_bytes += HILO_64_REGPAIR(pstats.sent_mcast_bytes);
  1239. p_stats->tx_bcast_bytes += HILO_64_REGPAIR(pstats.sent_bcast_bytes);
  1240. p_stats->tx_ucast_pkts += HILO_64_REGPAIR(pstats.sent_ucast_pkts);
  1241. p_stats->tx_mcast_pkts += HILO_64_REGPAIR(pstats.sent_mcast_pkts);
  1242. p_stats->tx_bcast_pkts += HILO_64_REGPAIR(pstats.sent_bcast_pkts);
  1243. p_stats->tx_err_drop_pkts += HILO_64_REGPAIR(pstats.error_drop_pkts);
  1244. }
  1245. static void __qed_get_vport_tstats(struct qed_hwfn *p_hwfn,
  1246. struct qed_ptt *p_ptt,
  1247. struct qed_eth_stats *p_stats,
  1248. u16 statistics_bin)
  1249. {
  1250. struct tstorm_per_port_stat tstats;
  1251. u32 tstats_addr, tstats_len;
  1252. if (IS_PF(p_hwfn->cdev)) {
  1253. tstats_addr = BAR0_MAP_REG_TSDM_RAM +
  1254. TSTORM_PORT_STAT_OFFSET(MFW_PORT(p_hwfn));
  1255. tstats_len = sizeof(struct tstorm_per_port_stat);
  1256. } else {
  1257. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  1258. struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;
  1259. tstats_addr = p_resp->pfdev_info.stats_info.tstats.address;
  1260. tstats_len = p_resp->pfdev_info.stats_info.tstats.len;
  1261. }
  1262. memset(&tstats, 0, sizeof(tstats));
  1263. qed_memcpy_from(p_hwfn, p_ptt, &tstats, tstats_addr, tstats_len);
  1264. p_stats->mftag_filter_discards +=
  1265. HILO_64_REGPAIR(tstats.mftag_filter_discard);
  1266. p_stats->mac_filter_discards +=
  1267. HILO_64_REGPAIR(tstats.eth_mac_filter_discard);
  1268. }
  1269. static void __qed_get_vport_ustats_addrlen(struct qed_hwfn *p_hwfn,
  1270. u32 *p_addr,
  1271. u32 *p_len, u16 statistics_bin)
  1272. {
  1273. if (IS_PF(p_hwfn->cdev)) {
  1274. *p_addr = BAR0_MAP_REG_USDM_RAM +
  1275. USTORM_QUEUE_STAT_OFFSET(statistics_bin);
  1276. *p_len = sizeof(struct eth_ustorm_per_queue_stat);
  1277. } else {
  1278. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  1279. struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;
  1280. *p_addr = p_resp->pfdev_info.stats_info.ustats.address;
  1281. *p_len = p_resp->pfdev_info.stats_info.ustats.len;
  1282. }
  1283. }
  1284. static void __qed_get_vport_ustats(struct qed_hwfn *p_hwfn,
  1285. struct qed_ptt *p_ptt,
  1286. struct qed_eth_stats *p_stats,
  1287. u16 statistics_bin)
  1288. {
  1289. struct eth_ustorm_per_queue_stat ustats;
  1290. u32 ustats_addr = 0, ustats_len = 0;
  1291. __qed_get_vport_ustats_addrlen(p_hwfn, &ustats_addr, &ustats_len,
  1292. statistics_bin);
  1293. memset(&ustats, 0, sizeof(ustats));
  1294. qed_memcpy_from(p_hwfn, p_ptt, &ustats, ustats_addr, ustats_len);
  1295. p_stats->rx_ucast_bytes += HILO_64_REGPAIR(ustats.rcv_ucast_bytes);
  1296. p_stats->rx_mcast_bytes += HILO_64_REGPAIR(ustats.rcv_mcast_bytes);
  1297. p_stats->rx_bcast_bytes += HILO_64_REGPAIR(ustats.rcv_bcast_bytes);
  1298. p_stats->rx_ucast_pkts += HILO_64_REGPAIR(ustats.rcv_ucast_pkts);
  1299. p_stats->rx_mcast_pkts += HILO_64_REGPAIR(ustats.rcv_mcast_pkts);
  1300. p_stats->rx_bcast_pkts += HILO_64_REGPAIR(ustats.rcv_bcast_pkts);
  1301. }
  1302. static void __qed_get_vport_mstats_addrlen(struct qed_hwfn *p_hwfn,
  1303. u32 *p_addr,
  1304. u32 *p_len, u16 statistics_bin)
  1305. {
  1306. if (IS_PF(p_hwfn->cdev)) {
  1307. *p_addr = BAR0_MAP_REG_MSDM_RAM +
  1308. MSTORM_QUEUE_STAT_OFFSET(statistics_bin);
  1309. *p_len = sizeof(struct eth_mstorm_per_queue_stat);
  1310. } else {
  1311. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  1312. struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;
  1313. *p_addr = p_resp->pfdev_info.stats_info.mstats.address;
  1314. *p_len = p_resp->pfdev_info.stats_info.mstats.len;
  1315. }
  1316. }
  1317. static void __qed_get_vport_mstats(struct qed_hwfn *p_hwfn,
  1318. struct qed_ptt *p_ptt,
  1319. struct qed_eth_stats *p_stats,
  1320. u16 statistics_bin)
  1321. {
  1322. struct eth_mstorm_per_queue_stat mstats;
  1323. u32 mstats_addr = 0, mstats_len = 0;
  1324. __qed_get_vport_mstats_addrlen(p_hwfn, &mstats_addr, &mstats_len,
  1325. statistics_bin);
  1326. memset(&mstats, 0, sizeof(mstats));
  1327. qed_memcpy_from(p_hwfn, p_ptt, &mstats, mstats_addr, mstats_len);
  1328. p_stats->no_buff_discards += HILO_64_REGPAIR(mstats.no_buff_discard);
  1329. p_stats->packet_too_big_discard +=
  1330. HILO_64_REGPAIR(mstats.packet_too_big_discard);
  1331. p_stats->ttl0_discard += HILO_64_REGPAIR(mstats.ttl0_discard);
  1332. p_stats->tpa_coalesced_pkts +=
  1333. HILO_64_REGPAIR(mstats.tpa_coalesced_pkts);
  1334. p_stats->tpa_coalesced_events +=
  1335. HILO_64_REGPAIR(mstats.tpa_coalesced_events);
  1336. p_stats->tpa_aborts_num += HILO_64_REGPAIR(mstats.tpa_aborts_num);
  1337. p_stats->tpa_coalesced_bytes +=
  1338. HILO_64_REGPAIR(mstats.tpa_coalesced_bytes);
  1339. }
  1340. static void __qed_get_vport_port_stats(struct qed_hwfn *p_hwfn,
  1341. struct qed_ptt *p_ptt,
  1342. struct qed_eth_stats *p_stats)
  1343. {
  1344. struct port_stats port_stats;
  1345. int j;
  1346. memset(&port_stats, 0, sizeof(port_stats));
  1347. qed_memcpy_from(p_hwfn, p_ptt, &port_stats,
  1348. p_hwfn->mcp_info->port_addr +
  1349. offsetof(struct public_port, stats),
  1350. sizeof(port_stats));
  1351. p_stats->rx_64_byte_packets += port_stats.eth.r64;
  1352. p_stats->rx_65_to_127_byte_packets += port_stats.eth.r127;
  1353. p_stats->rx_128_to_255_byte_packets += port_stats.eth.r255;
  1354. p_stats->rx_256_to_511_byte_packets += port_stats.eth.r511;
  1355. p_stats->rx_512_to_1023_byte_packets += port_stats.eth.r1023;
  1356. p_stats->rx_1024_to_1518_byte_packets += port_stats.eth.r1518;
  1357. p_stats->rx_1519_to_1522_byte_packets += port_stats.eth.r1522;
  1358. p_stats->rx_1519_to_2047_byte_packets += port_stats.eth.r2047;
  1359. p_stats->rx_2048_to_4095_byte_packets += port_stats.eth.r4095;
  1360. p_stats->rx_4096_to_9216_byte_packets += port_stats.eth.r9216;
  1361. p_stats->rx_9217_to_16383_byte_packets += port_stats.eth.r16383;
  1362. p_stats->rx_crc_errors += port_stats.eth.rfcs;
  1363. p_stats->rx_mac_crtl_frames += port_stats.eth.rxcf;
  1364. p_stats->rx_pause_frames += port_stats.eth.rxpf;
  1365. p_stats->rx_pfc_frames += port_stats.eth.rxpp;
  1366. p_stats->rx_align_errors += port_stats.eth.raln;
  1367. p_stats->rx_carrier_errors += port_stats.eth.rfcr;
  1368. p_stats->rx_oversize_packets += port_stats.eth.rovr;
  1369. p_stats->rx_jabbers += port_stats.eth.rjbr;
  1370. p_stats->rx_undersize_packets += port_stats.eth.rund;
  1371. p_stats->rx_fragments += port_stats.eth.rfrg;
  1372. p_stats->tx_64_byte_packets += port_stats.eth.t64;
  1373. p_stats->tx_65_to_127_byte_packets += port_stats.eth.t127;
  1374. p_stats->tx_128_to_255_byte_packets += port_stats.eth.t255;
  1375. p_stats->tx_256_to_511_byte_packets += port_stats.eth.t511;
  1376. p_stats->tx_512_to_1023_byte_packets += port_stats.eth.t1023;
  1377. p_stats->tx_1024_to_1518_byte_packets += port_stats.eth.t1518;
  1378. p_stats->tx_1519_to_2047_byte_packets += port_stats.eth.t2047;
  1379. p_stats->tx_2048_to_4095_byte_packets += port_stats.eth.t4095;
  1380. p_stats->tx_4096_to_9216_byte_packets += port_stats.eth.t9216;
  1381. p_stats->tx_9217_to_16383_byte_packets += port_stats.eth.t16383;
  1382. p_stats->tx_pause_frames += port_stats.eth.txpf;
  1383. p_stats->tx_pfc_frames += port_stats.eth.txpp;
  1384. p_stats->tx_lpi_entry_count += port_stats.eth.tlpiec;
  1385. p_stats->tx_total_collisions += port_stats.eth.tncl;
  1386. p_stats->rx_mac_bytes += port_stats.eth.rbyte;
  1387. p_stats->rx_mac_uc_packets += port_stats.eth.rxuca;
  1388. p_stats->rx_mac_mc_packets += port_stats.eth.rxmca;
  1389. p_stats->rx_mac_bc_packets += port_stats.eth.rxbca;
  1390. p_stats->rx_mac_frames_ok += port_stats.eth.rxpok;
  1391. p_stats->tx_mac_bytes += port_stats.eth.tbyte;
  1392. p_stats->tx_mac_uc_packets += port_stats.eth.txuca;
  1393. p_stats->tx_mac_mc_packets += port_stats.eth.txmca;
  1394. p_stats->tx_mac_bc_packets += port_stats.eth.txbca;
  1395. p_stats->tx_mac_ctrl_frames += port_stats.eth.txcf;
  1396. for (j = 0; j < 8; j++) {
  1397. p_stats->brb_truncates += port_stats.brb.brb_truncate[j];
  1398. p_stats->brb_discards += port_stats.brb.brb_discard[j];
  1399. }
  1400. }
  1401. static void __qed_get_vport_stats(struct qed_hwfn *p_hwfn,
  1402. struct qed_ptt *p_ptt,
  1403. struct qed_eth_stats *stats,
  1404. u16 statistics_bin, bool b_get_port_stats)
  1405. {
  1406. __qed_get_vport_mstats(p_hwfn, p_ptt, stats, statistics_bin);
  1407. __qed_get_vport_ustats(p_hwfn, p_ptt, stats, statistics_bin);
  1408. __qed_get_vport_tstats(p_hwfn, p_ptt, stats, statistics_bin);
  1409. __qed_get_vport_pstats(p_hwfn, p_ptt, stats, statistics_bin);
  1410. if (b_get_port_stats && p_hwfn->mcp_info)
  1411. __qed_get_vport_port_stats(p_hwfn, p_ptt, stats);
  1412. }
  1413. static void _qed_get_vport_stats(struct qed_dev *cdev,
  1414. struct qed_eth_stats *stats)
  1415. {
  1416. u8 fw_vport = 0;
  1417. int i;
  1418. memset(stats, 0, sizeof(*stats));
  1419. for_each_hwfn(cdev, i) {
  1420. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1421. struct qed_ptt *p_ptt = IS_PF(cdev) ? qed_ptt_acquire(p_hwfn)
  1422. : NULL;
  1423. if (IS_PF(cdev)) {
  1424. /* The main vport index is relative first */
  1425. if (qed_fw_vport(p_hwfn, 0, &fw_vport)) {
  1426. DP_ERR(p_hwfn, "No vport available!\n");
  1427. goto out;
  1428. }
  1429. }
  1430. if (IS_PF(cdev) && !p_ptt) {
  1431. DP_ERR(p_hwfn, "Failed to acquire ptt\n");
  1432. continue;
  1433. }
  1434. __qed_get_vport_stats(p_hwfn, p_ptt, stats, fw_vport,
  1435. IS_PF(cdev) ? true : false);
  1436. out:
  1437. if (IS_PF(cdev) && p_ptt)
  1438. qed_ptt_release(p_hwfn, p_ptt);
  1439. }
  1440. }
  1441. void qed_get_vport_stats(struct qed_dev *cdev, struct qed_eth_stats *stats)
  1442. {
  1443. u32 i;
  1444. if (!cdev) {
  1445. memset(stats, 0, sizeof(*stats));
  1446. return;
  1447. }
  1448. _qed_get_vport_stats(cdev, stats);
  1449. if (!cdev->reset_stats)
  1450. return;
  1451. /* Reduce the statistics baseline */
  1452. for (i = 0; i < sizeof(struct qed_eth_stats) / sizeof(u64); i++)
  1453. ((u64 *)stats)[i] -= ((u64 *)cdev->reset_stats)[i];
  1454. }
  1455. /* zeroes V-PORT specific portion of stats (Port stats remains untouched) */
  1456. void qed_reset_vport_stats(struct qed_dev *cdev)
  1457. {
  1458. int i;
  1459. for_each_hwfn(cdev, i) {
  1460. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1461. struct eth_mstorm_per_queue_stat mstats;
  1462. struct eth_ustorm_per_queue_stat ustats;
  1463. struct eth_pstorm_per_queue_stat pstats;
  1464. struct qed_ptt *p_ptt = IS_PF(cdev) ? qed_ptt_acquire(p_hwfn)
  1465. : NULL;
  1466. u32 addr = 0, len = 0;
  1467. if (IS_PF(cdev) && !p_ptt) {
  1468. DP_ERR(p_hwfn, "Failed to acquire ptt\n");
  1469. continue;
  1470. }
  1471. memset(&mstats, 0, sizeof(mstats));
  1472. __qed_get_vport_mstats_addrlen(p_hwfn, &addr, &len, 0);
  1473. qed_memcpy_to(p_hwfn, p_ptt, addr, &mstats, len);
  1474. memset(&ustats, 0, sizeof(ustats));
  1475. __qed_get_vport_ustats_addrlen(p_hwfn, &addr, &len, 0);
  1476. qed_memcpy_to(p_hwfn, p_ptt, addr, &ustats, len);
  1477. memset(&pstats, 0, sizeof(pstats));
  1478. __qed_get_vport_pstats_addrlen(p_hwfn, &addr, &len, 0);
  1479. qed_memcpy_to(p_hwfn, p_ptt, addr, &pstats, len);
  1480. if (IS_PF(cdev))
  1481. qed_ptt_release(p_hwfn, p_ptt);
  1482. }
  1483. /* PORT statistics are not necessarily reset, so we need to
  1484. * read and create a baseline for future statistics.
  1485. */
  1486. if (!cdev->reset_stats)
  1487. DP_INFO(cdev, "Reset stats not allocated\n");
  1488. else
  1489. _qed_get_vport_stats(cdev, cdev->reset_stats);
  1490. }
  1491. static int qed_fill_eth_dev_info(struct qed_dev *cdev,
  1492. struct qed_dev_eth_info *info)
  1493. {
  1494. int i;
  1495. memset(info, 0, sizeof(*info));
  1496. info->num_tc = 1;
  1497. if (IS_PF(cdev)) {
  1498. int max_vf_vlan_filters = 0;
  1499. int max_vf_mac_filters = 0;
  1500. if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
  1501. u16 num_queues = 0;
  1502. /* Since the feature controls only queue-zones,
  1503. * make sure we have the contexts [rx, tx, xdp] to
  1504. * match.
  1505. */
  1506. for_each_hwfn(cdev, i) {
  1507. struct qed_hwfn *hwfn = &cdev->hwfns[i];
  1508. u16 l2_queues = (u16)FEAT_NUM(hwfn,
  1509. QED_PF_L2_QUE);
  1510. u16 cids;
  1511. cids = hwfn->pf_params.eth_pf_params.num_cons;
  1512. num_queues += min_t(u16, l2_queues, cids / 3);
  1513. }
  1514. /* queues might theoretically be >256, but interrupts'
  1515. * upper-limit guarantes that it would fit in a u8.
  1516. */
  1517. if (cdev->int_params.fp_msix_cnt) {
  1518. u8 irqs = cdev->int_params.fp_msix_cnt;
  1519. info->num_queues = (u8)min_t(u16,
  1520. num_queues, irqs);
  1521. }
  1522. } else {
  1523. info->num_queues = cdev->num_hwfns;
  1524. }
  1525. if (IS_QED_SRIOV(cdev)) {
  1526. max_vf_vlan_filters = cdev->p_iov_info->total_vfs *
  1527. QED_ETH_VF_NUM_VLAN_FILTERS;
  1528. max_vf_mac_filters = cdev->p_iov_info->total_vfs *
  1529. QED_ETH_VF_NUM_MAC_FILTERS;
  1530. }
  1531. info->num_vlan_filters = RESC_NUM(QED_LEADING_HWFN(cdev),
  1532. QED_VLAN) -
  1533. max_vf_vlan_filters;
  1534. info->num_mac_filters = RESC_NUM(QED_LEADING_HWFN(cdev),
  1535. QED_MAC) -
  1536. max_vf_mac_filters;
  1537. ether_addr_copy(info->port_mac,
  1538. cdev->hwfns[0].hw_info.hw_mac_addr);
  1539. } else {
  1540. qed_vf_get_num_rxqs(QED_LEADING_HWFN(cdev), &info->num_queues);
  1541. if (cdev->num_hwfns > 1) {
  1542. u8 queues = 0;
  1543. qed_vf_get_num_rxqs(&cdev->hwfns[1], &queues);
  1544. info->num_queues += queues;
  1545. }
  1546. qed_vf_get_num_vlan_filters(&cdev->hwfns[0],
  1547. (u8 *)&info->num_vlan_filters);
  1548. qed_vf_get_num_mac_filters(&cdev->hwfns[0],
  1549. (u8 *)&info->num_mac_filters);
  1550. qed_vf_get_port_mac(&cdev->hwfns[0], info->port_mac);
  1551. info->is_legacy = !!cdev->hwfns[0].vf_iov_info->b_pre_fp_hsi;
  1552. }
  1553. qed_fill_dev_info(cdev, &info->common);
  1554. if (IS_VF(cdev))
  1555. eth_zero_addr(info->common.hw_mac);
  1556. return 0;
  1557. }
  1558. static void qed_register_eth_ops(struct qed_dev *cdev,
  1559. struct qed_eth_cb_ops *ops, void *cookie)
  1560. {
  1561. cdev->protocol_ops.eth = ops;
  1562. cdev->ops_cookie = cookie;
  1563. /* For VF, we start bulletin reading */
  1564. if (IS_VF(cdev))
  1565. qed_vf_start_iov_wq(cdev);
  1566. }
  1567. static bool qed_check_mac(struct qed_dev *cdev, u8 *mac)
  1568. {
  1569. if (IS_PF(cdev))
  1570. return true;
  1571. return qed_vf_check_mac(&cdev->hwfns[0], mac);
  1572. }
  1573. static int qed_start_vport(struct qed_dev *cdev,
  1574. struct qed_start_vport_params *params)
  1575. {
  1576. int rc, i;
  1577. for_each_hwfn(cdev, i) {
  1578. struct qed_sp_vport_start_params start = { 0 };
  1579. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1580. start.tpa_mode = params->gro_enable ? QED_TPA_MODE_GRO :
  1581. QED_TPA_MODE_NONE;
  1582. start.remove_inner_vlan = params->remove_inner_vlan;
  1583. start.only_untagged = true; /* untagged only */
  1584. start.drop_ttl0 = params->drop_ttl0;
  1585. start.opaque_fid = p_hwfn->hw_info.opaque_fid;
  1586. start.concrete_fid = p_hwfn->hw_info.concrete_fid;
  1587. start.handle_ptp_pkts = params->handle_ptp_pkts;
  1588. start.vport_id = params->vport_id;
  1589. start.max_buffers_per_cqe = 16;
  1590. start.mtu = params->mtu;
  1591. rc = qed_sp_vport_start(p_hwfn, &start);
  1592. if (rc) {
  1593. DP_ERR(cdev, "Failed to start VPORT\n");
  1594. return rc;
  1595. }
  1596. qed_hw_start_fastpath(p_hwfn);
  1597. DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
  1598. "Started V-PORT %d with MTU %d\n",
  1599. start.vport_id, start.mtu);
  1600. }
  1601. if (params->clear_stats)
  1602. qed_reset_vport_stats(cdev);
  1603. return 0;
  1604. }
  1605. static int qed_stop_vport(struct qed_dev *cdev, u8 vport_id)
  1606. {
  1607. int rc, i;
  1608. for_each_hwfn(cdev, i) {
  1609. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1610. rc = qed_sp_vport_stop(p_hwfn,
  1611. p_hwfn->hw_info.opaque_fid, vport_id);
  1612. if (rc) {
  1613. DP_ERR(cdev, "Failed to stop VPORT\n");
  1614. return rc;
  1615. }
  1616. }
  1617. return 0;
  1618. }
  1619. static int qed_update_vport_rss(struct qed_dev *cdev,
  1620. struct qed_update_vport_rss_params *input,
  1621. struct qed_rss_params *rss)
  1622. {
  1623. int i, fn;
  1624. /* Update configuration with what's correct regardless of CMT */
  1625. rss->update_rss_config = 1;
  1626. rss->rss_enable = 1;
  1627. rss->update_rss_capabilities = 1;
  1628. rss->update_rss_ind_table = 1;
  1629. rss->update_rss_key = 1;
  1630. rss->rss_caps = input->rss_caps;
  1631. memcpy(rss->rss_key, input->rss_key, QED_RSS_KEY_SIZE * sizeof(u32));
  1632. /* In regular scenario, we'd simply need to take input handlers.
  1633. * But in CMT, we'd have to split the handlers according to the
  1634. * engine they were configured on. We'd then have to understand
  1635. * whether RSS is really required, since 2-queues on CMT doesn't
  1636. * require RSS.
  1637. */
  1638. if (cdev->num_hwfns == 1) {
  1639. memcpy(rss->rss_ind_table,
  1640. input->rss_ind_table,
  1641. QED_RSS_IND_TABLE_SIZE * sizeof(void *));
  1642. rss->rss_table_size_log = 7;
  1643. return 0;
  1644. }
  1645. /* Start by copying the non-spcific information to the 2nd copy */
  1646. memcpy(&rss[1], &rss[0], sizeof(struct qed_rss_params));
  1647. /* CMT should be round-robin */
  1648. for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++) {
  1649. struct qed_queue_cid *cid = input->rss_ind_table[i];
  1650. struct qed_rss_params *t_rss;
  1651. if (cid->p_owner == QED_LEADING_HWFN(cdev))
  1652. t_rss = &rss[0];
  1653. else
  1654. t_rss = &rss[1];
  1655. t_rss->rss_ind_table[i / cdev->num_hwfns] = cid;
  1656. }
  1657. /* Make sure RSS is actually required */
  1658. for_each_hwfn(cdev, fn) {
  1659. for (i = 1; i < QED_RSS_IND_TABLE_SIZE / cdev->num_hwfns; i++) {
  1660. if (rss[fn].rss_ind_table[i] !=
  1661. rss[fn].rss_ind_table[0])
  1662. break;
  1663. }
  1664. if (i == QED_RSS_IND_TABLE_SIZE / cdev->num_hwfns) {
  1665. DP_VERBOSE(cdev, NETIF_MSG_IFUP,
  1666. "CMT - 1 queue per-hwfn; Disabling RSS\n");
  1667. return -EINVAL;
  1668. }
  1669. rss[fn].rss_table_size_log = 6;
  1670. }
  1671. return 0;
  1672. }
  1673. static int qed_update_vport(struct qed_dev *cdev,
  1674. struct qed_update_vport_params *params)
  1675. {
  1676. struct qed_sp_vport_update_params sp_params;
  1677. struct qed_rss_params *rss;
  1678. int rc = 0, i;
  1679. if (!cdev)
  1680. return -ENODEV;
  1681. rss = vzalloc(sizeof(*rss) * cdev->num_hwfns);
  1682. if (!rss)
  1683. return -ENOMEM;
  1684. memset(&sp_params, 0, sizeof(sp_params));
  1685. /* Translate protocol params into sp params */
  1686. sp_params.vport_id = params->vport_id;
  1687. sp_params.update_vport_active_rx_flg = params->update_vport_active_flg;
  1688. sp_params.update_vport_active_tx_flg = params->update_vport_active_flg;
  1689. sp_params.vport_active_rx_flg = params->vport_active_flg;
  1690. sp_params.vport_active_tx_flg = params->vport_active_flg;
  1691. sp_params.update_tx_switching_flg = params->update_tx_switching_flg;
  1692. sp_params.tx_switching_flg = params->tx_switching_flg;
  1693. sp_params.accept_any_vlan = params->accept_any_vlan;
  1694. sp_params.update_accept_any_vlan_flg =
  1695. params->update_accept_any_vlan_flg;
  1696. /* Prepare the RSS configuration */
  1697. if (params->update_rss_flg)
  1698. if (qed_update_vport_rss(cdev, &params->rss_params, rss))
  1699. params->update_rss_flg = 0;
  1700. for_each_hwfn(cdev, i) {
  1701. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1702. if (params->update_rss_flg)
  1703. sp_params.rss_params = &rss[i];
  1704. sp_params.opaque_fid = p_hwfn->hw_info.opaque_fid;
  1705. rc = qed_sp_vport_update(p_hwfn, &sp_params,
  1706. QED_SPQ_MODE_EBLOCK,
  1707. NULL);
  1708. if (rc) {
  1709. DP_ERR(cdev, "Failed to update VPORT\n");
  1710. goto out;
  1711. }
  1712. DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
  1713. "Updated V-PORT %d: active_flag %d [update %d]\n",
  1714. params->vport_id, params->vport_active_flg,
  1715. params->update_vport_active_flg);
  1716. }
  1717. out:
  1718. vfree(rss);
  1719. return rc;
  1720. }
  1721. static int qed_start_rxq(struct qed_dev *cdev,
  1722. u8 rss_num,
  1723. struct qed_queue_start_common_params *p_params,
  1724. u16 bd_max_bytes,
  1725. dma_addr_t bd_chain_phys_addr,
  1726. dma_addr_t cqe_pbl_addr,
  1727. u16 cqe_pbl_size,
  1728. struct qed_rxq_start_ret_params *ret_params)
  1729. {
  1730. struct qed_hwfn *p_hwfn;
  1731. int rc, hwfn_index;
  1732. hwfn_index = rss_num % cdev->num_hwfns;
  1733. p_hwfn = &cdev->hwfns[hwfn_index];
  1734. p_params->queue_id = p_params->queue_id / cdev->num_hwfns;
  1735. p_params->stats_id = p_params->vport_id;
  1736. rc = qed_eth_rx_queue_start(p_hwfn,
  1737. p_hwfn->hw_info.opaque_fid,
  1738. p_params,
  1739. bd_max_bytes,
  1740. bd_chain_phys_addr,
  1741. cqe_pbl_addr, cqe_pbl_size, ret_params);
  1742. if (rc) {
  1743. DP_ERR(cdev, "Failed to start RXQ#%d\n", p_params->queue_id);
  1744. return rc;
  1745. }
  1746. DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
  1747. "Started RX-Q %d [rss_num %d] on V-PORT %d and SB %d\n",
  1748. p_params->queue_id, rss_num, p_params->vport_id,
  1749. p_params->sb);
  1750. return 0;
  1751. }
  1752. static int qed_stop_rxq(struct qed_dev *cdev, u8 rss_id, void *handle)
  1753. {
  1754. int rc, hwfn_index;
  1755. struct qed_hwfn *p_hwfn;
  1756. hwfn_index = rss_id % cdev->num_hwfns;
  1757. p_hwfn = &cdev->hwfns[hwfn_index];
  1758. rc = qed_eth_rx_queue_stop(p_hwfn, handle, false, false);
  1759. if (rc) {
  1760. DP_ERR(cdev, "Failed to stop RXQ#%02x\n", rss_id);
  1761. return rc;
  1762. }
  1763. return 0;
  1764. }
  1765. static int qed_start_txq(struct qed_dev *cdev,
  1766. u8 rss_num,
  1767. struct qed_queue_start_common_params *p_params,
  1768. dma_addr_t pbl_addr,
  1769. u16 pbl_size,
  1770. struct qed_txq_start_ret_params *ret_params)
  1771. {
  1772. struct qed_hwfn *p_hwfn;
  1773. int rc, hwfn_index;
  1774. hwfn_index = rss_num % cdev->num_hwfns;
  1775. p_hwfn = &cdev->hwfns[hwfn_index];
  1776. p_params->queue_id = p_params->queue_id / cdev->num_hwfns;
  1777. p_params->stats_id = p_params->vport_id;
  1778. rc = qed_eth_tx_queue_start(p_hwfn,
  1779. p_hwfn->hw_info.opaque_fid,
  1780. p_params, 0,
  1781. pbl_addr, pbl_size, ret_params);
  1782. if (rc) {
  1783. DP_ERR(cdev, "Failed to start TXQ#%d\n", p_params->queue_id);
  1784. return rc;
  1785. }
  1786. DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
  1787. "Started TX-Q %d [rss_num %d] on V-PORT %d and SB %d\n",
  1788. p_params->queue_id, rss_num, p_params->vport_id,
  1789. p_params->sb);
  1790. return 0;
  1791. }
  1792. #define QED_HW_STOP_RETRY_LIMIT (10)
  1793. static int qed_fastpath_stop(struct qed_dev *cdev)
  1794. {
  1795. qed_hw_stop_fastpath(cdev);
  1796. return 0;
  1797. }
  1798. static int qed_stop_txq(struct qed_dev *cdev, u8 rss_id, void *handle)
  1799. {
  1800. struct qed_hwfn *p_hwfn;
  1801. int rc, hwfn_index;
  1802. hwfn_index = rss_id % cdev->num_hwfns;
  1803. p_hwfn = &cdev->hwfns[hwfn_index];
  1804. rc = qed_eth_tx_queue_stop(p_hwfn, handle);
  1805. if (rc) {
  1806. DP_ERR(cdev, "Failed to stop TXQ#%02x\n", rss_id);
  1807. return rc;
  1808. }
  1809. return 0;
  1810. }
  1811. static int qed_tunn_configure(struct qed_dev *cdev,
  1812. struct qed_tunn_params *tunn_params)
  1813. {
  1814. struct qed_tunn_update_params tunn_info;
  1815. int i, rc;
  1816. if (IS_VF(cdev))
  1817. return 0;
  1818. memset(&tunn_info, 0, sizeof(tunn_info));
  1819. if (tunn_params->update_vxlan_port == 1) {
  1820. tunn_info.update_vxlan_udp_port = 1;
  1821. tunn_info.vxlan_udp_port = tunn_params->vxlan_port;
  1822. }
  1823. if (tunn_params->update_geneve_port == 1) {
  1824. tunn_info.update_geneve_udp_port = 1;
  1825. tunn_info.geneve_udp_port = tunn_params->geneve_port;
  1826. }
  1827. for_each_hwfn(cdev, i) {
  1828. struct qed_hwfn *hwfn = &cdev->hwfns[i];
  1829. rc = qed_sp_pf_update_tunn_cfg(hwfn, &tunn_info,
  1830. QED_SPQ_MODE_EBLOCK, NULL);
  1831. if (rc)
  1832. return rc;
  1833. }
  1834. return 0;
  1835. }
  1836. static int qed_configure_filter_rx_mode(struct qed_dev *cdev,
  1837. enum qed_filter_rx_mode_type type)
  1838. {
  1839. struct qed_filter_accept_flags accept_flags;
  1840. memset(&accept_flags, 0, sizeof(accept_flags));
  1841. accept_flags.update_rx_mode_config = 1;
  1842. accept_flags.update_tx_mode_config = 1;
  1843. accept_flags.rx_accept_filter = QED_ACCEPT_UCAST_MATCHED |
  1844. QED_ACCEPT_MCAST_MATCHED |
  1845. QED_ACCEPT_BCAST;
  1846. accept_flags.tx_accept_filter = QED_ACCEPT_UCAST_MATCHED |
  1847. QED_ACCEPT_MCAST_MATCHED |
  1848. QED_ACCEPT_BCAST;
  1849. if (type == QED_FILTER_RX_MODE_TYPE_PROMISC) {
  1850. accept_flags.rx_accept_filter |= QED_ACCEPT_UCAST_UNMATCHED |
  1851. QED_ACCEPT_MCAST_UNMATCHED;
  1852. accept_flags.tx_accept_filter |= QED_ACCEPT_MCAST_UNMATCHED;
  1853. } else if (type == QED_FILTER_RX_MODE_TYPE_MULTI_PROMISC) {
  1854. accept_flags.rx_accept_filter |= QED_ACCEPT_MCAST_UNMATCHED;
  1855. accept_flags.tx_accept_filter |= QED_ACCEPT_MCAST_UNMATCHED;
  1856. }
  1857. return qed_filter_accept_cmd(cdev, 0, accept_flags, false, false,
  1858. QED_SPQ_MODE_CB, NULL);
  1859. }
  1860. static int qed_configure_filter_ucast(struct qed_dev *cdev,
  1861. struct qed_filter_ucast_params *params)
  1862. {
  1863. struct qed_filter_ucast ucast;
  1864. if (!params->vlan_valid && !params->mac_valid) {
  1865. DP_NOTICE(cdev,
  1866. "Tried configuring a unicast filter, but both MAC and VLAN are not set\n");
  1867. return -EINVAL;
  1868. }
  1869. memset(&ucast, 0, sizeof(ucast));
  1870. switch (params->type) {
  1871. case QED_FILTER_XCAST_TYPE_ADD:
  1872. ucast.opcode = QED_FILTER_ADD;
  1873. break;
  1874. case QED_FILTER_XCAST_TYPE_DEL:
  1875. ucast.opcode = QED_FILTER_REMOVE;
  1876. break;
  1877. case QED_FILTER_XCAST_TYPE_REPLACE:
  1878. ucast.opcode = QED_FILTER_REPLACE;
  1879. break;
  1880. default:
  1881. DP_NOTICE(cdev, "Unknown unicast filter type %d\n",
  1882. params->type);
  1883. }
  1884. if (params->vlan_valid && params->mac_valid) {
  1885. ucast.type = QED_FILTER_MAC_VLAN;
  1886. ether_addr_copy(ucast.mac, params->mac);
  1887. ucast.vlan = params->vlan;
  1888. } else if (params->mac_valid) {
  1889. ucast.type = QED_FILTER_MAC;
  1890. ether_addr_copy(ucast.mac, params->mac);
  1891. } else {
  1892. ucast.type = QED_FILTER_VLAN;
  1893. ucast.vlan = params->vlan;
  1894. }
  1895. ucast.is_rx_filter = true;
  1896. ucast.is_tx_filter = true;
  1897. return qed_filter_ucast_cmd(cdev, &ucast, QED_SPQ_MODE_CB, NULL);
  1898. }
  1899. static int qed_configure_filter_mcast(struct qed_dev *cdev,
  1900. struct qed_filter_mcast_params *params)
  1901. {
  1902. struct qed_filter_mcast mcast;
  1903. int i;
  1904. memset(&mcast, 0, sizeof(mcast));
  1905. switch (params->type) {
  1906. case QED_FILTER_XCAST_TYPE_ADD:
  1907. mcast.opcode = QED_FILTER_ADD;
  1908. break;
  1909. case QED_FILTER_XCAST_TYPE_DEL:
  1910. mcast.opcode = QED_FILTER_REMOVE;
  1911. break;
  1912. default:
  1913. DP_NOTICE(cdev, "Unknown multicast filter type %d\n",
  1914. params->type);
  1915. }
  1916. mcast.num_mc_addrs = params->num;
  1917. for (i = 0; i < mcast.num_mc_addrs; i++)
  1918. ether_addr_copy(mcast.mac[i], params->mac[i]);
  1919. return qed_filter_mcast_cmd(cdev, &mcast, QED_SPQ_MODE_CB, NULL);
  1920. }
  1921. static int qed_configure_filter(struct qed_dev *cdev,
  1922. struct qed_filter_params *params)
  1923. {
  1924. enum qed_filter_rx_mode_type accept_flags;
  1925. switch (params->type) {
  1926. case QED_FILTER_TYPE_UCAST:
  1927. return qed_configure_filter_ucast(cdev, &params->filter.ucast);
  1928. case QED_FILTER_TYPE_MCAST:
  1929. return qed_configure_filter_mcast(cdev, &params->filter.mcast);
  1930. case QED_FILTER_TYPE_RX_MODE:
  1931. accept_flags = params->filter.accept_flags;
  1932. return qed_configure_filter_rx_mode(cdev, accept_flags);
  1933. default:
  1934. DP_NOTICE(cdev, "Unknown filter type %d\n", (int)params->type);
  1935. return -EINVAL;
  1936. }
  1937. }
  1938. static int qed_fp_cqe_completion(struct qed_dev *dev,
  1939. u8 rss_id, struct eth_slow_path_rx_cqe *cqe)
  1940. {
  1941. return qed_eth_cqe_completion(&dev->hwfns[rss_id % dev->num_hwfns],
  1942. cqe);
  1943. }
  1944. #ifdef CONFIG_QED_SRIOV
  1945. extern const struct qed_iov_hv_ops qed_iov_ops_pass;
  1946. #endif
  1947. #ifdef CONFIG_DCB
  1948. extern const struct qed_eth_dcbnl_ops qed_dcbnl_ops_pass;
  1949. #endif
  1950. extern const struct qed_eth_ptp_ops qed_ptp_ops_pass;
  1951. static const struct qed_eth_ops qed_eth_ops_pass = {
  1952. .common = &qed_common_ops_pass,
  1953. #ifdef CONFIG_QED_SRIOV
  1954. .iov = &qed_iov_ops_pass,
  1955. #endif
  1956. #ifdef CONFIG_DCB
  1957. .dcb = &qed_dcbnl_ops_pass,
  1958. #endif
  1959. .ptp = &qed_ptp_ops_pass,
  1960. .fill_dev_info = &qed_fill_eth_dev_info,
  1961. .register_ops = &qed_register_eth_ops,
  1962. .check_mac = &qed_check_mac,
  1963. .vport_start = &qed_start_vport,
  1964. .vport_stop = &qed_stop_vport,
  1965. .vport_update = &qed_update_vport,
  1966. .q_rx_start = &qed_start_rxq,
  1967. .q_rx_stop = &qed_stop_rxq,
  1968. .q_tx_start = &qed_start_txq,
  1969. .q_tx_stop = &qed_stop_txq,
  1970. .filter_config = &qed_configure_filter,
  1971. .fastpath_stop = &qed_fastpath_stop,
  1972. .eth_cqe_completion = &qed_fp_cqe_completion,
  1973. .get_vport_stats = &qed_get_vport_stats,
  1974. .tunn_config = &qed_tunn_configure,
  1975. };
  1976. const struct qed_eth_ops *qed_get_eth_ops(void)
  1977. {
  1978. return &qed_eth_ops_pass;
  1979. }
  1980. EXPORT_SYMBOL(qed_get_eth_ops);
  1981. void qed_put_eth_ops(void)
  1982. {
  1983. /* TODO - reference count for module? */
  1984. }
  1985. EXPORT_SYMBOL(qed_put_eth_ops);