qed_l2.c 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902
  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/workqueue.h>
  46. #include <linux/bitops.h>
  47. #include <linux/bug.h>
  48. #include <linux/vmalloc.h>
  49. #include "qed.h"
  50. #include <linux/qed/qed_chain.h>
  51. #include "qed_cxt.h"
  52. #include "qed_dev_api.h"
  53. #include <linux/qed/qed_eth_if.h>
  54. #include "qed_hsi.h"
  55. #include "qed_hw.h"
  56. #include "qed_int.h"
  57. #include "qed_l2.h"
  58. #include "qed_mcp.h"
  59. #include "qed_reg_addr.h"
  60. #include "qed_sp.h"
  61. #include "qed_sriov.h"
  62. #define QED_MAX_SGES_NUM 16
  63. #define CRC32_POLY 0x1edc6f41
  64. struct qed_l2_info {
  65. u32 queues;
  66. unsigned long **pp_qid_usage;
  67. /* The lock is meant to synchronize access to the qid usage */
  68. struct mutex lock;
  69. };
  70. int qed_l2_alloc(struct qed_hwfn *p_hwfn)
  71. {
  72. struct qed_l2_info *p_l2_info;
  73. unsigned long **pp_qids;
  74. u32 i;
  75. if (!QED_IS_L2_PERSONALITY(p_hwfn))
  76. return 0;
  77. p_l2_info = kzalloc(sizeof(*p_l2_info), GFP_KERNEL);
  78. if (!p_l2_info)
  79. return -ENOMEM;
  80. p_hwfn->p_l2_info = p_l2_info;
  81. if (IS_PF(p_hwfn->cdev)) {
  82. p_l2_info->queues = RESC_NUM(p_hwfn, QED_L2_QUEUE);
  83. } else {
  84. u8 rx = 0, tx = 0;
  85. qed_vf_get_num_rxqs(p_hwfn, &rx);
  86. qed_vf_get_num_txqs(p_hwfn, &tx);
  87. p_l2_info->queues = max_t(u8, rx, tx);
  88. }
  89. pp_qids = kzalloc(sizeof(unsigned long *) * p_l2_info->queues,
  90. GFP_KERNEL);
  91. if (!pp_qids)
  92. return -ENOMEM;
  93. p_l2_info->pp_qid_usage = pp_qids;
  94. for (i = 0; i < p_l2_info->queues; i++) {
  95. pp_qids[i] = kzalloc(MAX_QUEUES_PER_QZONE / 8, GFP_KERNEL);
  96. if (!pp_qids[i])
  97. return -ENOMEM;
  98. }
  99. return 0;
  100. }
  101. void qed_l2_setup(struct qed_hwfn *p_hwfn)
  102. {
  103. if (p_hwfn->hw_info.personality != QED_PCI_ETH &&
  104. p_hwfn->hw_info.personality != QED_PCI_ETH_ROCE)
  105. return;
  106. mutex_init(&p_hwfn->p_l2_info->lock);
  107. }
  108. void qed_l2_free(struct qed_hwfn *p_hwfn)
  109. {
  110. u32 i;
  111. if (p_hwfn->hw_info.personality != QED_PCI_ETH &&
  112. p_hwfn->hw_info.personality != QED_PCI_ETH_ROCE)
  113. return;
  114. if (!p_hwfn->p_l2_info)
  115. return;
  116. if (!p_hwfn->p_l2_info->pp_qid_usage)
  117. goto out_l2_info;
  118. /* Free until hit first uninitialized entry */
  119. for (i = 0; i < p_hwfn->p_l2_info->queues; i++) {
  120. if (!p_hwfn->p_l2_info->pp_qid_usage[i])
  121. break;
  122. kfree(p_hwfn->p_l2_info->pp_qid_usage[i]);
  123. }
  124. kfree(p_hwfn->p_l2_info->pp_qid_usage);
  125. out_l2_info:
  126. kfree(p_hwfn->p_l2_info);
  127. p_hwfn->p_l2_info = NULL;
  128. }
  129. static bool qed_eth_queue_qid_usage_add(struct qed_hwfn *p_hwfn,
  130. struct qed_queue_cid *p_cid)
  131. {
  132. struct qed_l2_info *p_l2_info = p_hwfn->p_l2_info;
  133. u16 queue_id = p_cid->rel.queue_id;
  134. bool b_rc = true;
  135. u8 first;
  136. mutex_lock(&p_l2_info->lock);
  137. if (queue_id >= p_l2_info->queues) {
  138. DP_NOTICE(p_hwfn,
  139. "Requested to increase usage for qzone %04x out of %08x\n",
  140. queue_id, p_l2_info->queues);
  141. b_rc = false;
  142. goto out;
  143. }
  144. first = (u8)find_first_zero_bit(p_l2_info->pp_qid_usage[queue_id],
  145. MAX_QUEUES_PER_QZONE);
  146. if (first >= MAX_QUEUES_PER_QZONE) {
  147. b_rc = false;
  148. goto out;
  149. }
  150. __set_bit(first, p_l2_info->pp_qid_usage[queue_id]);
  151. p_cid->qid_usage_idx = first;
  152. out:
  153. mutex_unlock(&p_l2_info->lock);
  154. return b_rc;
  155. }
  156. static void qed_eth_queue_qid_usage_del(struct qed_hwfn *p_hwfn,
  157. struct qed_queue_cid *p_cid)
  158. {
  159. mutex_lock(&p_hwfn->p_l2_info->lock);
  160. clear_bit(p_cid->qid_usage_idx,
  161. p_hwfn->p_l2_info->pp_qid_usage[p_cid->rel.queue_id]);
  162. mutex_unlock(&p_hwfn->p_l2_info->lock);
  163. }
  164. void qed_eth_queue_cid_release(struct qed_hwfn *p_hwfn,
  165. struct qed_queue_cid *p_cid)
  166. {
  167. bool b_legacy_vf = !!(p_cid->vf_legacy & QED_QCID_LEGACY_VF_CID);
  168. if (IS_PF(p_hwfn->cdev) && !b_legacy_vf)
  169. _qed_cxt_release_cid(p_hwfn, p_cid->cid, p_cid->vfid);
  170. /* For PF's VFs we maintain the index inside queue-zone in IOV */
  171. if (p_cid->vfid == QED_QUEUE_CID_SELF)
  172. qed_eth_queue_qid_usage_del(p_hwfn, p_cid);
  173. vfree(p_cid);
  174. }
  175. /* The internal is only meant to be directly called by PFs initializeing CIDs
  176. * for their VFs.
  177. */
  178. static struct qed_queue_cid *
  179. _qed_eth_queue_to_cid(struct qed_hwfn *p_hwfn,
  180. u16 opaque_fid,
  181. u32 cid,
  182. struct qed_queue_start_common_params *p_params,
  183. bool b_is_rx,
  184. struct qed_queue_cid_vf_params *p_vf_params)
  185. {
  186. struct qed_queue_cid *p_cid;
  187. int rc;
  188. p_cid = vzalloc(sizeof(*p_cid));
  189. if (!p_cid)
  190. return NULL;
  191. p_cid->opaque_fid = opaque_fid;
  192. p_cid->cid = cid;
  193. p_cid->p_owner = p_hwfn;
  194. /* Fill in parameters */
  195. p_cid->rel.vport_id = p_params->vport_id;
  196. p_cid->rel.queue_id = p_params->queue_id;
  197. p_cid->rel.stats_id = p_params->stats_id;
  198. p_cid->sb_igu_id = p_params->p_sb->igu_sb_id;
  199. p_cid->b_is_rx = b_is_rx;
  200. p_cid->sb_idx = p_params->sb_idx;
  201. /* Fill-in bits related to VFs' queues if information was provided */
  202. if (p_vf_params) {
  203. p_cid->vfid = p_vf_params->vfid;
  204. p_cid->vf_qid = p_vf_params->vf_qid;
  205. p_cid->vf_legacy = p_vf_params->vf_legacy;
  206. } else {
  207. p_cid->vfid = QED_QUEUE_CID_SELF;
  208. }
  209. /* Don't try calculating the absolute indices for VFs */
  210. if (IS_VF(p_hwfn->cdev)) {
  211. p_cid->abs = p_cid->rel;
  212. goto out;
  213. }
  214. /* Calculate the engine-absolute indices of the resources.
  215. * This would guarantee they're valid later on.
  216. * In some cases [SBs] we already have the right values.
  217. */
  218. rc = qed_fw_vport(p_hwfn, p_cid->rel.vport_id, &p_cid->abs.vport_id);
  219. if (rc)
  220. goto fail;
  221. rc = qed_fw_l2_queue(p_hwfn, p_cid->rel.queue_id, &p_cid->abs.queue_id);
  222. if (rc)
  223. goto fail;
  224. /* In case of a PF configuring its VF's queues, the stats-id is already
  225. * absolute [since there's a single index that's suitable per-VF].
  226. */
  227. if (p_cid->vfid == QED_QUEUE_CID_SELF) {
  228. rc = qed_fw_vport(p_hwfn, p_cid->rel.stats_id,
  229. &p_cid->abs.stats_id);
  230. if (rc)
  231. goto fail;
  232. } else {
  233. p_cid->abs.stats_id = p_cid->rel.stats_id;
  234. }
  235. out:
  236. /* VF-images have provided the qid_usage_idx on their own.
  237. * Otherwise, we need to allocate a unique one.
  238. */
  239. if (!p_vf_params) {
  240. if (!qed_eth_queue_qid_usage_add(p_hwfn, p_cid))
  241. goto fail;
  242. } else {
  243. p_cid->qid_usage_idx = p_vf_params->qid_usage_idx;
  244. }
  245. DP_VERBOSE(p_hwfn,
  246. QED_MSG_SP,
  247. "opaque_fid: %04x CID %08x vport %02x [%02x] qzone %04x.%02x [%04x] stats %02x [%02x] SB %04x PI %02x\n",
  248. p_cid->opaque_fid,
  249. p_cid->cid,
  250. p_cid->rel.vport_id,
  251. p_cid->abs.vport_id,
  252. p_cid->rel.queue_id,
  253. p_cid->qid_usage_idx,
  254. p_cid->abs.queue_id,
  255. p_cid->rel.stats_id,
  256. p_cid->abs.stats_id, p_cid->sb_igu_id, p_cid->sb_idx);
  257. return p_cid;
  258. fail:
  259. vfree(p_cid);
  260. return NULL;
  261. }
  262. struct qed_queue_cid *
  263. qed_eth_queue_to_cid(struct qed_hwfn *p_hwfn,
  264. u16 opaque_fid,
  265. struct qed_queue_start_common_params *p_params,
  266. bool b_is_rx,
  267. struct qed_queue_cid_vf_params *p_vf_params)
  268. {
  269. struct qed_queue_cid *p_cid;
  270. u8 vfid = QED_CXT_PF_CID;
  271. bool b_legacy_vf = false;
  272. u32 cid = 0;
  273. /* In case of legacy VFs, The CID can be derived from the additional
  274. * VF parameters - the VF assumes queue X uses CID X, so we can simply
  275. * use the vf_qid for this purpose as well.
  276. */
  277. if (p_vf_params) {
  278. vfid = p_vf_params->vfid;
  279. if (p_vf_params->vf_legacy & QED_QCID_LEGACY_VF_CID) {
  280. b_legacy_vf = true;
  281. cid = p_vf_params->vf_qid;
  282. }
  283. }
  284. /* Get a unique firmware CID for this queue, in case it's a PF.
  285. * VF's don't need a CID as the queue configuration will be done
  286. * by PF.
  287. */
  288. if (IS_PF(p_hwfn->cdev) && !b_legacy_vf) {
  289. if (_qed_cxt_acquire_cid(p_hwfn, PROTOCOLID_ETH,
  290. &cid, vfid)) {
  291. DP_NOTICE(p_hwfn, "Failed to acquire cid\n");
  292. return NULL;
  293. }
  294. }
  295. p_cid = _qed_eth_queue_to_cid(p_hwfn, opaque_fid, cid,
  296. p_params, b_is_rx, p_vf_params);
  297. if (!p_cid && IS_PF(p_hwfn->cdev) && !b_legacy_vf)
  298. _qed_cxt_release_cid(p_hwfn, cid, vfid);
  299. return p_cid;
  300. }
  301. static struct qed_queue_cid *
  302. qed_eth_queue_to_cid_pf(struct qed_hwfn *p_hwfn,
  303. u16 opaque_fid,
  304. bool b_is_rx,
  305. struct qed_queue_start_common_params *p_params)
  306. {
  307. return qed_eth_queue_to_cid(p_hwfn, opaque_fid, p_params, b_is_rx,
  308. NULL);
  309. }
  310. int qed_sp_eth_vport_start(struct qed_hwfn *p_hwfn,
  311. struct qed_sp_vport_start_params *p_params)
  312. {
  313. struct vport_start_ramrod_data *p_ramrod = NULL;
  314. struct qed_spq_entry *p_ent = NULL;
  315. struct qed_sp_init_data init_data;
  316. u8 abs_vport_id = 0;
  317. int rc = -EINVAL;
  318. u16 rx_mode = 0;
  319. rc = qed_fw_vport(p_hwfn, p_params->vport_id, &abs_vport_id);
  320. if (rc)
  321. return rc;
  322. memset(&init_data, 0, sizeof(init_data));
  323. init_data.cid = qed_spq_get_cid(p_hwfn);
  324. init_data.opaque_fid = p_params->opaque_fid;
  325. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  326. rc = qed_sp_init_request(p_hwfn, &p_ent,
  327. ETH_RAMROD_VPORT_START,
  328. PROTOCOLID_ETH, &init_data);
  329. if (rc)
  330. return rc;
  331. p_ramrod = &p_ent->ramrod.vport_start;
  332. p_ramrod->vport_id = abs_vport_id;
  333. p_ramrod->mtu = cpu_to_le16(p_params->mtu);
  334. p_ramrod->handle_ptp_pkts = p_params->handle_ptp_pkts;
  335. p_ramrod->inner_vlan_removal_en = p_params->remove_inner_vlan;
  336. p_ramrod->drop_ttl0_en = p_params->drop_ttl0;
  337. p_ramrod->untagged = p_params->only_untagged;
  338. SET_FIELD(rx_mode, ETH_VPORT_RX_MODE_UCAST_DROP_ALL, 1);
  339. SET_FIELD(rx_mode, ETH_VPORT_RX_MODE_MCAST_DROP_ALL, 1);
  340. p_ramrod->rx_mode.state = cpu_to_le16(rx_mode);
  341. /* TPA related fields */
  342. memset(&p_ramrod->tpa_param, 0, sizeof(struct eth_vport_tpa_param));
  343. p_ramrod->tpa_param.max_buff_num = p_params->max_buffers_per_cqe;
  344. switch (p_params->tpa_mode) {
  345. case QED_TPA_MODE_GRO:
  346. p_ramrod->tpa_param.tpa_max_aggs_num = ETH_TPA_MAX_AGGS_NUM;
  347. p_ramrod->tpa_param.tpa_max_size = (u16)-1;
  348. p_ramrod->tpa_param.tpa_min_size_to_cont = p_params->mtu / 2;
  349. p_ramrod->tpa_param.tpa_min_size_to_start = p_params->mtu / 2;
  350. p_ramrod->tpa_param.tpa_ipv4_en_flg = 1;
  351. p_ramrod->tpa_param.tpa_ipv6_en_flg = 1;
  352. p_ramrod->tpa_param.tpa_pkt_split_flg = 1;
  353. p_ramrod->tpa_param.tpa_gro_consistent_flg = 1;
  354. break;
  355. default:
  356. break;
  357. }
  358. p_ramrod->tx_switching_en = p_params->tx_switching;
  359. p_ramrod->ctl_frame_mac_check_en = !!p_params->check_mac;
  360. p_ramrod->ctl_frame_ethtype_check_en = !!p_params->check_ethtype;
  361. /* Software Function ID in hwfn (PFs are 0 - 15, VFs are 16 - 135) */
  362. p_ramrod->sw_fid = qed_concrete_to_sw_fid(p_hwfn->cdev,
  363. p_params->concrete_fid);
  364. return qed_spq_post(p_hwfn, p_ent, NULL);
  365. }
  366. static int qed_sp_vport_start(struct qed_hwfn *p_hwfn,
  367. struct qed_sp_vport_start_params *p_params)
  368. {
  369. if (IS_VF(p_hwfn->cdev)) {
  370. return qed_vf_pf_vport_start(p_hwfn, p_params->vport_id,
  371. p_params->mtu,
  372. p_params->remove_inner_vlan,
  373. p_params->tpa_mode,
  374. p_params->max_buffers_per_cqe,
  375. p_params->only_untagged);
  376. }
  377. return qed_sp_eth_vport_start(p_hwfn, p_params);
  378. }
  379. static int
  380. qed_sp_vport_update_rss(struct qed_hwfn *p_hwfn,
  381. struct vport_update_ramrod_data *p_ramrod,
  382. struct qed_rss_params *p_rss)
  383. {
  384. struct eth_vport_rss_config *p_config;
  385. u16 capabilities = 0;
  386. int i, table_size;
  387. int rc = 0;
  388. if (!p_rss) {
  389. p_ramrod->common.update_rss_flg = 0;
  390. return rc;
  391. }
  392. p_config = &p_ramrod->rss_config;
  393. BUILD_BUG_ON(QED_RSS_IND_TABLE_SIZE != ETH_RSS_IND_TABLE_ENTRIES_NUM);
  394. rc = qed_fw_rss_eng(p_hwfn, p_rss->rss_eng_id, &p_config->rss_id);
  395. if (rc)
  396. return rc;
  397. p_ramrod->common.update_rss_flg = p_rss->update_rss_config;
  398. p_config->update_rss_capabilities = p_rss->update_rss_capabilities;
  399. p_config->update_rss_ind_table = p_rss->update_rss_ind_table;
  400. p_config->update_rss_key = p_rss->update_rss_key;
  401. p_config->rss_mode = p_rss->rss_enable ?
  402. ETH_VPORT_RSS_MODE_REGULAR :
  403. ETH_VPORT_RSS_MODE_DISABLED;
  404. SET_FIELD(capabilities,
  405. ETH_VPORT_RSS_CONFIG_IPV4_CAPABILITY,
  406. !!(p_rss->rss_caps & QED_RSS_IPV4));
  407. SET_FIELD(capabilities,
  408. ETH_VPORT_RSS_CONFIG_IPV6_CAPABILITY,
  409. !!(p_rss->rss_caps & QED_RSS_IPV6));
  410. SET_FIELD(capabilities,
  411. ETH_VPORT_RSS_CONFIG_IPV4_TCP_CAPABILITY,
  412. !!(p_rss->rss_caps & QED_RSS_IPV4_TCP));
  413. SET_FIELD(capabilities,
  414. ETH_VPORT_RSS_CONFIG_IPV6_TCP_CAPABILITY,
  415. !!(p_rss->rss_caps & QED_RSS_IPV6_TCP));
  416. SET_FIELD(capabilities,
  417. ETH_VPORT_RSS_CONFIG_IPV4_UDP_CAPABILITY,
  418. !!(p_rss->rss_caps & QED_RSS_IPV4_UDP));
  419. SET_FIELD(capabilities,
  420. ETH_VPORT_RSS_CONFIG_IPV6_UDP_CAPABILITY,
  421. !!(p_rss->rss_caps & QED_RSS_IPV6_UDP));
  422. p_config->tbl_size = p_rss->rss_table_size_log;
  423. p_config->capabilities = cpu_to_le16(capabilities);
  424. DP_VERBOSE(p_hwfn, NETIF_MSG_IFUP,
  425. "update rss flag %d, rss_mode = %d, update_caps = %d, capabilities = %d, update_ind = %d, update_rss_key = %d\n",
  426. p_ramrod->common.update_rss_flg,
  427. p_config->rss_mode,
  428. p_config->update_rss_capabilities,
  429. p_config->capabilities,
  430. p_config->update_rss_ind_table, p_config->update_rss_key);
  431. table_size = min_t(int, QED_RSS_IND_TABLE_SIZE,
  432. 1 << p_config->tbl_size);
  433. for (i = 0; i < table_size; i++) {
  434. struct qed_queue_cid *p_queue = p_rss->rss_ind_table[i];
  435. if (!p_queue)
  436. return -EINVAL;
  437. p_config->indirection_table[i] =
  438. cpu_to_le16(p_queue->abs.queue_id);
  439. }
  440. DP_VERBOSE(p_hwfn, NETIF_MSG_IFUP,
  441. "Configured RSS indirection table [%d entries]:\n",
  442. table_size);
  443. for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i += 0x10) {
  444. DP_VERBOSE(p_hwfn,
  445. NETIF_MSG_IFUP,
  446. "%04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x\n",
  447. le16_to_cpu(p_config->indirection_table[i]),
  448. le16_to_cpu(p_config->indirection_table[i + 1]),
  449. le16_to_cpu(p_config->indirection_table[i + 2]),
  450. le16_to_cpu(p_config->indirection_table[i + 3]),
  451. le16_to_cpu(p_config->indirection_table[i + 4]),
  452. le16_to_cpu(p_config->indirection_table[i + 5]),
  453. le16_to_cpu(p_config->indirection_table[i + 6]),
  454. le16_to_cpu(p_config->indirection_table[i + 7]),
  455. le16_to_cpu(p_config->indirection_table[i + 8]),
  456. le16_to_cpu(p_config->indirection_table[i + 9]),
  457. le16_to_cpu(p_config->indirection_table[i + 10]),
  458. le16_to_cpu(p_config->indirection_table[i + 11]),
  459. le16_to_cpu(p_config->indirection_table[i + 12]),
  460. le16_to_cpu(p_config->indirection_table[i + 13]),
  461. le16_to_cpu(p_config->indirection_table[i + 14]),
  462. le16_to_cpu(p_config->indirection_table[i + 15]));
  463. }
  464. for (i = 0; i < 10; i++)
  465. p_config->rss_key[i] = cpu_to_le32(p_rss->rss_key[i]);
  466. return rc;
  467. }
  468. static void
  469. qed_sp_update_accept_mode(struct qed_hwfn *p_hwfn,
  470. struct vport_update_ramrod_data *p_ramrod,
  471. struct qed_filter_accept_flags accept_flags)
  472. {
  473. p_ramrod->common.update_rx_mode_flg =
  474. accept_flags.update_rx_mode_config;
  475. p_ramrod->common.update_tx_mode_flg =
  476. accept_flags.update_tx_mode_config;
  477. /* Set Rx mode accept flags */
  478. if (p_ramrod->common.update_rx_mode_flg) {
  479. u8 accept_filter = accept_flags.rx_accept_filter;
  480. u16 state = 0;
  481. SET_FIELD(state, ETH_VPORT_RX_MODE_UCAST_DROP_ALL,
  482. !(!!(accept_filter & QED_ACCEPT_UCAST_MATCHED) ||
  483. !!(accept_filter & QED_ACCEPT_UCAST_UNMATCHED)));
  484. SET_FIELD(state, ETH_VPORT_RX_MODE_UCAST_ACCEPT_UNMATCHED,
  485. !!(accept_filter & QED_ACCEPT_UCAST_UNMATCHED));
  486. SET_FIELD(state, ETH_VPORT_RX_MODE_MCAST_DROP_ALL,
  487. !(!!(accept_filter & QED_ACCEPT_MCAST_MATCHED) ||
  488. !!(accept_filter & QED_ACCEPT_MCAST_UNMATCHED)));
  489. SET_FIELD(state, ETH_VPORT_RX_MODE_MCAST_ACCEPT_ALL,
  490. (!!(accept_filter & QED_ACCEPT_MCAST_MATCHED) &&
  491. !!(accept_filter & QED_ACCEPT_MCAST_UNMATCHED)));
  492. SET_FIELD(state, ETH_VPORT_RX_MODE_BCAST_ACCEPT_ALL,
  493. !!(accept_filter & QED_ACCEPT_BCAST));
  494. p_ramrod->rx_mode.state = cpu_to_le16(state);
  495. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  496. "p_ramrod->rx_mode.state = 0x%x\n", state);
  497. }
  498. /* Set Tx mode accept flags */
  499. if (p_ramrod->common.update_tx_mode_flg) {
  500. u8 accept_filter = accept_flags.tx_accept_filter;
  501. u16 state = 0;
  502. SET_FIELD(state, ETH_VPORT_TX_MODE_UCAST_DROP_ALL,
  503. !!(accept_filter & QED_ACCEPT_NONE));
  504. SET_FIELD(state, ETH_VPORT_TX_MODE_MCAST_DROP_ALL,
  505. !!(accept_filter & QED_ACCEPT_NONE));
  506. SET_FIELD(state, ETH_VPORT_TX_MODE_MCAST_ACCEPT_ALL,
  507. (!!(accept_filter & QED_ACCEPT_MCAST_MATCHED) &&
  508. !!(accept_filter & QED_ACCEPT_MCAST_UNMATCHED)));
  509. SET_FIELD(state, ETH_VPORT_TX_MODE_BCAST_ACCEPT_ALL,
  510. !!(accept_filter & QED_ACCEPT_BCAST));
  511. p_ramrod->tx_mode.state = cpu_to_le16(state);
  512. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  513. "p_ramrod->tx_mode.state = 0x%x\n", state);
  514. }
  515. }
  516. static void
  517. qed_sp_vport_update_sge_tpa(struct qed_hwfn *p_hwfn,
  518. struct vport_update_ramrod_data *p_ramrod,
  519. struct qed_sge_tpa_params *p_params)
  520. {
  521. struct eth_vport_tpa_param *p_tpa;
  522. if (!p_params) {
  523. p_ramrod->common.update_tpa_param_flg = 0;
  524. p_ramrod->common.update_tpa_en_flg = 0;
  525. p_ramrod->common.update_tpa_param_flg = 0;
  526. return;
  527. }
  528. p_ramrod->common.update_tpa_en_flg = p_params->update_tpa_en_flg;
  529. p_tpa = &p_ramrod->tpa_param;
  530. p_tpa->tpa_ipv4_en_flg = p_params->tpa_ipv4_en_flg;
  531. p_tpa->tpa_ipv6_en_flg = p_params->tpa_ipv6_en_flg;
  532. p_tpa->tpa_ipv4_tunn_en_flg = p_params->tpa_ipv4_tunn_en_flg;
  533. p_tpa->tpa_ipv6_tunn_en_flg = p_params->tpa_ipv6_tunn_en_flg;
  534. p_ramrod->common.update_tpa_param_flg = p_params->update_tpa_param_flg;
  535. p_tpa->max_buff_num = p_params->max_buffers_per_cqe;
  536. p_tpa->tpa_pkt_split_flg = p_params->tpa_pkt_split_flg;
  537. p_tpa->tpa_hdr_data_split_flg = p_params->tpa_hdr_data_split_flg;
  538. p_tpa->tpa_gro_consistent_flg = p_params->tpa_gro_consistent_flg;
  539. p_tpa->tpa_max_aggs_num = p_params->tpa_max_aggs_num;
  540. p_tpa->tpa_max_size = p_params->tpa_max_size;
  541. p_tpa->tpa_min_size_to_start = p_params->tpa_min_size_to_start;
  542. p_tpa->tpa_min_size_to_cont = p_params->tpa_min_size_to_cont;
  543. }
  544. static void
  545. qed_sp_update_mcast_bin(struct qed_hwfn *p_hwfn,
  546. struct vport_update_ramrod_data *p_ramrod,
  547. struct qed_sp_vport_update_params *p_params)
  548. {
  549. int i;
  550. memset(&p_ramrod->approx_mcast.bins, 0,
  551. sizeof(p_ramrod->approx_mcast.bins));
  552. if (!p_params->update_approx_mcast_flg)
  553. return;
  554. p_ramrod->common.update_approx_mcast_flg = 1;
  555. for (i = 0; i < ETH_MULTICAST_MAC_BINS_IN_REGS; i++) {
  556. u32 *p_bins = (u32 *)p_params->bins;
  557. p_ramrod->approx_mcast.bins[i] = cpu_to_le32(p_bins[i]);
  558. }
  559. }
  560. int qed_sp_vport_update(struct qed_hwfn *p_hwfn,
  561. struct qed_sp_vport_update_params *p_params,
  562. enum spq_mode comp_mode,
  563. struct qed_spq_comp_cb *p_comp_data)
  564. {
  565. struct qed_rss_params *p_rss_params = p_params->rss_params;
  566. struct vport_update_ramrod_data_cmn *p_cmn;
  567. struct qed_sp_init_data init_data;
  568. struct vport_update_ramrod_data *p_ramrod = NULL;
  569. struct qed_spq_entry *p_ent = NULL;
  570. u8 abs_vport_id = 0, val;
  571. int rc = -EINVAL;
  572. if (IS_VF(p_hwfn->cdev)) {
  573. rc = qed_vf_pf_vport_update(p_hwfn, p_params);
  574. return rc;
  575. }
  576. rc = qed_fw_vport(p_hwfn, p_params->vport_id, &abs_vport_id);
  577. if (rc)
  578. return rc;
  579. memset(&init_data, 0, sizeof(init_data));
  580. init_data.cid = qed_spq_get_cid(p_hwfn);
  581. init_data.opaque_fid = p_params->opaque_fid;
  582. init_data.comp_mode = comp_mode;
  583. init_data.p_comp_data = p_comp_data;
  584. rc = qed_sp_init_request(p_hwfn, &p_ent,
  585. ETH_RAMROD_VPORT_UPDATE,
  586. PROTOCOLID_ETH, &init_data);
  587. if (rc)
  588. return rc;
  589. /* Copy input params to ramrod according to FW struct */
  590. p_ramrod = &p_ent->ramrod.vport_update;
  591. p_cmn = &p_ramrod->common;
  592. p_cmn->vport_id = abs_vport_id;
  593. p_cmn->rx_active_flg = p_params->vport_active_rx_flg;
  594. p_cmn->update_rx_active_flg = p_params->update_vport_active_rx_flg;
  595. p_cmn->tx_active_flg = p_params->vport_active_tx_flg;
  596. p_cmn->update_tx_active_flg = p_params->update_vport_active_tx_flg;
  597. p_cmn->accept_any_vlan = p_params->accept_any_vlan;
  598. val = p_params->update_accept_any_vlan_flg;
  599. p_cmn->update_accept_any_vlan_flg = val;
  600. p_cmn->inner_vlan_removal_en = p_params->inner_vlan_removal_flg;
  601. val = p_params->update_inner_vlan_removal_flg;
  602. p_cmn->update_inner_vlan_removal_en_flg = val;
  603. p_cmn->default_vlan_en = p_params->default_vlan_enable_flg;
  604. val = p_params->update_default_vlan_enable_flg;
  605. p_cmn->update_default_vlan_en_flg = val;
  606. p_cmn->default_vlan = cpu_to_le16(p_params->default_vlan);
  607. p_cmn->update_default_vlan_flg = p_params->update_default_vlan_flg;
  608. p_cmn->silent_vlan_removal_en = p_params->silent_vlan_removal_flg;
  609. p_ramrod->common.tx_switching_en = p_params->tx_switching_flg;
  610. p_cmn->update_tx_switching_en_flg = p_params->update_tx_switching_flg;
  611. p_cmn->anti_spoofing_en = p_params->anti_spoofing_en;
  612. val = p_params->update_anti_spoofing_en_flg;
  613. p_ramrod->common.update_anti_spoofing_en_flg = val;
  614. rc = qed_sp_vport_update_rss(p_hwfn, p_ramrod, p_rss_params);
  615. if (rc) {
  616. /* Return spq entry which is taken in qed_sp_init_request()*/
  617. qed_spq_return_entry(p_hwfn, p_ent);
  618. return rc;
  619. }
  620. /* Update mcast bins for VFs, PF doesn't use this functionality */
  621. qed_sp_update_mcast_bin(p_hwfn, p_ramrod, p_params);
  622. qed_sp_update_accept_mode(p_hwfn, p_ramrod, p_params->accept_flags);
  623. qed_sp_vport_update_sge_tpa(p_hwfn, p_ramrod, p_params->sge_tpa_params);
  624. return qed_spq_post(p_hwfn, p_ent, NULL);
  625. }
  626. int qed_sp_vport_stop(struct qed_hwfn *p_hwfn, u16 opaque_fid, u8 vport_id)
  627. {
  628. struct vport_stop_ramrod_data *p_ramrod;
  629. struct qed_sp_init_data init_data;
  630. struct qed_spq_entry *p_ent;
  631. u8 abs_vport_id = 0;
  632. int rc;
  633. if (IS_VF(p_hwfn->cdev))
  634. return qed_vf_pf_vport_stop(p_hwfn);
  635. rc = qed_fw_vport(p_hwfn, vport_id, &abs_vport_id);
  636. if (rc)
  637. return rc;
  638. memset(&init_data, 0, sizeof(init_data));
  639. init_data.cid = qed_spq_get_cid(p_hwfn);
  640. init_data.opaque_fid = opaque_fid;
  641. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  642. rc = qed_sp_init_request(p_hwfn, &p_ent,
  643. ETH_RAMROD_VPORT_STOP,
  644. PROTOCOLID_ETH, &init_data);
  645. if (rc)
  646. return rc;
  647. p_ramrod = &p_ent->ramrod.vport_stop;
  648. p_ramrod->vport_id = abs_vport_id;
  649. return qed_spq_post(p_hwfn, p_ent, NULL);
  650. }
  651. static int
  652. qed_vf_pf_accept_flags(struct qed_hwfn *p_hwfn,
  653. struct qed_filter_accept_flags *p_accept_flags)
  654. {
  655. struct qed_sp_vport_update_params s_params;
  656. memset(&s_params, 0, sizeof(s_params));
  657. memcpy(&s_params.accept_flags, p_accept_flags,
  658. sizeof(struct qed_filter_accept_flags));
  659. return qed_vf_pf_vport_update(p_hwfn, &s_params);
  660. }
  661. static int qed_filter_accept_cmd(struct qed_dev *cdev,
  662. u8 vport,
  663. struct qed_filter_accept_flags accept_flags,
  664. u8 update_accept_any_vlan,
  665. u8 accept_any_vlan,
  666. enum spq_mode comp_mode,
  667. struct qed_spq_comp_cb *p_comp_data)
  668. {
  669. struct qed_sp_vport_update_params vport_update_params;
  670. int i, rc;
  671. /* Prepare and send the vport rx_mode change */
  672. memset(&vport_update_params, 0, sizeof(vport_update_params));
  673. vport_update_params.vport_id = vport;
  674. vport_update_params.accept_flags = accept_flags;
  675. vport_update_params.update_accept_any_vlan_flg = update_accept_any_vlan;
  676. vport_update_params.accept_any_vlan = accept_any_vlan;
  677. for_each_hwfn(cdev, i) {
  678. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  679. vport_update_params.opaque_fid = p_hwfn->hw_info.opaque_fid;
  680. if (IS_VF(cdev)) {
  681. rc = qed_vf_pf_accept_flags(p_hwfn, &accept_flags);
  682. if (rc)
  683. return rc;
  684. continue;
  685. }
  686. rc = qed_sp_vport_update(p_hwfn, &vport_update_params,
  687. comp_mode, p_comp_data);
  688. if (rc) {
  689. DP_ERR(cdev, "Update rx_mode failed %d\n", rc);
  690. return rc;
  691. }
  692. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  693. "Accept filter configured, flags = [Rx]%x [Tx]%x\n",
  694. accept_flags.rx_accept_filter,
  695. accept_flags.tx_accept_filter);
  696. if (update_accept_any_vlan)
  697. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  698. "accept_any_vlan=%d configured\n",
  699. accept_any_vlan);
  700. }
  701. return 0;
  702. }
  703. int qed_eth_rxq_start_ramrod(struct qed_hwfn *p_hwfn,
  704. struct qed_queue_cid *p_cid,
  705. u16 bd_max_bytes,
  706. dma_addr_t bd_chain_phys_addr,
  707. dma_addr_t cqe_pbl_addr, u16 cqe_pbl_size)
  708. {
  709. struct rx_queue_start_ramrod_data *p_ramrod = NULL;
  710. struct qed_spq_entry *p_ent = NULL;
  711. struct qed_sp_init_data init_data;
  712. int rc = -EINVAL;
  713. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  714. "opaque_fid=0x%x, cid=0x%x, rx_qzone=0x%x, vport_id=0x%x, sb_id=0x%x\n",
  715. p_cid->opaque_fid, p_cid->cid,
  716. p_cid->abs.queue_id, p_cid->abs.vport_id, p_cid->sb_igu_id);
  717. /* Get SPQ entry */
  718. memset(&init_data, 0, sizeof(init_data));
  719. init_data.cid = p_cid->cid;
  720. init_data.opaque_fid = p_cid->opaque_fid;
  721. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  722. rc = qed_sp_init_request(p_hwfn, &p_ent,
  723. ETH_RAMROD_RX_QUEUE_START,
  724. PROTOCOLID_ETH, &init_data);
  725. if (rc)
  726. return rc;
  727. p_ramrod = &p_ent->ramrod.rx_queue_start;
  728. p_ramrod->sb_id = cpu_to_le16(p_cid->sb_igu_id);
  729. p_ramrod->sb_index = p_cid->sb_idx;
  730. p_ramrod->vport_id = p_cid->abs.vport_id;
  731. p_ramrod->stats_counter_id = p_cid->abs.stats_id;
  732. p_ramrod->rx_queue_id = cpu_to_le16(p_cid->abs.queue_id);
  733. p_ramrod->complete_cqe_flg = 0;
  734. p_ramrod->complete_event_flg = 1;
  735. p_ramrod->bd_max_bytes = cpu_to_le16(bd_max_bytes);
  736. DMA_REGPAIR_LE(p_ramrod->bd_base, bd_chain_phys_addr);
  737. p_ramrod->num_of_pbl_pages = cpu_to_le16(cqe_pbl_size);
  738. DMA_REGPAIR_LE(p_ramrod->cqe_pbl_addr, cqe_pbl_addr);
  739. if (p_cid->vfid != QED_QUEUE_CID_SELF) {
  740. bool b_legacy_vf = !!(p_cid->vf_legacy &
  741. QED_QCID_LEGACY_VF_RX_PROD);
  742. p_ramrod->vf_rx_prod_index = p_cid->vf_qid;
  743. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  744. "Queue%s is meant for VF rxq[%02x]\n",
  745. b_legacy_vf ? " [legacy]" : "", p_cid->vf_qid);
  746. p_ramrod->vf_rx_prod_use_zone_a = b_legacy_vf;
  747. }
  748. return qed_spq_post(p_hwfn, p_ent, NULL);
  749. }
  750. static int
  751. qed_eth_pf_rx_queue_start(struct qed_hwfn *p_hwfn,
  752. struct qed_queue_cid *p_cid,
  753. u16 bd_max_bytes,
  754. dma_addr_t bd_chain_phys_addr,
  755. dma_addr_t cqe_pbl_addr,
  756. u16 cqe_pbl_size, void __iomem **pp_prod)
  757. {
  758. u32 init_prod_val = 0;
  759. *pp_prod = p_hwfn->regview +
  760. GTT_BAR0_MAP_REG_MSDM_RAM +
  761. MSTORM_ETH_PF_PRODS_OFFSET(p_cid->abs.queue_id);
  762. /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
  763. __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
  764. (u32 *)(&init_prod_val));
  765. return qed_eth_rxq_start_ramrod(p_hwfn, p_cid,
  766. bd_max_bytes,
  767. bd_chain_phys_addr,
  768. cqe_pbl_addr, cqe_pbl_size);
  769. }
  770. static int
  771. qed_eth_rx_queue_start(struct qed_hwfn *p_hwfn,
  772. u16 opaque_fid,
  773. struct qed_queue_start_common_params *p_params,
  774. u16 bd_max_bytes,
  775. dma_addr_t bd_chain_phys_addr,
  776. dma_addr_t cqe_pbl_addr,
  777. u16 cqe_pbl_size,
  778. struct qed_rxq_start_ret_params *p_ret_params)
  779. {
  780. struct qed_queue_cid *p_cid;
  781. int rc;
  782. /* Allocate a CID for the queue */
  783. p_cid = qed_eth_queue_to_cid_pf(p_hwfn, opaque_fid, true, p_params);
  784. if (!p_cid)
  785. return -ENOMEM;
  786. if (IS_PF(p_hwfn->cdev)) {
  787. rc = qed_eth_pf_rx_queue_start(p_hwfn, p_cid,
  788. bd_max_bytes,
  789. bd_chain_phys_addr,
  790. cqe_pbl_addr, cqe_pbl_size,
  791. &p_ret_params->p_prod);
  792. } else {
  793. rc = qed_vf_pf_rxq_start(p_hwfn, p_cid,
  794. bd_max_bytes,
  795. bd_chain_phys_addr,
  796. cqe_pbl_addr,
  797. cqe_pbl_size, &p_ret_params->p_prod);
  798. }
  799. /* Provide the caller with a reference to as handler */
  800. if (rc)
  801. qed_eth_queue_cid_release(p_hwfn, p_cid);
  802. else
  803. p_ret_params->p_handle = (void *)p_cid;
  804. return rc;
  805. }
  806. int qed_sp_eth_rx_queues_update(struct qed_hwfn *p_hwfn,
  807. void **pp_rxq_handles,
  808. u8 num_rxqs,
  809. u8 complete_cqe_flg,
  810. u8 complete_event_flg,
  811. enum spq_mode comp_mode,
  812. struct qed_spq_comp_cb *p_comp_data)
  813. {
  814. struct rx_queue_update_ramrod_data *p_ramrod = NULL;
  815. struct qed_spq_entry *p_ent = NULL;
  816. struct qed_sp_init_data init_data;
  817. struct qed_queue_cid *p_cid;
  818. int rc = -EINVAL;
  819. u8 i;
  820. memset(&init_data, 0, sizeof(init_data));
  821. init_data.comp_mode = comp_mode;
  822. init_data.p_comp_data = p_comp_data;
  823. for (i = 0; i < num_rxqs; i++) {
  824. p_cid = ((struct qed_queue_cid **)pp_rxq_handles)[i];
  825. /* Get SPQ entry */
  826. init_data.cid = p_cid->cid;
  827. init_data.opaque_fid = p_cid->opaque_fid;
  828. rc = qed_sp_init_request(p_hwfn, &p_ent,
  829. ETH_RAMROD_RX_QUEUE_UPDATE,
  830. PROTOCOLID_ETH, &init_data);
  831. if (rc)
  832. return rc;
  833. p_ramrod = &p_ent->ramrod.rx_queue_update;
  834. p_ramrod->vport_id = p_cid->abs.vport_id;
  835. p_ramrod->rx_queue_id = cpu_to_le16(p_cid->abs.queue_id);
  836. p_ramrod->complete_cqe_flg = complete_cqe_flg;
  837. p_ramrod->complete_event_flg = complete_event_flg;
  838. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  839. if (rc)
  840. return rc;
  841. }
  842. return rc;
  843. }
  844. static int
  845. qed_eth_pf_rx_queue_stop(struct qed_hwfn *p_hwfn,
  846. struct qed_queue_cid *p_cid,
  847. bool b_eq_completion_only, bool b_cqe_completion)
  848. {
  849. struct rx_queue_stop_ramrod_data *p_ramrod = NULL;
  850. struct qed_spq_entry *p_ent = NULL;
  851. struct qed_sp_init_data init_data;
  852. int rc;
  853. memset(&init_data, 0, sizeof(init_data));
  854. init_data.cid = p_cid->cid;
  855. init_data.opaque_fid = p_cid->opaque_fid;
  856. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  857. rc = qed_sp_init_request(p_hwfn, &p_ent,
  858. ETH_RAMROD_RX_QUEUE_STOP,
  859. PROTOCOLID_ETH, &init_data);
  860. if (rc)
  861. return rc;
  862. p_ramrod = &p_ent->ramrod.rx_queue_stop;
  863. p_ramrod->vport_id = p_cid->abs.vport_id;
  864. p_ramrod->rx_queue_id = cpu_to_le16(p_cid->abs.queue_id);
  865. /* Cleaning the queue requires the completion to arrive there.
  866. * In addition, VFs require the answer to come as eqe to PF.
  867. */
  868. p_ramrod->complete_cqe_flg = ((p_cid->vfid == QED_QUEUE_CID_SELF) &&
  869. !b_eq_completion_only) ||
  870. b_cqe_completion;
  871. p_ramrod->complete_event_flg = (p_cid->vfid != QED_QUEUE_CID_SELF) ||
  872. b_eq_completion_only;
  873. return qed_spq_post(p_hwfn, p_ent, NULL);
  874. }
  875. int qed_eth_rx_queue_stop(struct qed_hwfn *p_hwfn,
  876. void *p_rxq,
  877. bool eq_completion_only, bool cqe_completion)
  878. {
  879. struct qed_queue_cid *p_cid = (struct qed_queue_cid *)p_rxq;
  880. int rc = -EINVAL;
  881. if (IS_PF(p_hwfn->cdev))
  882. rc = qed_eth_pf_rx_queue_stop(p_hwfn, p_cid,
  883. eq_completion_only,
  884. cqe_completion);
  885. else
  886. rc = qed_vf_pf_rxq_stop(p_hwfn, p_cid, cqe_completion);
  887. if (!rc)
  888. qed_eth_queue_cid_release(p_hwfn, p_cid);
  889. return rc;
  890. }
  891. int
  892. qed_eth_txq_start_ramrod(struct qed_hwfn *p_hwfn,
  893. struct qed_queue_cid *p_cid,
  894. dma_addr_t pbl_addr, u16 pbl_size, u16 pq_id)
  895. {
  896. struct tx_queue_start_ramrod_data *p_ramrod = NULL;
  897. struct qed_spq_entry *p_ent = NULL;
  898. struct qed_sp_init_data init_data;
  899. int rc = -EINVAL;
  900. /* Get SPQ entry */
  901. memset(&init_data, 0, sizeof(init_data));
  902. init_data.cid = p_cid->cid;
  903. init_data.opaque_fid = p_cid->opaque_fid;
  904. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  905. rc = qed_sp_init_request(p_hwfn, &p_ent,
  906. ETH_RAMROD_TX_QUEUE_START,
  907. PROTOCOLID_ETH, &init_data);
  908. if (rc)
  909. return rc;
  910. p_ramrod = &p_ent->ramrod.tx_queue_start;
  911. p_ramrod->vport_id = p_cid->abs.vport_id;
  912. p_ramrod->sb_id = cpu_to_le16(p_cid->sb_igu_id);
  913. p_ramrod->sb_index = p_cid->sb_idx;
  914. p_ramrod->stats_counter_id = p_cid->abs.stats_id;
  915. p_ramrod->queue_zone_id = cpu_to_le16(p_cid->abs.queue_id);
  916. p_ramrod->same_as_last_id = cpu_to_le16(p_cid->abs.queue_id);
  917. p_ramrod->pbl_size = cpu_to_le16(pbl_size);
  918. DMA_REGPAIR_LE(p_ramrod->pbl_base_addr, pbl_addr);
  919. p_ramrod->qm_pq_id = cpu_to_le16(pq_id);
  920. return qed_spq_post(p_hwfn, p_ent, NULL);
  921. }
  922. static int
  923. qed_eth_pf_tx_queue_start(struct qed_hwfn *p_hwfn,
  924. struct qed_queue_cid *p_cid,
  925. u8 tc,
  926. dma_addr_t pbl_addr,
  927. u16 pbl_size, void __iomem **pp_doorbell)
  928. {
  929. int rc;
  930. rc = qed_eth_txq_start_ramrod(p_hwfn, p_cid,
  931. pbl_addr, pbl_size,
  932. qed_get_cm_pq_idx_mcos(p_hwfn, tc));
  933. if (rc)
  934. return rc;
  935. /* Provide the caller with the necessary return values */
  936. *pp_doorbell = p_hwfn->doorbells +
  937. qed_db_addr(p_cid->cid, DQ_DEMS_LEGACY);
  938. return 0;
  939. }
  940. static int
  941. qed_eth_tx_queue_start(struct qed_hwfn *p_hwfn,
  942. u16 opaque_fid,
  943. struct qed_queue_start_common_params *p_params,
  944. u8 tc,
  945. dma_addr_t pbl_addr,
  946. u16 pbl_size,
  947. struct qed_txq_start_ret_params *p_ret_params)
  948. {
  949. struct qed_queue_cid *p_cid;
  950. int rc;
  951. p_cid = qed_eth_queue_to_cid_pf(p_hwfn, opaque_fid, false, p_params);
  952. if (!p_cid)
  953. return -EINVAL;
  954. if (IS_PF(p_hwfn->cdev))
  955. rc = qed_eth_pf_tx_queue_start(p_hwfn, p_cid, tc,
  956. pbl_addr, pbl_size,
  957. &p_ret_params->p_doorbell);
  958. else
  959. rc = qed_vf_pf_txq_start(p_hwfn, p_cid,
  960. pbl_addr, pbl_size,
  961. &p_ret_params->p_doorbell);
  962. if (rc)
  963. qed_eth_queue_cid_release(p_hwfn, p_cid);
  964. else
  965. p_ret_params->p_handle = (void *)p_cid;
  966. return rc;
  967. }
  968. static int
  969. qed_eth_pf_tx_queue_stop(struct qed_hwfn *p_hwfn, struct qed_queue_cid *p_cid)
  970. {
  971. struct qed_spq_entry *p_ent = NULL;
  972. struct qed_sp_init_data init_data;
  973. int rc;
  974. memset(&init_data, 0, sizeof(init_data));
  975. init_data.cid = p_cid->cid;
  976. init_data.opaque_fid = p_cid->opaque_fid;
  977. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  978. rc = qed_sp_init_request(p_hwfn, &p_ent,
  979. ETH_RAMROD_TX_QUEUE_STOP,
  980. PROTOCOLID_ETH, &init_data);
  981. if (rc)
  982. return rc;
  983. return qed_spq_post(p_hwfn, p_ent, NULL);
  984. }
  985. int qed_eth_tx_queue_stop(struct qed_hwfn *p_hwfn, void *p_handle)
  986. {
  987. struct qed_queue_cid *p_cid = (struct qed_queue_cid *)p_handle;
  988. int rc;
  989. if (IS_PF(p_hwfn->cdev))
  990. rc = qed_eth_pf_tx_queue_stop(p_hwfn, p_cid);
  991. else
  992. rc = qed_vf_pf_txq_stop(p_hwfn, p_cid);
  993. if (!rc)
  994. qed_eth_queue_cid_release(p_hwfn, p_cid);
  995. return rc;
  996. }
  997. static enum eth_filter_action qed_filter_action(enum qed_filter_opcode opcode)
  998. {
  999. enum eth_filter_action action = MAX_ETH_FILTER_ACTION;
  1000. switch (opcode) {
  1001. case QED_FILTER_ADD:
  1002. action = ETH_FILTER_ACTION_ADD;
  1003. break;
  1004. case QED_FILTER_REMOVE:
  1005. action = ETH_FILTER_ACTION_REMOVE;
  1006. break;
  1007. case QED_FILTER_FLUSH:
  1008. action = ETH_FILTER_ACTION_REMOVE_ALL;
  1009. break;
  1010. default:
  1011. action = MAX_ETH_FILTER_ACTION;
  1012. }
  1013. return action;
  1014. }
  1015. static int
  1016. qed_filter_ucast_common(struct qed_hwfn *p_hwfn,
  1017. u16 opaque_fid,
  1018. struct qed_filter_ucast *p_filter_cmd,
  1019. struct vport_filter_update_ramrod_data **pp_ramrod,
  1020. struct qed_spq_entry **pp_ent,
  1021. enum spq_mode comp_mode,
  1022. struct qed_spq_comp_cb *p_comp_data)
  1023. {
  1024. u8 vport_to_add_to = 0, vport_to_remove_from = 0;
  1025. struct vport_filter_update_ramrod_data *p_ramrod;
  1026. struct eth_filter_cmd *p_first_filter;
  1027. struct eth_filter_cmd *p_second_filter;
  1028. struct qed_sp_init_data init_data;
  1029. enum eth_filter_action action;
  1030. int rc;
  1031. rc = qed_fw_vport(p_hwfn, p_filter_cmd->vport_to_remove_from,
  1032. &vport_to_remove_from);
  1033. if (rc)
  1034. return rc;
  1035. rc = qed_fw_vport(p_hwfn, p_filter_cmd->vport_to_add_to,
  1036. &vport_to_add_to);
  1037. if (rc)
  1038. return rc;
  1039. /* Get SPQ entry */
  1040. memset(&init_data, 0, sizeof(init_data));
  1041. init_data.cid = qed_spq_get_cid(p_hwfn);
  1042. init_data.opaque_fid = opaque_fid;
  1043. init_data.comp_mode = comp_mode;
  1044. init_data.p_comp_data = p_comp_data;
  1045. rc = qed_sp_init_request(p_hwfn, pp_ent,
  1046. ETH_RAMROD_FILTERS_UPDATE,
  1047. PROTOCOLID_ETH, &init_data);
  1048. if (rc)
  1049. return rc;
  1050. *pp_ramrod = &(*pp_ent)->ramrod.vport_filter_update;
  1051. p_ramrod = *pp_ramrod;
  1052. p_ramrod->filter_cmd_hdr.rx = p_filter_cmd->is_rx_filter ? 1 : 0;
  1053. p_ramrod->filter_cmd_hdr.tx = p_filter_cmd->is_tx_filter ? 1 : 0;
  1054. switch (p_filter_cmd->opcode) {
  1055. case QED_FILTER_REPLACE:
  1056. case QED_FILTER_MOVE:
  1057. p_ramrod->filter_cmd_hdr.cmd_cnt = 2; break;
  1058. default:
  1059. p_ramrod->filter_cmd_hdr.cmd_cnt = 1; break;
  1060. }
  1061. p_first_filter = &p_ramrod->filter_cmds[0];
  1062. p_second_filter = &p_ramrod->filter_cmds[1];
  1063. switch (p_filter_cmd->type) {
  1064. case QED_FILTER_MAC:
  1065. p_first_filter->type = ETH_FILTER_TYPE_MAC; break;
  1066. case QED_FILTER_VLAN:
  1067. p_first_filter->type = ETH_FILTER_TYPE_VLAN; break;
  1068. case QED_FILTER_MAC_VLAN:
  1069. p_first_filter->type = ETH_FILTER_TYPE_PAIR; break;
  1070. case QED_FILTER_INNER_MAC:
  1071. p_first_filter->type = ETH_FILTER_TYPE_INNER_MAC; break;
  1072. case QED_FILTER_INNER_VLAN:
  1073. p_first_filter->type = ETH_FILTER_TYPE_INNER_VLAN; break;
  1074. case QED_FILTER_INNER_PAIR:
  1075. p_first_filter->type = ETH_FILTER_TYPE_INNER_PAIR; break;
  1076. case QED_FILTER_INNER_MAC_VNI_PAIR:
  1077. p_first_filter->type = ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR;
  1078. break;
  1079. case QED_FILTER_MAC_VNI_PAIR:
  1080. p_first_filter->type = ETH_FILTER_TYPE_MAC_VNI_PAIR; break;
  1081. case QED_FILTER_VNI:
  1082. p_first_filter->type = ETH_FILTER_TYPE_VNI; break;
  1083. }
  1084. if ((p_first_filter->type == ETH_FILTER_TYPE_MAC) ||
  1085. (p_first_filter->type == ETH_FILTER_TYPE_PAIR) ||
  1086. (p_first_filter->type == ETH_FILTER_TYPE_INNER_MAC) ||
  1087. (p_first_filter->type == ETH_FILTER_TYPE_INNER_PAIR) ||
  1088. (p_first_filter->type == ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR) ||
  1089. (p_first_filter->type == ETH_FILTER_TYPE_MAC_VNI_PAIR)) {
  1090. qed_set_fw_mac_addr(&p_first_filter->mac_msb,
  1091. &p_first_filter->mac_mid,
  1092. &p_first_filter->mac_lsb,
  1093. (u8 *)p_filter_cmd->mac);
  1094. }
  1095. if ((p_first_filter->type == ETH_FILTER_TYPE_VLAN) ||
  1096. (p_first_filter->type == ETH_FILTER_TYPE_PAIR) ||
  1097. (p_first_filter->type == ETH_FILTER_TYPE_INNER_VLAN) ||
  1098. (p_first_filter->type == ETH_FILTER_TYPE_INNER_PAIR))
  1099. p_first_filter->vlan_id = cpu_to_le16(p_filter_cmd->vlan);
  1100. if ((p_first_filter->type == ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR) ||
  1101. (p_first_filter->type == ETH_FILTER_TYPE_MAC_VNI_PAIR) ||
  1102. (p_first_filter->type == ETH_FILTER_TYPE_VNI))
  1103. p_first_filter->vni = cpu_to_le32(p_filter_cmd->vni);
  1104. if (p_filter_cmd->opcode == QED_FILTER_MOVE) {
  1105. p_second_filter->type = p_first_filter->type;
  1106. p_second_filter->mac_msb = p_first_filter->mac_msb;
  1107. p_second_filter->mac_mid = p_first_filter->mac_mid;
  1108. p_second_filter->mac_lsb = p_first_filter->mac_lsb;
  1109. p_second_filter->vlan_id = p_first_filter->vlan_id;
  1110. p_second_filter->vni = p_first_filter->vni;
  1111. p_first_filter->action = ETH_FILTER_ACTION_REMOVE;
  1112. p_first_filter->vport_id = vport_to_remove_from;
  1113. p_second_filter->action = ETH_FILTER_ACTION_ADD;
  1114. p_second_filter->vport_id = vport_to_add_to;
  1115. } else if (p_filter_cmd->opcode == QED_FILTER_REPLACE) {
  1116. p_first_filter->vport_id = vport_to_add_to;
  1117. memcpy(p_second_filter, p_first_filter,
  1118. sizeof(*p_second_filter));
  1119. p_first_filter->action = ETH_FILTER_ACTION_REMOVE_ALL;
  1120. p_second_filter->action = ETH_FILTER_ACTION_ADD;
  1121. } else {
  1122. action = qed_filter_action(p_filter_cmd->opcode);
  1123. if (action == MAX_ETH_FILTER_ACTION) {
  1124. DP_NOTICE(p_hwfn,
  1125. "%d is not supported yet\n",
  1126. p_filter_cmd->opcode);
  1127. return -EINVAL;
  1128. }
  1129. p_first_filter->action = action;
  1130. p_first_filter->vport_id = (p_filter_cmd->opcode ==
  1131. QED_FILTER_REMOVE) ?
  1132. vport_to_remove_from :
  1133. vport_to_add_to;
  1134. }
  1135. return 0;
  1136. }
  1137. int qed_sp_eth_filter_ucast(struct qed_hwfn *p_hwfn,
  1138. u16 opaque_fid,
  1139. struct qed_filter_ucast *p_filter_cmd,
  1140. enum spq_mode comp_mode,
  1141. struct qed_spq_comp_cb *p_comp_data)
  1142. {
  1143. struct vport_filter_update_ramrod_data *p_ramrod = NULL;
  1144. struct qed_spq_entry *p_ent = NULL;
  1145. struct eth_filter_cmd_header *p_header;
  1146. int rc;
  1147. rc = qed_filter_ucast_common(p_hwfn, opaque_fid, p_filter_cmd,
  1148. &p_ramrod, &p_ent,
  1149. comp_mode, p_comp_data);
  1150. if (rc) {
  1151. DP_ERR(p_hwfn, "Uni. filter command failed %d\n", rc);
  1152. return rc;
  1153. }
  1154. p_header = &p_ramrod->filter_cmd_hdr;
  1155. p_header->assert_on_error = p_filter_cmd->assert_on_error;
  1156. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  1157. if (rc) {
  1158. DP_ERR(p_hwfn, "Unicast filter ADD command failed %d\n", rc);
  1159. return rc;
  1160. }
  1161. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  1162. "Unicast filter configured, opcode = %s, type = %s, cmd_cnt = %d, is_rx_filter = %d, is_tx_filter = %d\n",
  1163. (p_filter_cmd->opcode == QED_FILTER_ADD) ? "ADD" :
  1164. ((p_filter_cmd->opcode == QED_FILTER_REMOVE) ?
  1165. "REMOVE" :
  1166. ((p_filter_cmd->opcode == QED_FILTER_MOVE) ?
  1167. "MOVE" : "REPLACE")),
  1168. (p_filter_cmd->type == QED_FILTER_MAC) ? "MAC" :
  1169. ((p_filter_cmd->type == QED_FILTER_VLAN) ?
  1170. "VLAN" : "MAC & VLAN"),
  1171. p_ramrod->filter_cmd_hdr.cmd_cnt,
  1172. p_filter_cmd->is_rx_filter,
  1173. p_filter_cmd->is_tx_filter);
  1174. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  1175. "vport_to_add_to = %d, vport_to_remove_from = %d, mac = %2x:%2x:%2x:%2x:%2x:%2x, vlan = %d\n",
  1176. p_filter_cmd->vport_to_add_to,
  1177. p_filter_cmd->vport_to_remove_from,
  1178. p_filter_cmd->mac[0],
  1179. p_filter_cmd->mac[1],
  1180. p_filter_cmd->mac[2],
  1181. p_filter_cmd->mac[3],
  1182. p_filter_cmd->mac[4],
  1183. p_filter_cmd->mac[5],
  1184. p_filter_cmd->vlan);
  1185. return 0;
  1186. }
  1187. /*******************************************************************************
  1188. * Description:
  1189. * Calculates crc 32 on a buffer
  1190. * Note: crc32_length MUST be aligned to 8
  1191. * Return:
  1192. ******************************************************************************/
  1193. static u32 qed_calc_crc32c(u8 *crc32_packet,
  1194. u32 crc32_length, u32 crc32_seed, u8 complement)
  1195. {
  1196. u32 byte = 0, bit = 0, crc32_result = crc32_seed;
  1197. u8 msb = 0, current_byte = 0;
  1198. if ((!crc32_packet) ||
  1199. (crc32_length == 0) ||
  1200. ((crc32_length % 8) != 0))
  1201. return crc32_result;
  1202. for (byte = 0; byte < crc32_length; byte++) {
  1203. current_byte = crc32_packet[byte];
  1204. for (bit = 0; bit < 8; bit++) {
  1205. msb = (u8)(crc32_result >> 31);
  1206. crc32_result = crc32_result << 1;
  1207. if (msb != (0x1 & (current_byte >> bit))) {
  1208. crc32_result = crc32_result ^ CRC32_POLY;
  1209. crc32_result |= 1; /*crc32_result[0] = 1;*/
  1210. }
  1211. }
  1212. }
  1213. return crc32_result;
  1214. }
  1215. static u32 qed_crc32c_le(u32 seed, u8 *mac, u32 len)
  1216. {
  1217. u32 packet_buf[2] = { 0 };
  1218. memcpy((u8 *)(&packet_buf[0]), &mac[0], 6);
  1219. return qed_calc_crc32c((u8 *)packet_buf, 8, seed, 0);
  1220. }
  1221. u8 qed_mcast_bin_from_mac(u8 *mac)
  1222. {
  1223. u32 crc = qed_crc32c_le(ETH_MULTICAST_BIN_FROM_MAC_SEED,
  1224. mac, ETH_ALEN);
  1225. return crc & 0xff;
  1226. }
  1227. static int
  1228. qed_sp_eth_filter_mcast(struct qed_hwfn *p_hwfn,
  1229. u16 opaque_fid,
  1230. struct qed_filter_mcast *p_filter_cmd,
  1231. enum spq_mode comp_mode,
  1232. struct qed_spq_comp_cb *p_comp_data)
  1233. {
  1234. unsigned long bins[ETH_MULTICAST_MAC_BINS_IN_REGS];
  1235. struct vport_update_ramrod_data *p_ramrod = NULL;
  1236. struct qed_spq_entry *p_ent = NULL;
  1237. struct qed_sp_init_data init_data;
  1238. u8 abs_vport_id = 0;
  1239. int rc, i;
  1240. if (p_filter_cmd->opcode == QED_FILTER_ADD)
  1241. rc = qed_fw_vport(p_hwfn, p_filter_cmd->vport_to_add_to,
  1242. &abs_vport_id);
  1243. else
  1244. rc = qed_fw_vport(p_hwfn, p_filter_cmd->vport_to_remove_from,
  1245. &abs_vport_id);
  1246. if (rc)
  1247. return rc;
  1248. /* Get SPQ entry */
  1249. memset(&init_data, 0, sizeof(init_data));
  1250. init_data.cid = qed_spq_get_cid(p_hwfn);
  1251. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  1252. init_data.comp_mode = comp_mode;
  1253. init_data.p_comp_data = p_comp_data;
  1254. rc = qed_sp_init_request(p_hwfn, &p_ent,
  1255. ETH_RAMROD_VPORT_UPDATE,
  1256. PROTOCOLID_ETH, &init_data);
  1257. if (rc) {
  1258. DP_ERR(p_hwfn, "Multi-cast command failed %d\n", rc);
  1259. return rc;
  1260. }
  1261. p_ramrod = &p_ent->ramrod.vport_update;
  1262. p_ramrod->common.update_approx_mcast_flg = 1;
  1263. /* explicitly clear out the entire vector */
  1264. memset(&p_ramrod->approx_mcast.bins, 0,
  1265. sizeof(p_ramrod->approx_mcast.bins));
  1266. memset(bins, 0, sizeof(unsigned long) *
  1267. ETH_MULTICAST_MAC_BINS_IN_REGS);
  1268. /* filter ADD op is explicit set op and it removes
  1269. * any existing filters for the vport
  1270. */
  1271. if (p_filter_cmd->opcode == QED_FILTER_ADD) {
  1272. for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) {
  1273. u32 bit;
  1274. bit = qed_mcast_bin_from_mac(p_filter_cmd->mac[i]);
  1275. __set_bit(bit, bins);
  1276. }
  1277. /* Convert to correct endianity */
  1278. for (i = 0; i < ETH_MULTICAST_MAC_BINS_IN_REGS; i++) {
  1279. struct vport_update_ramrod_mcast *p_ramrod_bins;
  1280. u32 *p_bins = (u32 *)bins;
  1281. p_ramrod_bins = &p_ramrod->approx_mcast;
  1282. p_ramrod_bins->bins[i] = cpu_to_le32(p_bins[i]);
  1283. }
  1284. }
  1285. p_ramrod->common.vport_id = abs_vport_id;
  1286. return qed_spq_post(p_hwfn, p_ent, NULL);
  1287. }
  1288. static int qed_filter_mcast_cmd(struct qed_dev *cdev,
  1289. struct qed_filter_mcast *p_filter_cmd,
  1290. enum spq_mode comp_mode,
  1291. struct qed_spq_comp_cb *p_comp_data)
  1292. {
  1293. int rc = 0;
  1294. int i;
  1295. /* only ADD and REMOVE operations are supported for multi-cast */
  1296. if ((p_filter_cmd->opcode != QED_FILTER_ADD &&
  1297. (p_filter_cmd->opcode != QED_FILTER_REMOVE)) ||
  1298. (p_filter_cmd->num_mc_addrs > QED_MAX_MC_ADDRS))
  1299. return -EINVAL;
  1300. for_each_hwfn(cdev, i) {
  1301. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1302. u16 opaque_fid;
  1303. if (IS_VF(cdev)) {
  1304. qed_vf_pf_filter_mcast(p_hwfn, p_filter_cmd);
  1305. continue;
  1306. }
  1307. opaque_fid = p_hwfn->hw_info.opaque_fid;
  1308. rc = qed_sp_eth_filter_mcast(p_hwfn,
  1309. opaque_fid,
  1310. p_filter_cmd,
  1311. comp_mode, p_comp_data);
  1312. }
  1313. return rc;
  1314. }
  1315. static int qed_filter_ucast_cmd(struct qed_dev *cdev,
  1316. struct qed_filter_ucast *p_filter_cmd,
  1317. enum spq_mode comp_mode,
  1318. struct qed_spq_comp_cb *p_comp_data)
  1319. {
  1320. int rc = 0;
  1321. int i;
  1322. for_each_hwfn(cdev, i) {
  1323. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1324. u16 opaque_fid;
  1325. if (IS_VF(cdev)) {
  1326. rc = qed_vf_pf_filter_ucast(p_hwfn, p_filter_cmd);
  1327. continue;
  1328. }
  1329. opaque_fid = p_hwfn->hw_info.opaque_fid;
  1330. rc = qed_sp_eth_filter_ucast(p_hwfn,
  1331. opaque_fid,
  1332. p_filter_cmd,
  1333. comp_mode, p_comp_data);
  1334. if (rc)
  1335. break;
  1336. }
  1337. return rc;
  1338. }
  1339. /* Statistics related code */
  1340. static void __qed_get_vport_pstats_addrlen(struct qed_hwfn *p_hwfn,
  1341. u32 *p_addr,
  1342. u32 *p_len, u16 statistics_bin)
  1343. {
  1344. if (IS_PF(p_hwfn->cdev)) {
  1345. *p_addr = BAR0_MAP_REG_PSDM_RAM +
  1346. PSTORM_QUEUE_STAT_OFFSET(statistics_bin);
  1347. *p_len = sizeof(struct eth_pstorm_per_queue_stat);
  1348. } else {
  1349. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  1350. struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;
  1351. *p_addr = p_resp->pfdev_info.stats_info.pstats.address;
  1352. *p_len = p_resp->pfdev_info.stats_info.pstats.len;
  1353. }
  1354. }
  1355. static void __qed_get_vport_pstats(struct qed_hwfn *p_hwfn,
  1356. struct qed_ptt *p_ptt,
  1357. struct qed_eth_stats *p_stats,
  1358. u16 statistics_bin)
  1359. {
  1360. struct eth_pstorm_per_queue_stat pstats;
  1361. u32 pstats_addr = 0, pstats_len = 0;
  1362. __qed_get_vport_pstats_addrlen(p_hwfn, &pstats_addr, &pstats_len,
  1363. statistics_bin);
  1364. memset(&pstats, 0, sizeof(pstats));
  1365. qed_memcpy_from(p_hwfn, p_ptt, &pstats, pstats_addr, pstats_len);
  1366. p_stats->common.tx_ucast_bytes +=
  1367. HILO_64_REGPAIR(pstats.sent_ucast_bytes);
  1368. p_stats->common.tx_mcast_bytes +=
  1369. HILO_64_REGPAIR(pstats.sent_mcast_bytes);
  1370. p_stats->common.tx_bcast_bytes +=
  1371. HILO_64_REGPAIR(pstats.sent_bcast_bytes);
  1372. p_stats->common.tx_ucast_pkts +=
  1373. HILO_64_REGPAIR(pstats.sent_ucast_pkts);
  1374. p_stats->common.tx_mcast_pkts +=
  1375. HILO_64_REGPAIR(pstats.sent_mcast_pkts);
  1376. p_stats->common.tx_bcast_pkts +=
  1377. HILO_64_REGPAIR(pstats.sent_bcast_pkts);
  1378. p_stats->common.tx_err_drop_pkts +=
  1379. HILO_64_REGPAIR(pstats.error_drop_pkts);
  1380. }
  1381. static void __qed_get_vport_tstats(struct qed_hwfn *p_hwfn,
  1382. struct qed_ptt *p_ptt,
  1383. struct qed_eth_stats *p_stats,
  1384. u16 statistics_bin)
  1385. {
  1386. struct tstorm_per_port_stat tstats;
  1387. u32 tstats_addr, tstats_len;
  1388. if (IS_PF(p_hwfn->cdev)) {
  1389. tstats_addr = BAR0_MAP_REG_TSDM_RAM +
  1390. TSTORM_PORT_STAT_OFFSET(MFW_PORT(p_hwfn));
  1391. tstats_len = sizeof(struct tstorm_per_port_stat);
  1392. } else {
  1393. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  1394. struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;
  1395. tstats_addr = p_resp->pfdev_info.stats_info.tstats.address;
  1396. tstats_len = p_resp->pfdev_info.stats_info.tstats.len;
  1397. }
  1398. memset(&tstats, 0, sizeof(tstats));
  1399. qed_memcpy_from(p_hwfn, p_ptt, &tstats, tstats_addr, tstats_len);
  1400. p_stats->common.mftag_filter_discards +=
  1401. HILO_64_REGPAIR(tstats.mftag_filter_discard);
  1402. p_stats->common.mac_filter_discards +=
  1403. HILO_64_REGPAIR(tstats.eth_mac_filter_discard);
  1404. }
  1405. static void __qed_get_vport_ustats_addrlen(struct qed_hwfn *p_hwfn,
  1406. u32 *p_addr,
  1407. u32 *p_len, u16 statistics_bin)
  1408. {
  1409. if (IS_PF(p_hwfn->cdev)) {
  1410. *p_addr = BAR0_MAP_REG_USDM_RAM +
  1411. USTORM_QUEUE_STAT_OFFSET(statistics_bin);
  1412. *p_len = sizeof(struct eth_ustorm_per_queue_stat);
  1413. } else {
  1414. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  1415. struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;
  1416. *p_addr = p_resp->pfdev_info.stats_info.ustats.address;
  1417. *p_len = p_resp->pfdev_info.stats_info.ustats.len;
  1418. }
  1419. }
  1420. static void __qed_get_vport_ustats(struct qed_hwfn *p_hwfn,
  1421. struct qed_ptt *p_ptt,
  1422. struct qed_eth_stats *p_stats,
  1423. u16 statistics_bin)
  1424. {
  1425. struct eth_ustorm_per_queue_stat ustats;
  1426. u32 ustats_addr = 0, ustats_len = 0;
  1427. __qed_get_vport_ustats_addrlen(p_hwfn, &ustats_addr, &ustats_len,
  1428. statistics_bin);
  1429. memset(&ustats, 0, sizeof(ustats));
  1430. qed_memcpy_from(p_hwfn, p_ptt, &ustats, ustats_addr, ustats_len);
  1431. p_stats->common.rx_ucast_bytes +=
  1432. HILO_64_REGPAIR(ustats.rcv_ucast_bytes);
  1433. p_stats->common.rx_mcast_bytes +=
  1434. HILO_64_REGPAIR(ustats.rcv_mcast_bytes);
  1435. p_stats->common.rx_bcast_bytes +=
  1436. HILO_64_REGPAIR(ustats.rcv_bcast_bytes);
  1437. p_stats->common.rx_ucast_pkts += HILO_64_REGPAIR(ustats.rcv_ucast_pkts);
  1438. p_stats->common.rx_mcast_pkts += HILO_64_REGPAIR(ustats.rcv_mcast_pkts);
  1439. p_stats->common.rx_bcast_pkts += HILO_64_REGPAIR(ustats.rcv_bcast_pkts);
  1440. }
  1441. static void __qed_get_vport_mstats_addrlen(struct qed_hwfn *p_hwfn,
  1442. u32 *p_addr,
  1443. u32 *p_len, u16 statistics_bin)
  1444. {
  1445. if (IS_PF(p_hwfn->cdev)) {
  1446. *p_addr = BAR0_MAP_REG_MSDM_RAM +
  1447. MSTORM_QUEUE_STAT_OFFSET(statistics_bin);
  1448. *p_len = sizeof(struct eth_mstorm_per_queue_stat);
  1449. } else {
  1450. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  1451. struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;
  1452. *p_addr = p_resp->pfdev_info.stats_info.mstats.address;
  1453. *p_len = p_resp->pfdev_info.stats_info.mstats.len;
  1454. }
  1455. }
  1456. static void __qed_get_vport_mstats(struct qed_hwfn *p_hwfn,
  1457. struct qed_ptt *p_ptt,
  1458. struct qed_eth_stats *p_stats,
  1459. u16 statistics_bin)
  1460. {
  1461. struct eth_mstorm_per_queue_stat mstats;
  1462. u32 mstats_addr = 0, mstats_len = 0;
  1463. __qed_get_vport_mstats_addrlen(p_hwfn, &mstats_addr, &mstats_len,
  1464. statistics_bin);
  1465. memset(&mstats, 0, sizeof(mstats));
  1466. qed_memcpy_from(p_hwfn, p_ptt, &mstats, mstats_addr, mstats_len);
  1467. p_stats->common.no_buff_discards +=
  1468. HILO_64_REGPAIR(mstats.no_buff_discard);
  1469. p_stats->common.packet_too_big_discard +=
  1470. HILO_64_REGPAIR(mstats.packet_too_big_discard);
  1471. p_stats->common.ttl0_discard += HILO_64_REGPAIR(mstats.ttl0_discard);
  1472. p_stats->common.tpa_coalesced_pkts +=
  1473. HILO_64_REGPAIR(mstats.tpa_coalesced_pkts);
  1474. p_stats->common.tpa_coalesced_events +=
  1475. HILO_64_REGPAIR(mstats.tpa_coalesced_events);
  1476. p_stats->common.tpa_aborts_num +=
  1477. HILO_64_REGPAIR(mstats.tpa_aborts_num);
  1478. p_stats->common.tpa_coalesced_bytes +=
  1479. HILO_64_REGPAIR(mstats.tpa_coalesced_bytes);
  1480. }
  1481. static void __qed_get_vport_port_stats(struct qed_hwfn *p_hwfn,
  1482. struct qed_ptt *p_ptt,
  1483. struct qed_eth_stats *p_stats)
  1484. {
  1485. struct qed_eth_stats_common *p_common = &p_stats->common;
  1486. struct port_stats port_stats;
  1487. int j;
  1488. memset(&port_stats, 0, sizeof(port_stats));
  1489. qed_memcpy_from(p_hwfn, p_ptt, &port_stats,
  1490. p_hwfn->mcp_info->port_addr +
  1491. offsetof(struct public_port, stats),
  1492. sizeof(port_stats));
  1493. p_common->rx_64_byte_packets += port_stats.eth.r64;
  1494. p_common->rx_65_to_127_byte_packets += port_stats.eth.r127;
  1495. p_common->rx_128_to_255_byte_packets += port_stats.eth.r255;
  1496. p_common->rx_256_to_511_byte_packets += port_stats.eth.r511;
  1497. p_common->rx_512_to_1023_byte_packets += port_stats.eth.r1023;
  1498. p_common->rx_1024_to_1518_byte_packets += port_stats.eth.r1518;
  1499. p_common->rx_crc_errors += port_stats.eth.rfcs;
  1500. p_common->rx_mac_crtl_frames += port_stats.eth.rxcf;
  1501. p_common->rx_pause_frames += port_stats.eth.rxpf;
  1502. p_common->rx_pfc_frames += port_stats.eth.rxpp;
  1503. p_common->rx_align_errors += port_stats.eth.raln;
  1504. p_common->rx_carrier_errors += port_stats.eth.rfcr;
  1505. p_common->rx_oversize_packets += port_stats.eth.rovr;
  1506. p_common->rx_jabbers += port_stats.eth.rjbr;
  1507. p_common->rx_undersize_packets += port_stats.eth.rund;
  1508. p_common->rx_fragments += port_stats.eth.rfrg;
  1509. p_common->tx_64_byte_packets += port_stats.eth.t64;
  1510. p_common->tx_65_to_127_byte_packets += port_stats.eth.t127;
  1511. p_common->tx_128_to_255_byte_packets += port_stats.eth.t255;
  1512. p_common->tx_256_to_511_byte_packets += port_stats.eth.t511;
  1513. p_common->tx_512_to_1023_byte_packets += port_stats.eth.t1023;
  1514. p_common->tx_1024_to_1518_byte_packets += port_stats.eth.t1518;
  1515. p_common->tx_pause_frames += port_stats.eth.txpf;
  1516. p_common->tx_pfc_frames += port_stats.eth.txpp;
  1517. p_common->rx_mac_bytes += port_stats.eth.rbyte;
  1518. p_common->rx_mac_uc_packets += port_stats.eth.rxuca;
  1519. p_common->rx_mac_mc_packets += port_stats.eth.rxmca;
  1520. p_common->rx_mac_bc_packets += port_stats.eth.rxbca;
  1521. p_common->rx_mac_frames_ok += port_stats.eth.rxpok;
  1522. p_common->tx_mac_bytes += port_stats.eth.tbyte;
  1523. p_common->tx_mac_uc_packets += port_stats.eth.txuca;
  1524. p_common->tx_mac_mc_packets += port_stats.eth.txmca;
  1525. p_common->tx_mac_bc_packets += port_stats.eth.txbca;
  1526. p_common->tx_mac_ctrl_frames += port_stats.eth.txcf;
  1527. for (j = 0; j < 8; j++) {
  1528. p_common->brb_truncates += port_stats.brb.brb_truncate[j];
  1529. p_common->brb_discards += port_stats.brb.brb_discard[j];
  1530. }
  1531. if (QED_IS_BB(p_hwfn->cdev)) {
  1532. struct qed_eth_stats_bb *p_bb = &p_stats->bb;
  1533. p_bb->rx_1519_to_1522_byte_packets +=
  1534. port_stats.eth.u0.bb0.r1522;
  1535. p_bb->rx_1519_to_2047_byte_packets +=
  1536. port_stats.eth.u0.bb0.r2047;
  1537. p_bb->rx_2048_to_4095_byte_packets +=
  1538. port_stats.eth.u0.bb0.r4095;
  1539. p_bb->rx_4096_to_9216_byte_packets +=
  1540. port_stats.eth.u0.bb0.r9216;
  1541. p_bb->rx_9217_to_16383_byte_packets +=
  1542. port_stats.eth.u0.bb0.r16383;
  1543. p_bb->tx_1519_to_2047_byte_packets +=
  1544. port_stats.eth.u1.bb1.t2047;
  1545. p_bb->tx_2048_to_4095_byte_packets +=
  1546. port_stats.eth.u1.bb1.t4095;
  1547. p_bb->tx_4096_to_9216_byte_packets +=
  1548. port_stats.eth.u1.bb1.t9216;
  1549. p_bb->tx_9217_to_16383_byte_packets +=
  1550. port_stats.eth.u1.bb1.t16383;
  1551. p_bb->tx_lpi_entry_count += port_stats.eth.u2.bb2.tlpiec;
  1552. p_bb->tx_total_collisions += port_stats.eth.u2.bb2.tncl;
  1553. } else {
  1554. struct qed_eth_stats_ah *p_ah = &p_stats->ah;
  1555. p_ah->rx_1519_to_max_byte_packets +=
  1556. port_stats.eth.u0.ah0.r1519_to_max;
  1557. p_ah->tx_1519_to_max_byte_packets =
  1558. port_stats.eth.u1.ah1.t1519_to_max;
  1559. }
  1560. }
  1561. static void __qed_get_vport_stats(struct qed_hwfn *p_hwfn,
  1562. struct qed_ptt *p_ptt,
  1563. struct qed_eth_stats *stats,
  1564. u16 statistics_bin, bool b_get_port_stats)
  1565. {
  1566. __qed_get_vport_mstats(p_hwfn, p_ptt, stats, statistics_bin);
  1567. __qed_get_vport_ustats(p_hwfn, p_ptt, stats, statistics_bin);
  1568. __qed_get_vport_tstats(p_hwfn, p_ptt, stats, statistics_bin);
  1569. __qed_get_vport_pstats(p_hwfn, p_ptt, stats, statistics_bin);
  1570. if (b_get_port_stats && p_hwfn->mcp_info)
  1571. __qed_get_vport_port_stats(p_hwfn, p_ptt, stats);
  1572. }
  1573. static void _qed_get_vport_stats(struct qed_dev *cdev,
  1574. struct qed_eth_stats *stats)
  1575. {
  1576. u8 fw_vport = 0;
  1577. int i;
  1578. memset(stats, 0, sizeof(*stats));
  1579. for_each_hwfn(cdev, i) {
  1580. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1581. struct qed_ptt *p_ptt = IS_PF(cdev) ? qed_ptt_acquire(p_hwfn)
  1582. : NULL;
  1583. if (IS_PF(cdev)) {
  1584. /* The main vport index is relative first */
  1585. if (qed_fw_vport(p_hwfn, 0, &fw_vport)) {
  1586. DP_ERR(p_hwfn, "No vport available!\n");
  1587. goto out;
  1588. }
  1589. }
  1590. if (IS_PF(cdev) && !p_ptt) {
  1591. DP_ERR(p_hwfn, "Failed to acquire ptt\n");
  1592. continue;
  1593. }
  1594. __qed_get_vport_stats(p_hwfn, p_ptt, stats, fw_vport,
  1595. IS_PF(cdev) ? true : false);
  1596. out:
  1597. if (IS_PF(cdev) && p_ptt)
  1598. qed_ptt_release(p_hwfn, p_ptt);
  1599. }
  1600. }
  1601. void qed_get_vport_stats(struct qed_dev *cdev, struct qed_eth_stats *stats)
  1602. {
  1603. u32 i;
  1604. if (!cdev) {
  1605. memset(stats, 0, sizeof(*stats));
  1606. return;
  1607. }
  1608. _qed_get_vport_stats(cdev, stats);
  1609. if (!cdev->reset_stats)
  1610. return;
  1611. /* Reduce the statistics baseline */
  1612. for (i = 0; i < sizeof(struct qed_eth_stats) / sizeof(u64); i++)
  1613. ((u64 *)stats)[i] -= ((u64 *)cdev->reset_stats)[i];
  1614. }
  1615. /* zeroes V-PORT specific portion of stats (Port stats remains untouched) */
  1616. void qed_reset_vport_stats(struct qed_dev *cdev)
  1617. {
  1618. int i;
  1619. for_each_hwfn(cdev, i) {
  1620. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1621. struct eth_mstorm_per_queue_stat mstats;
  1622. struct eth_ustorm_per_queue_stat ustats;
  1623. struct eth_pstorm_per_queue_stat pstats;
  1624. struct qed_ptt *p_ptt = IS_PF(cdev) ? qed_ptt_acquire(p_hwfn)
  1625. : NULL;
  1626. u32 addr = 0, len = 0;
  1627. if (IS_PF(cdev) && !p_ptt) {
  1628. DP_ERR(p_hwfn, "Failed to acquire ptt\n");
  1629. continue;
  1630. }
  1631. memset(&mstats, 0, sizeof(mstats));
  1632. __qed_get_vport_mstats_addrlen(p_hwfn, &addr, &len, 0);
  1633. qed_memcpy_to(p_hwfn, p_ptt, addr, &mstats, len);
  1634. memset(&ustats, 0, sizeof(ustats));
  1635. __qed_get_vport_ustats_addrlen(p_hwfn, &addr, &len, 0);
  1636. qed_memcpy_to(p_hwfn, p_ptt, addr, &ustats, len);
  1637. memset(&pstats, 0, sizeof(pstats));
  1638. __qed_get_vport_pstats_addrlen(p_hwfn, &addr, &len, 0);
  1639. qed_memcpy_to(p_hwfn, p_ptt, addr, &pstats, len);
  1640. if (IS_PF(cdev))
  1641. qed_ptt_release(p_hwfn, p_ptt);
  1642. }
  1643. /* PORT statistics are not necessarily reset, so we need to
  1644. * read and create a baseline for future statistics.
  1645. */
  1646. if (!cdev->reset_stats)
  1647. DP_INFO(cdev, "Reset stats not allocated\n");
  1648. else
  1649. _qed_get_vport_stats(cdev, cdev->reset_stats);
  1650. }
  1651. static enum gft_profile_type
  1652. qed_arfs_mode_to_hsi(enum qed_filter_config_mode mode)
  1653. {
  1654. if (mode == QED_FILTER_CONFIG_MODE_5_TUPLE)
  1655. return GFT_PROFILE_TYPE_4_TUPLE;
  1656. if (mode == QED_FILTER_CONFIG_MODE_IP_DEST)
  1657. return GFT_PROFILE_TYPE_IP_DST_ADDR;
  1658. return GFT_PROFILE_TYPE_L4_DST_PORT;
  1659. }
  1660. void qed_arfs_mode_configure(struct qed_hwfn *p_hwfn,
  1661. struct qed_ptt *p_ptt,
  1662. struct qed_arfs_config_params *p_cfg_params)
  1663. {
  1664. if (p_cfg_params->mode != QED_FILTER_CONFIG_MODE_DISABLE) {
  1665. qed_gft_config(p_hwfn, p_ptt, p_hwfn->rel_pf_id,
  1666. p_cfg_params->tcp,
  1667. p_cfg_params->udp,
  1668. p_cfg_params->ipv4,
  1669. p_cfg_params->ipv6,
  1670. qed_arfs_mode_to_hsi(p_cfg_params->mode));
  1671. DP_VERBOSE(p_hwfn,
  1672. QED_MSG_SP,
  1673. "Configured Filtering: tcp = %s, udp = %s, ipv4 = %s, ipv6 =%s mode=%08x\n",
  1674. p_cfg_params->tcp ? "Enable" : "Disable",
  1675. p_cfg_params->udp ? "Enable" : "Disable",
  1676. p_cfg_params->ipv4 ? "Enable" : "Disable",
  1677. p_cfg_params->ipv6 ? "Enable" : "Disable",
  1678. (u32)p_cfg_params->mode);
  1679. } else {
  1680. DP_VERBOSE(p_hwfn, QED_MSG_SP, "Disabled Filtering\n");
  1681. qed_gft_disable(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
  1682. }
  1683. }
  1684. int
  1685. qed_configure_rfs_ntuple_filter(struct qed_hwfn *p_hwfn,
  1686. struct qed_spq_comp_cb *p_cb,
  1687. struct qed_ntuple_filter_params *p_params)
  1688. {
  1689. struct rx_update_gft_filter_data *p_ramrod = NULL;
  1690. struct qed_spq_entry *p_ent = NULL;
  1691. struct qed_sp_init_data init_data;
  1692. u16 abs_rx_q_id = 0;
  1693. u8 abs_vport_id = 0;
  1694. int rc = -EINVAL;
  1695. rc = qed_fw_vport(p_hwfn, p_params->vport_id, &abs_vport_id);
  1696. if (rc)
  1697. return rc;
  1698. if (p_params->qid != QED_RFS_NTUPLE_QID_RSS) {
  1699. rc = qed_fw_l2_queue(p_hwfn, p_params->qid, &abs_rx_q_id);
  1700. if (rc)
  1701. return rc;
  1702. }
  1703. /* Get SPQ entry */
  1704. memset(&init_data, 0, sizeof(init_data));
  1705. init_data.cid = qed_spq_get_cid(p_hwfn);
  1706. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  1707. if (p_cb) {
  1708. init_data.comp_mode = QED_SPQ_MODE_CB;
  1709. init_data.p_comp_data = p_cb;
  1710. } else {
  1711. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  1712. }
  1713. rc = qed_sp_init_request(p_hwfn, &p_ent,
  1714. ETH_RAMROD_GFT_UPDATE_FILTER,
  1715. PROTOCOLID_ETH, &init_data);
  1716. if (rc)
  1717. return rc;
  1718. p_ramrod = &p_ent->ramrod.rx_update_gft;
  1719. DMA_REGPAIR_LE(p_ramrod->pkt_hdr_addr, p_params->addr);
  1720. p_ramrod->pkt_hdr_length = cpu_to_le16(p_params->length);
  1721. if (p_params->qid != QED_RFS_NTUPLE_QID_RSS) {
  1722. p_ramrod->rx_qid_valid = 1;
  1723. p_ramrod->rx_qid = cpu_to_le16(abs_rx_q_id);
  1724. }
  1725. p_ramrod->flow_id_valid = 0;
  1726. p_ramrod->flow_id = 0;
  1727. p_ramrod->vport_id = cpu_to_le16((u16)abs_vport_id);
  1728. p_ramrod->filter_action = p_params->b_is_add ? GFT_ADD_FILTER
  1729. : GFT_DELETE_FILTER;
  1730. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  1731. "V[%0x], Q[%04x] - %s filter from 0x%llx [length %04xb]\n",
  1732. abs_vport_id, abs_rx_q_id,
  1733. p_params->b_is_add ? "Adding" : "Removing",
  1734. (u64)p_params->addr, p_params->length);
  1735. return qed_spq_post(p_hwfn, p_ent, NULL);
  1736. }
  1737. int qed_get_rxq_coalesce(struct qed_hwfn *p_hwfn,
  1738. struct qed_ptt *p_ptt,
  1739. struct qed_queue_cid *p_cid, u16 *p_rx_coal)
  1740. {
  1741. u32 coalesce, address, is_valid;
  1742. struct cau_sb_entry sb_entry;
  1743. u8 timer_res;
  1744. int rc;
  1745. rc = qed_dmae_grc2host(p_hwfn, p_ptt, CAU_REG_SB_VAR_MEMORY +
  1746. p_cid->sb_igu_id * sizeof(u64),
  1747. (u64)(uintptr_t)&sb_entry, 2, 0);
  1748. if (rc) {
  1749. DP_ERR(p_hwfn, "dmae_grc2host failed %d\n", rc);
  1750. return rc;
  1751. }
  1752. timer_res = GET_FIELD(sb_entry.params, CAU_SB_ENTRY_TIMER_RES0);
  1753. address = BAR0_MAP_REG_USDM_RAM +
  1754. USTORM_ETH_QUEUE_ZONE_OFFSET(p_cid->abs.queue_id);
  1755. coalesce = qed_rd(p_hwfn, p_ptt, address);
  1756. is_valid = GET_FIELD(coalesce, COALESCING_TIMESET_VALID);
  1757. if (!is_valid)
  1758. return -EINVAL;
  1759. coalesce = GET_FIELD(coalesce, COALESCING_TIMESET_TIMESET);
  1760. *p_rx_coal = (u16)(coalesce << timer_res);
  1761. return 0;
  1762. }
  1763. int qed_get_txq_coalesce(struct qed_hwfn *p_hwfn,
  1764. struct qed_ptt *p_ptt,
  1765. struct qed_queue_cid *p_cid, u16 *p_tx_coal)
  1766. {
  1767. u32 coalesce, address, is_valid;
  1768. struct cau_sb_entry sb_entry;
  1769. u8 timer_res;
  1770. int rc;
  1771. rc = qed_dmae_grc2host(p_hwfn, p_ptt, CAU_REG_SB_VAR_MEMORY +
  1772. p_cid->sb_igu_id * sizeof(u64),
  1773. (u64)(uintptr_t)&sb_entry, 2, 0);
  1774. if (rc) {
  1775. DP_ERR(p_hwfn, "dmae_grc2host failed %d\n", rc);
  1776. return rc;
  1777. }
  1778. timer_res = GET_FIELD(sb_entry.params, CAU_SB_ENTRY_TIMER_RES1);
  1779. address = BAR0_MAP_REG_XSDM_RAM +
  1780. XSTORM_ETH_QUEUE_ZONE_OFFSET(p_cid->abs.queue_id);
  1781. coalesce = qed_rd(p_hwfn, p_ptt, address);
  1782. is_valid = GET_FIELD(coalesce, COALESCING_TIMESET_VALID);
  1783. if (!is_valid)
  1784. return -EINVAL;
  1785. coalesce = GET_FIELD(coalesce, COALESCING_TIMESET_TIMESET);
  1786. *p_tx_coal = (u16)(coalesce << timer_res);
  1787. return 0;
  1788. }
  1789. int qed_get_queue_coalesce(struct qed_hwfn *p_hwfn, u16 *p_coal, void *handle)
  1790. {
  1791. struct qed_queue_cid *p_cid = handle;
  1792. struct qed_ptt *p_ptt;
  1793. int rc = 0;
  1794. if (IS_VF(p_hwfn->cdev)) {
  1795. rc = qed_vf_pf_get_coalesce(p_hwfn, p_coal, p_cid);
  1796. if (rc)
  1797. DP_NOTICE(p_hwfn, "Unable to read queue coalescing\n");
  1798. return rc;
  1799. }
  1800. p_ptt = qed_ptt_acquire(p_hwfn);
  1801. if (!p_ptt)
  1802. return -EAGAIN;
  1803. if (p_cid->b_is_rx) {
  1804. rc = qed_get_rxq_coalesce(p_hwfn, p_ptt, p_cid, p_coal);
  1805. if (rc)
  1806. goto out;
  1807. } else {
  1808. rc = qed_get_txq_coalesce(p_hwfn, p_ptt, p_cid, p_coal);
  1809. if (rc)
  1810. goto out;
  1811. }
  1812. out:
  1813. qed_ptt_release(p_hwfn, p_ptt);
  1814. return rc;
  1815. }
  1816. static int qed_fill_eth_dev_info(struct qed_dev *cdev,
  1817. struct qed_dev_eth_info *info)
  1818. {
  1819. int i;
  1820. memset(info, 0, sizeof(*info));
  1821. info->num_tc = 1;
  1822. if (IS_PF(cdev)) {
  1823. int max_vf_vlan_filters = 0;
  1824. int max_vf_mac_filters = 0;
  1825. if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
  1826. u16 num_queues = 0;
  1827. /* Since the feature controls only queue-zones,
  1828. * make sure we have the contexts [rx, tx, xdp] to
  1829. * match.
  1830. */
  1831. for_each_hwfn(cdev, i) {
  1832. struct qed_hwfn *hwfn = &cdev->hwfns[i];
  1833. u16 l2_queues = (u16)FEAT_NUM(hwfn,
  1834. QED_PF_L2_QUE);
  1835. u16 cids;
  1836. cids = hwfn->pf_params.eth_pf_params.num_cons;
  1837. num_queues += min_t(u16, l2_queues, cids / 3);
  1838. }
  1839. /* queues might theoretically be >256, but interrupts'
  1840. * upper-limit guarantes that it would fit in a u8.
  1841. */
  1842. if (cdev->int_params.fp_msix_cnt) {
  1843. u8 irqs = cdev->int_params.fp_msix_cnt;
  1844. info->num_queues = (u8)min_t(u16,
  1845. num_queues, irqs);
  1846. }
  1847. } else {
  1848. info->num_queues = cdev->num_hwfns;
  1849. }
  1850. if (IS_QED_SRIOV(cdev)) {
  1851. max_vf_vlan_filters = cdev->p_iov_info->total_vfs *
  1852. QED_ETH_VF_NUM_VLAN_FILTERS;
  1853. max_vf_mac_filters = cdev->p_iov_info->total_vfs *
  1854. QED_ETH_VF_NUM_MAC_FILTERS;
  1855. }
  1856. info->num_vlan_filters = RESC_NUM(QED_LEADING_HWFN(cdev),
  1857. QED_VLAN) -
  1858. max_vf_vlan_filters;
  1859. info->num_mac_filters = RESC_NUM(QED_LEADING_HWFN(cdev),
  1860. QED_MAC) -
  1861. max_vf_mac_filters;
  1862. ether_addr_copy(info->port_mac,
  1863. cdev->hwfns[0].hw_info.hw_mac_addr);
  1864. info->xdp_supported = true;
  1865. } else {
  1866. u16 total_cids = 0;
  1867. /* Determine queues & XDP support */
  1868. for_each_hwfn(cdev, i) {
  1869. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1870. u8 queues, cids;
  1871. qed_vf_get_num_cids(p_hwfn, &cids);
  1872. qed_vf_get_num_rxqs(p_hwfn, &queues);
  1873. info->num_queues += queues;
  1874. total_cids += cids;
  1875. }
  1876. /* Enable VF XDP in case PF guarntees sufficient connections */
  1877. if (total_cids >= info->num_queues * 3)
  1878. info->xdp_supported = true;
  1879. qed_vf_get_num_vlan_filters(&cdev->hwfns[0],
  1880. (u8 *)&info->num_vlan_filters);
  1881. qed_vf_get_num_mac_filters(&cdev->hwfns[0],
  1882. (u8 *)&info->num_mac_filters);
  1883. qed_vf_get_port_mac(&cdev->hwfns[0], info->port_mac);
  1884. info->is_legacy = !!cdev->hwfns[0].vf_iov_info->b_pre_fp_hsi;
  1885. }
  1886. qed_fill_dev_info(cdev, &info->common);
  1887. if (IS_VF(cdev))
  1888. eth_zero_addr(info->common.hw_mac);
  1889. return 0;
  1890. }
  1891. static void qed_register_eth_ops(struct qed_dev *cdev,
  1892. struct qed_eth_cb_ops *ops, void *cookie)
  1893. {
  1894. cdev->protocol_ops.eth = ops;
  1895. cdev->ops_cookie = cookie;
  1896. /* For VF, we start bulletin reading */
  1897. if (IS_VF(cdev))
  1898. qed_vf_start_iov_wq(cdev);
  1899. }
  1900. static bool qed_check_mac(struct qed_dev *cdev, u8 *mac)
  1901. {
  1902. if (IS_PF(cdev))
  1903. return true;
  1904. return qed_vf_check_mac(&cdev->hwfns[0], mac);
  1905. }
  1906. static int qed_start_vport(struct qed_dev *cdev,
  1907. struct qed_start_vport_params *params)
  1908. {
  1909. int rc, i;
  1910. for_each_hwfn(cdev, i) {
  1911. struct qed_sp_vport_start_params start = { 0 };
  1912. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1913. start.tpa_mode = params->gro_enable ? QED_TPA_MODE_GRO :
  1914. QED_TPA_MODE_NONE;
  1915. start.remove_inner_vlan = params->remove_inner_vlan;
  1916. start.only_untagged = true; /* untagged only */
  1917. start.drop_ttl0 = params->drop_ttl0;
  1918. start.opaque_fid = p_hwfn->hw_info.opaque_fid;
  1919. start.concrete_fid = p_hwfn->hw_info.concrete_fid;
  1920. start.handle_ptp_pkts = params->handle_ptp_pkts;
  1921. start.vport_id = params->vport_id;
  1922. start.max_buffers_per_cqe = 16;
  1923. start.mtu = params->mtu;
  1924. rc = qed_sp_vport_start(p_hwfn, &start);
  1925. if (rc) {
  1926. DP_ERR(cdev, "Failed to start VPORT\n");
  1927. return rc;
  1928. }
  1929. rc = qed_hw_start_fastpath(p_hwfn);
  1930. if (rc) {
  1931. DP_ERR(cdev, "Failed to start VPORT fastpath\n");
  1932. return rc;
  1933. }
  1934. DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
  1935. "Started V-PORT %d with MTU %d\n",
  1936. start.vport_id, start.mtu);
  1937. }
  1938. if (params->clear_stats)
  1939. qed_reset_vport_stats(cdev);
  1940. return 0;
  1941. }
  1942. static int qed_stop_vport(struct qed_dev *cdev, u8 vport_id)
  1943. {
  1944. int rc, i;
  1945. for_each_hwfn(cdev, i) {
  1946. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1947. rc = qed_sp_vport_stop(p_hwfn,
  1948. p_hwfn->hw_info.opaque_fid, vport_id);
  1949. if (rc) {
  1950. DP_ERR(cdev, "Failed to stop VPORT\n");
  1951. return rc;
  1952. }
  1953. }
  1954. return 0;
  1955. }
  1956. static int qed_update_vport_rss(struct qed_dev *cdev,
  1957. struct qed_update_vport_rss_params *input,
  1958. struct qed_rss_params *rss)
  1959. {
  1960. int i, fn;
  1961. /* Update configuration with what's correct regardless of CMT */
  1962. rss->update_rss_config = 1;
  1963. rss->rss_enable = 1;
  1964. rss->update_rss_capabilities = 1;
  1965. rss->update_rss_ind_table = 1;
  1966. rss->update_rss_key = 1;
  1967. rss->rss_caps = input->rss_caps;
  1968. memcpy(rss->rss_key, input->rss_key, QED_RSS_KEY_SIZE * sizeof(u32));
  1969. /* In regular scenario, we'd simply need to take input handlers.
  1970. * But in CMT, we'd have to split the handlers according to the
  1971. * engine they were configured on. We'd then have to understand
  1972. * whether RSS is really required, since 2-queues on CMT doesn't
  1973. * require RSS.
  1974. */
  1975. if (cdev->num_hwfns == 1) {
  1976. memcpy(rss->rss_ind_table,
  1977. input->rss_ind_table,
  1978. QED_RSS_IND_TABLE_SIZE * sizeof(void *));
  1979. rss->rss_table_size_log = 7;
  1980. return 0;
  1981. }
  1982. /* Start by copying the non-spcific information to the 2nd copy */
  1983. memcpy(&rss[1], &rss[0], sizeof(struct qed_rss_params));
  1984. /* CMT should be round-robin */
  1985. for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++) {
  1986. struct qed_queue_cid *cid = input->rss_ind_table[i];
  1987. struct qed_rss_params *t_rss;
  1988. if (cid->p_owner == QED_LEADING_HWFN(cdev))
  1989. t_rss = &rss[0];
  1990. else
  1991. t_rss = &rss[1];
  1992. t_rss->rss_ind_table[i / cdev->num_hwfns] = cid;
  1993. }
  1994. /* Make sure RSS is actually required */
  1995. for_each_hwfn(cdev, fn) {
  1996. for (i = 1; i < QED_RSS_IND_TABLE_SIZE / cdev->num_hwfns; i++) {
  1997. if (rss[fn].rss_ind_table[i] !=
  1998. rss[fn].rss_ind_table[0])
  1999. break;
  2000. }
  2001. if (i == QED_RSS_IND_TABLE_SIZE / cdev->num_hwfns) {
  2002. DP_VERBOSE(cdev, NETIF_MSG_IFUP,
  2003. "CMT - 1 queue per-hwfn; Disabling RSS\n");
  2004. return -EINVAL;
  2005. }
  2006. rss[fn].rss_table_size_log = 6;
  2007. }
  2008. return 0;
  2009. }
  2010. static int qed_update_vport(struct qed_dev *cdev,
  2011. struct qed_update_vport_params *params)
  2012. {
  2013. struct qed_sp_vport_update_params sp_params;
  2014. struct qed_rss_params *rss;
  2015. int rc = 0, i;
  2016. if (!cdev)
  2017. return -ENODEV;
  2018. rss = vzalloc(sizeof(*rss) * cdev->num_hwfns);
  2019. if (!rss)
  2020. return -ENOMEM;
  2021. memset(&sp_params, 0, sizeof(sp_params));
  2022. /* Translate protocol params into sp params */
  2023. sp_params.vport_id = params->vport_id;
  2024. sp_params.update_vport_active_rx_flg = params->update_vport_active_flg;
  2025. sp_params.update_vport_active_tx_flg = params->update_vport_active_flg;
  2026. sp_params.vport_active_rx_flg = params->vport_active_flg;
  2027. sp_params.vport_active_tx_flg = params->vport_active_flg;
  2028. sp_params.update_tx_switching_flg = params->update_tx_switching_flg;
  2029. sp_params.tx_switching_flg = params->tx_switching_flg;
  2030. sp_params.accept_any_vlan = params->accept_any_vlan;
  2031. sp_params.update_accept_any_vlan_flg =
  2032. params->update_accept_any_vlan_flg;
  2033. /* Prepare the RSS configuration */
  2034. if (params->update_rss_flg)
  2035. if (qed_update_vport_rss(cdev, &params->rss_params, rss))
  2036. params->update_rss_flg = 0;
  2037. for_each_hwfn(cdev, i) {
  2038. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  2039. if (params->update_rss_flg)
  2040. sp_params.rss_params = &rss[i];
  2041. sp_params.opaque_fid = p_hwfn->hw_info.opaque_fid;
  2042. rc = qed_sp_vport_update(p_hwfn, &sp_params,
  2043. QED_SPQ_MODE_EBLOCK,
  2044. NULL);
  2045. if (rc) {
  2046. DP_ERR(cdev, "Failed to update VPORT\n");
  2047. goto out;
  2048. }
  2049. DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
  2050. "Updated V-PORT %d: active_flag %d [update %d]\n",
  2051. params->vport_id, params->vport_active_flg,
  2052. params->update_vport_active_flg);
  2053. }
  2054. out:
  2055. vfree(rss);
  2056. return rc;
  2057. }
  2058. static int qed_start_rxq(struct qed_dev *cdev,
  2059. u8 rss_num,
  2060. struct qed_queue_start_common_params *p_params,
  2061. u16 bd_max_bytes,
  2062. dma_addr_t bd_chain_phys_addr,
  2063. dma_addr_t cqe_pbl_addr,
  2064. u16 cqe_pbl_size,
  2065. struct qed_rxq_start_ret_params *ret_params)
  2066. {
  2067. struct qed_hwfn *p_hwfn;
  2068. int rc, hwfn_index;
  2069. hwfn_index = rss_num % cdev->num_hwfns;
  2070. p_hwfn = &cdev->hwfns[hwfn_index];
  2071. p_params->queue_id = p_params->queue_id / cdev->num_hwfns;
  2072. p_params->stats_id = p_params->vport_id;
  2073. rc = qed_eth_rx_queue_start(p_hwfn,
  2074. p_hwfn->hw_info.opaque_fid,
  2075. p_params,
  2076. bd_max_bytes,
  2077. bd_chain_phys_addr,
  2078. cqe_pbl_addr, cqe_pbl_size, ret_params);
  2079. if (rc) {
  2080. DP_ERR(cdev, "Failed to start RXQ#%d\n", p_params->queue_id);
  2081. return rc;
  2082. }
  2083. DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
  2084. "Started RX-Q %d [rss_num %d] on V-PORT %d and SB igu %d\n",
  2085. p_params->queue_id, rss_num, p_params->vport_id,
  2086. p_params->p_sb->igu_sb_id);
  2087. return 0;
  2088. }
  2089. static int qed_stop_rxq(struct qed_dev *cdev, u8 rss_id, void *handle)
  2090. {
  2091. int rc, hwfn_index;
  2092. struct qed_hwfn *p_hwfn;
  2093. hwfn_index = rss_id % cdev->num_hwfns;
  2094. p_hwfn = &cdev->hwfns[hwfn_index];
  2095. rc = qed_eth_rx_queue_stop(p_hwfn, handle, false, false);
  2096. if (rc) {
  2097. DP_ERR(cdev, "Failed to stop RXQ#%02x\n", rss_id);
  2098. return rc;
  2099. }
  2100. return 0;
  2101. }
  2102. static int qed_start_txq(struct qed_dev *cdev,
  2103. u8 rss_num,
  2104. struct qed_queue_start_common_params *p_params,
  2105. dma_addr_t pbl_addr,
  2106. u16 pbl_size,
  2107. struct qed_txq_start_ret_params *ret_params)
  2108. {
  2109. struct qed_hwfn *p_hwfn;
  2110. int rc, hwfn_index;
  2111. hwfn_index = rss_num % cdev->num_hwfns;
  2112. p_hwfn = &cdev->hwfns[hwfn_index];
  2113. p_params->queue_id = p_params->queue_id / cdev->num_hwfns;
  2114. p_params->stats_id = p_params->vport_id;
  2115. rc = qed_eth_tx_queue_start(p_hwfn,
  2116. p_hwfn->hw_info.opaque_fid,
  2117. p_params, 0,
  2118. pbl_addr, pbl_size, ret_params);
  2119. if (rc) {
  2120. DP_ERR(cdev, "Failed to start TXQ#%d\n", p_params->queue_id);
  2121. return rc;
  2122. }
  2123. DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
  2124. "Started TX-Q %d [rss_num %d] on V-PORT %d and SB igu %d\n",
  2125. p_params->queue_id, rss_num, p_params->vport_id,
  2126. p_params->p_sb->igu_sb_id);
  2127. return 0;
  2128. }
  2129. #define QED_HW_STOP_RETRY_LIMIT (10)
  2130. static int qed_fastpath_stop(struct qed_dev *cdev)
  2131. {
  2132. int rc;
  2133. rc = qed_hw_stop_fastpath(cdev);
  2134. if (rc) {
  2135. DP_ERR(cdev, "Failed to stop Fastpath\n");
  2136. return rc;
  2137. }
  2138. return 0;
  2139. }
  2140. static int qed_stop_txq(struct qed_dev *cdev, u8 rss_id, void *handle)
  2141. {
  2142. struct qed_hwfn *p_hwfn;
  2143. int rc, hwfn_index;
  2144. hwfn_index = rss_id % cdev->num_hwfns;
  2145. p_hwfn = &cdev->hwfns[hwfn_index];
  2146. rc = qed_eth_tx_queue_stop(p_hwfn, handle);
  2147. if (rc) {
  2148. DP_ERR(cdev, "Failed to stop TXQ#%02x\n", rss_id);
  2149. return rc;
  2150. }
  2151. return 0;
  2152. }
  2153. static int qed_tunn_configure(struct qed_dev *cdev,
  2154. struct qed_tunn_params *tunn_params)
  2155. {
  2156. struct qed_tunnel_info tunn_info;
  2157. int i, rc;
  2158. memset(&tunn_info, 0, sizeof(tunn_info));
  2159. if (tunn_params->update_vxlan_port) {
  2160. tunn_info.vxlan_port.b_update_port = true;
  2161. tunn_info.vxlan_port.port = tunn_params->vxlan_port;
  2162. }
  2163. if (tunn_params->update_geneve_port) {
  2164. tunn_info.geneve_port.b_update_port = true;
  2165. tunn_info.geneve_port.port = tunn_params->geneve_port;
  2166. }
  2167. for_each_hwfn(cdev, i) {
  2168. struct qed_hwfn *hwfn = &cdev->hwfns[i];
  2169. struct qed_ptt *p_ptt;
  2170. struct qed_tunnel_info *tun;
  2171. tun = &hwfn->cdev->tunnel;
  2172. if (IS_PF(cdev)) {
  2173. p_ptt = qed_ptt_acquire(hwfn);
  2174. if (!p_ptt)
  2175. return -EAGAIN;
  2176. } else {
  2177. p_ptt = NULL;
  2178. }
  2179. rc = qed_sp_pf_update_tunn_cfg(hwfn, p_ptt, &tunn_info,
  2180. QED_SPQ_MODE_EBLOCK, NULL);
  2181. if (rc) {
  2182. if (IS_PF(cdev))
  2183. qed_ptt_release(hwfn, p_ptt);
  2184. return rc;
  2185. }
  2186. if (IS_PF_SRIOV(hwfn)) {
  2187. u16 vxlan_port, geneve_port;
  2188. int j;
  2189. vxlan_port = tun->vxlan_port.port;
  2190. geneve_port = tun->geneve_port.port;
  2191. qed_for_each_vf(hwfn, j) {
  2192. qed_iov_bulletin_set_udp_ports(hwfn, j,
  2193. vxlan_port,
  2194. geneve_port);
  2195. }
  2196. qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
  2197. }
  2198. if (IS_PF(cdev))
  2199. qed_ptt_release(hwfn, p_ptt);
  2200. }
  2201. return 0;
  2202. }
  2203. static int qed_configure_filter_rx_mode(struct qed_dev *cdev,
  2204. enum qed_filter_rx_mode_type type)
  2205. {
  2206. struct qed_filter_accept_flags accept_flags;
  2207. memset(&accept_flags, 0, sizeof(accept_flags));
  2208. accept_flags.update_rx_mode_config = 1;
  2209. accept_flags.update_tx_mode_config = 1;
  2210. accept_flags.rx_accept_filter = QED_ACCEPT_UCAST_MATCHED |
  2211. QED_ACCEPT_MCAST_MATCHED |
  2212. QED_ACCEPT_BCAST;
  2213. accept_flags.tx_accept_filter = QED_ACCEPT_UCAST_MATCHED |
  2214. QED_ACCEPT_MCAST_MATCHED |
  2215. QED_ACCEPT_BCAST;
  2216. if (type == QED_FILTER_RX_MODE_TYPE_PROMISC) {
  2217. accept_flags.rx_accept_filter |= QED_ACCEPT_UCAST_UNMATCHED |
  2218. QED_ACCEPT_MCAST_UNMATCHED;
  2219. accept_flags.tx_accept_filter |= QED_ACCEPT_MCAST_UNMATCHED;
  2220. } else if (type == QED_FILTER_RX_MODE_TYPE_MULTI_PROMISC) {
  2221. accept_flags.rx_accept_filter |= QED_ACCEPT_MCAST_UNMATCHED;
  2222. accept_flags.tx_accept_filter |= QED_ACCEPT_MCAST_UNMATCHED;
  2223. }
  2224. return qed_filter_accept_cmd(cdev, 0, accept_flags, false, false,
  2225. QED_SPQ_MODE_CB, NULL);
  2226. }
  2227. static int qed_configure_filter_ucast(struct qed_dev *cdev,
  2228. struct qed_filter_ucast_params *params)
  2229. {
  2230. struct qed_filter_ucast ucast;
  2231. if (!params->vlan_valid && !params->mac_valid) {
  2232. DP_NOTICE(cdev,
  2233. "Tried configuring a unicast filter, but both MAC and VLAN are not set\n");
  2234. return -EINVAL;
  2235. }
  2236. memset(&ucast, 0, sizeof(ucast));
  2237. switch (params->type) {
  2238. case QED_FILTER_XCAST_TYPE_ADD:
  2239. ucast.opcode = QED_FILTER_ADD;
  2240. break;
  2241. case QED_FILTER_XCAST_TYPE_DEL:
  2242. ucast.opcode = QED_FILTER_REMOVE;
  2243. break;
  2244. case QED_FILTER_XCAST_TYPE_REPLACE:
  2245. ucast.opcode = QED_FILTER_REPLACE;
  2246. break;
  2247. default:
  2248. DP_NOTICE(cdev, "Unknown unicast filter type %d\n",
  2249. params->type);
  2250. }
  2251. if (params->vlan_valid && params->mac_valid) {
  2252. ucast.type = QED_FILTER_MAC_VLAN;
  2253. ether_addr_copy(ucast.mac, params->mac);
  2254. ucast.vlan = params->vlan;
  2255. } else if (params->mac_valid) {
  2256. ucast.type = QED_FILTER_MAC;
  2257. ether_addr_copy(ucast.mac, params->mac);
  2258. } else {
  2259. ucast.type = QED_FILTER_VLAN;
  2260. ucast.vlan = params->vlan;
  2261. }
  2262. ucast.is_rx_filter = true;
  2263. ucast.is_tx_filter = true;
  2264. return qed_filter_ucast_cmd(cdev, &ucast, QED_SPQ_MODE_CB, NULL);
  2265. }
  2266. static int qed_configure_filter_mcast(struct qed_dev *cdev,
  2267. struct qed_filter_mcast_params *params)
  2268. {
  2269. struct qed_filter_mcast mcast;
  2270. int i;
  2271. memset(&mcast, 0, sizeof(mcast));
  2272. switch (params->type) {
  2273. case QED_FILTER_XCAST_TYPE_ADD:
  2274. mcast.opcode = QED_FILTER_ADD;
  2275. break;
  2276. case QED_FILTER_XCAST_TYPE_DEL:
  2277. mcast.opcode = QED_FILTER_REMOVE;
  2278. break;
  2279. default:
  2280. DP_NOTICE(cdev, "Unknown multicast filter type %d\n",
  2281. params->type);
  2282. }
  2283. mcast.num_mc_addrs = params->num;
  2284. for (i = 0; i < mcast.num_mc_addrs; i++)
  2285. ether_addr_copy(mcast.mac[i], params->mac[i]);
  2286. return qed_filter_mcast_cmd(cdev, &mcast, QED_SPQ_MODE_CB, NULL);
  2287. }
  2288. static int qed_configure_filter(struct qed_dev *cdev,
  2289. struct qed_filter_params *params)
  2290. {
  2291. enum qed_filter_rx_mode_type accept_flags;
  2292. switch (params->type) {
  2293. case QED_FILTER_TYPE_UCAST:
  2294. return qed_configure_filter_ucast(cdev, &params->filter.ucast);
  2295. case QED_FILTER_TYPE_MCAST:
  2296. return qed_configure_filter_mcast(cdev, &params->filter.mcast);
  2297. case QED_FILTER_TYPE_RX_MODE:
  2298. accept_flags = params->filter.accept_flags;
  2299. return qed_configure_filter_rx_mode(cdev, accept_flags);
  2300. default:
  2301. DP_NOTICE(cdev, "Unknown filter type %d\n", (int)params->type);
  2302. return -EINVAL;
  2303. }
  2304. }
  2305. static int qed_configure_arfs_searcher(struct qed_dev *cdev,
  2306. enum qed_filter_config_mode mode)
  2307. {
  2308. struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
  2309. struct qed_arfs_config_params arfs_config_params;
  2310. memset(&arfs_config_params, 0, sizeof(arfs_config_params));
  2311. arfs_config_params.tcp = true;
  2312. arfs_config_params.udp = true;
  2313. arfs_config_params.ipv4 = true;
  2314. arfs_config_params.ipv6 = true;
  2315. arfs_config_params.mode = mode;
  2316. qed_arfs_mode_configure(p_hwfn, p_hwfn->p_arfs_ptt,
  2317. &arfs_config_params);
  2318. return 0;
  2319. }
  2320. static void
  2321. qed_arfs_sp_response_handler(struct qed_hwfn *p_hwfn,
  2322. void *cookie,
  2323. union event_ring_data *data, u8 fw_return_code)
  2324. {
  2325. struct qed_common_cb_ops *op = p_hwfn->cdev->protocol_ops.common;
  2326. void *dev = p_hwfn->cdev->ops_cookie;
  2327. op->arfs_filter_op(dev, cookie, fw_return_code);
  2328. }
  2329. static int
  2330. qed_ntuple_arfs_filter_config(struct qed_dev *cdev,
  2331. void *cookie,
  2332. struct qed_ntuple_filter_params *params)
  2333. {
  2334. struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
  2335. struct qed_spq_comp_cb cb;
  2336. int rc = -EINVAL;
  2337. cb.function = qed_arfs_sp_response_handler;
  2338. cb.cookie = cookie;
  2339. if (params->b_is_vf) {
  2340. if (!qed_iov_is_valid_vfid(p_hwfn, params->vf_id, false,
  2341. false)) {
  2342. DP_INFO(p_hwfn, "vfid 0x%02x is out of bounds\n",
  2343. params->vf_id);
  2344. return rc;
  2345. }
  2346. params->vport_id = params->vf_id + 1;
  2347. params->qid = QED_RFS_NTUPLE_QID_RSS;
  2348. }
  2349. rc = qed_configure_rfs_ntuple_filter(p_hwfn, &cb, params);
  2350. if (rc)
  2351. DP_NOTICE(p_hwfn,
  2352. "Failed to issue a-RFS filter configuration\n");
  2353. else
  2354. DP_VERBOSE(p_hwfn, NETIF_MSG_DRV,
  2355. "Successfully issued a-RFS filter configuration\n");
  2356. return rc;
  2357. }
  2358. static int qed_get_coalesce(struct qed_dev *cdev, u16 *coal, void *handle)
  2359. {
  2360. struct qed_queue_cid *p_cid = handle;
  2361. struct qed_hwfn *p_hwfn;
  2362. int rc;
  2363. p_hwfn = p_cid->p_owner;
  2364. rc = qed_get_queue_coalesce(p_hwfn, coal, handle);
  2365. if (rc)
  2366. DP_NOTICE(p_hwfn, "Unable to read queue coalescing\n");
  2367. return rc;
  2368. }
  2369. static int qed_fp_cqe_completion(struct qed_dev *dev,
  2370. u8 rss_id, struct eth_slow_path_rx_cqe *cqe)
  2371. {
  2372. return qed_eth_cqe_completion(&dev->hwfns[rss_id % dev->num_hwfns],
  2373. cqe);
  2374. }
  2375. #ifdef CONFIG_QED_SRIOV
  2376. extern const struct qed_iov_hv_ops qed_iov_ops_pass;
  2377. #endif
  2378. #ifdef CONFIG_DCB
  2379. extern const struct qed_eth_dcbnl_ops qed_dcbnl_ops_pass;
  2380. #endif
  2381. extern const struct qed_eth_ptp_ops qed_ptp_ops_pass;
  2382. static const struct qed_eth_ops qed_eth_ops_pass = {
  2383. .common = &qed_common_ops_pass,
  2384. #ifdef CONFIG_QED_SRIOV
  2385. .iov = &qed_iov_ops_pass,
  2386. #endif
  2387. #ifdef CONFIG_DCB
  2388. .dcb = &qed_dcbnl_ops_pass,
  2389. #endif
  2390. .ptp = &qed_ptp_ops_pass,
  2391. .fill_dev_info = &qed_fill_eth_dev_info,
  2392. .register_ops = &qed_register_eth_ops,
  2393. .check_mac = &qed_check_mac,
  2394. .vport_start = &qed_start_vport,
  2395. .vport_stop = &qed_stop_vport,
  2396. .vport_update = &qed_update_vport,
  2397. .q_rx_start = &qed_start_rxq,
  2398. .q_rx_stop = &qed_stop_rxq,
  2399. .q_tx_start = &qed_start_txq,
  2400. .q_tx_stop = &qed_stop_txq,
  2401. .filter_config = &qed_configure_filter,
  2402. .fastpath_stop = &qed_fastpath_stop,
  2403. .eth_cqe_completion = &qed_fp_cqe_completion,
  2404. .get_vport_stats = &qed_get_vport_stats,
  2405. .tunn_config = &qed_tunn_configure,
  2406. .ntuple_filter_config = &qed_ntuple_arfs_filter_config,
  2407. .configure_arfs_searcher = &qed_configure_arfs_searcher,
  2408. .get_coalesce = &qed_get_coalesce,
  2409. };
  2410. const struct qed_eth_ops *qed_get_eth_ops(void)
  2411. {
  2412. return &qed_eth_ops_pass;
  2413. }
  2414. EXPORT_SYMBOL(qed_get_eth_ops);
  2415. void qed_put_eth_ops(void)
  2416. {
  2417. /* TODO - reference count for module? */
  2418. }
  2419. EXPORT_SYMBOL(qed_put_eth_ops);