1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288 |
- /* QLogic qede NIC Driver
- * Copyright (c) 2015 QLogic Corporation
- *
- * This software is available under the terms of the GNU General Public License
- * (GPL) Version 2, available from the file COPYING in the main directory of
- * this source tree.
- */
- #include <linux/module.h>
- #include <linux/pci.h>
- #include <linux/version.h>
- #include <linux/device.h>
- #include <linux/netdevice.h>
- #include <linux/etherdevice.h>
- #include <linux/skbuff.h>
- #include <linux/errno.h>
- #include <linux/list.h>
- #include <linux/string.h>
- #include <linux/dma-mapping.h>
- #include <linux/interrupt.h>
- #include <asm/byteorder.h>
- #include <asm/param.h>
- #include <linux/io.h>
- #include <linux/netdev_features.h>
- #include <linux/udp.h>
- #include <linux/tcp.h>
- #include <net/udp_tunnel.h>
- #include <linux/ip.h>
- #include <net/ipv6.h>
- #include <net/tcp.h>
- #include <linux/if_ether.h>
- #include <linux/if_vlan.h>
- #include <linux/pkt_sched.h>
- #include <linux/ethtool.h>
- #include <linux/in.h>
- #include <linux/random.h>
- #include <net/ip6_checksum.h>
- #include <linux/bitops.h>
- #include <linux/qed/qede_roce.h>
- #include "qede.h"
- static char version[] =
- "QLogic FastLinQ 4xxxx Ethernet Driver qede " DRV_MODULE_VERSION "\n";
- MODULE_DESCRIPTION("QLogic FastLinQ 4xxxx Ethernet Driver");
- MODULE_LICENSE("GPL");
- MODULE_VERSION(DRV_MODULE_VERSION);
- static uint debug;
- module_param(debug, uint, 0);
- MODULE_PARM_DESC(debug, " Default debug msglevel");
- static const struct qed_eth_ops *qed_ops;
- #define CHIP_NUM_57980S_40 0x1634
- #define CHIP_NUM_57980S_10 0x1666
- #define CHIP_NUM_57980S_MF 0x1636
- #define CHIP_NUM_57980S_100 0x1644
- #define CHIP_NUM_57980S_50 0x1654
- #define CHIP_NUM_57980S_25 0x1656
- #define CHIP_NUM_57980S_IOV 0x1664
- #ifndef PCI_DEVICE_ID_NX2_57980E
- #define PCI_DEVICE_ID_57980S_40 CHIP_NUM_57980S_40
- #define PCI_DEVICE_ID_57980S_10 CHIP_NUM_57980S_10
- #define PCI_DEVICE_ID_57980S_MF CHIP_NUM_57980S_MF
- #define PCI_DEVICE_ID_57980S_100 CHIP_NUM_57980S_100
- #define PCI_DEVICE_ID_57980S_50 CHIP_NUM_57980S_50
- #define PCI_DEVICE_ID_57980S_25 CHIP_NUM_57980S_25
- #define PCI_DEVICE_ID_57980S_IOV CHIP_NUM_57980S_IOV
- #endif
- enum qede_pci_private {
- QEDE_PRIVATE_PF,
- QEDE_PRIVATE_VF
- };
- static const struct pci_device_id qede_pci_tbl[] = {
- {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_40), QEDE_PRIVATE_PF},
- {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_10), QEDE_PRIVATE_PF},
- {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_MF), QEDE_PRIVATE_PF},
- {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_100), QEDE_PRIVATE_PF},
- {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_50), QEDE_PRIVATE_PF},
- {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_25), QEDE_PRIVATE_PF},
- #ifdef CONFIG_QED_SRIOV
- {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_IOV), QEDE_PRIVATE_VF},
- #endif
- { 0 }
- };
- MODULE_DEVICE_TABLE(pci, qede_pci_tbl);
- static int qede_probe(struct pci_dev *pdev, const struct pci_device_id *id);
- #define TX_TIMEOUT (5 * HZ)
- /* Utilize last protocol index for XDP */
- #define XDP_PI 11
- static void qede_remove(struct pci_dev *pdev);
- static void qede_shutdown(struct pci_dev *pdev);
- static void qede_link_update(void *dev, struct qed_link_output *link);
- /* The qede lock is used to protect driver state change and driver flows that
- * are not reentrant.
- */
- void __qede_lock(struct qede_dev *edev)
- {
- mutex_lock(&edev->qede_lock);
- }
- void __qede_unlock(struct qede_dev *edev)
- {
- mutex_unlock(&edev->qede_lock);
- }
- #ifdef CONFIG_QED_SRIOV
- static int qede_set_vf_vlan(struct net_device *ndev, int vf, u16 vlan, u8 qos,
- __be16 vlan_proto)
- {
- struct qede_dev *edev = netdev_priv(ndev);
- if (vlan > 4095) {
- DP_NOTICE(edev, "Illegal vlan value %d\n", vlan);
- return -EINVAL;
- }
- if (vlan_proto != htons(ETH_P_8021Q))
- return -EPROTONOSUPPORT;
- DP_VERBOSE(edev, QED_MSG_IOV, "Setting Vlan 0x%04x to VF [%d]\n",
- vlan, vf);
- return edev->ops->iov->set_vlan(edev->cdev, vlan, vf);
- }
- static int qede_set_vf_mac(struct net_device *ndev, int vfidx, u8 *mac)
- {
- struct qede_dev *edev = netdev_priv(ndev);
- DP_VERBOSE(edev, QED_MSG_IOV,
- "Setting MAC %02x:%02x:%02x:%02x:%02x:%02x to VF [%d]\n",
- mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], vfidx);
- if (!is_valid_ether_addr(mac)) {
- DP_VERBOSE(edev, QED_MSG_IOV, "MAC address isn't valid\n");
- return -EINVAL;
- }
- return edev->ops->iov->set_mac(edev->cdev, mac, vfidx);
- }
- static int qede_sriov_configure(struct pci_dev *pdev, int num_vfs_param)
- {
- struct qede_dev *edev = netdev_priv(pci_get_drvdata(pdev));
- struct qed_dev_info *qed_info = &edev->dev_info.common;
- int rc;
- DP_VERBOSE(edev, QED_MSG_IOV, "Requested %d VFs\n", num_vfs_param);
- rc = edev->ops->iov->configure(edev->cdev, num_vfs_param);
- /* Enable/Disable Tx switching for PF */
- if ((rc == num_vfs_param) && netif_running(edev->ndev) &&
- qed_info->mf_mode != QED_MF_NPAR && qed_info->tx_switching) {
- struct qed_update_vport_params params;
- memset(¶ms, 0, sizeof(params));
- params.vport_id = 0;
- params.update_tx_switching_flg = 1;
- params.tx_switching_flg = num_vfs_param ? 1 : 0;
- edev->ops->vport_update(edev->cdev, ¶ms);
- }
- return rc;
- }
- #endif
- static struct pci_driver qede_pci_driver = {
- .name = "qede",
- .id_table = qede_pci_tbl,
- .probe = qede_probe,
- .remove = qede_remove,
- .shutdown = qede_shutdown,
- #ifdef CONFIG_QED_SRIOV
- .sriov_configure = qede_sriov_configure,
- #endif
- };
- static void qede_force_mac(void *dev, u8 *mac, bool forced)
- {
- struct qede_dev *edev = dev;
- /* MAC hints take effect only if we haven't set one already */
- if (is_valid_ether_addr(edev->ndev->dev_addr) && !forced)
- return;
- ether_addr_copy(edev->ndev->dev_addr, mac);
- ether_addr_copy(edev->primary_mac, mac);
- }
- static struct qed_eth_cb_ops qede_ll_ops = {
- {
- .link_update = qede_link_update,
- },
- .force_mac = qede_force_mac,
- };
- static int qede_netdev_event(struct notifier_block *this, unsigned long event,
- void *ptr)
- {
- struct net_device *ndev = netdev_notifier_info_to_dev(ptr);
- struct ethtool_drvinfo drvinfo;
- struct qede_dev *edev;
- if (event != NETDEV_CHANGENAME && event != NETDEV_CHANGEADDR)
- goto done;
- /* Check whether this is a qede device */
- if (!ndev || !ndev->ethtool_ops || !ndev->ethtool_ops->get_drvinfo)
- goto done;
- memset(&drvinfo, 0, sizeof(drvinfo));
- ndev->ethtool_ops->get_drvinfo(ndev, &drvinfo);
- if (strcmp(drvinfo.driver, "qede"))
- goto done;
- edev = netdev_priv(ndev);
- switch (event) {
- case NETDEV_CHANGENAME:
- /* Notify qed of the name change */
- if (!edev->ops || !edev->ops->common)
- goto done;
- edev->ops->common->set_id(edev->cdev, edev->ndev->name, "qede");
- break;
- case NETDEV_CHANGEADDR:
- edev = netdev_priv(ndev);
- qede_roce_event_changeaddr(edev);
- break;
- }
- done:
- return NOTIFY_DONE;
- }
- static struct notifier_block qede_netdev_notifier = {
- .notifier_call = qede_netdev_event,
- };
- static
- int __init qede_init(void)
- {
- int ret;
- pr_info("qede_init: %s\n", version);
- qed_ops = qed_get_eth_ops();
- if (!qed_ops) {
- pr_notice("Failed to get qed ethtool operations\n");
- return -EINVAL;
- }
- /* Must register notifier before pci ops, since we might miss
- * interface rename after pci probe and netdev registeration.
- */
- ret = register_netdevice_notifier(&qede_netdev_notifier);
- if (ret) {
- pr_notice("Failed to register netdevice_notifier\n");
- qed_put_eth_ops();
- return -EINVAL;
- }
- ret = pci_register_driver(&qede_pci_driver);
- if (ret) {
- pr_notice("Failed to register driver\n");
- unregister_netdevice_notifier(&qede_netdev_notifier);
- qed_put_eth_ops();
- return -EINVAL;
- }
- return 0;
- }
- static void __exit qede_cleanup(void)
- {
- if (debug & QED_LOG_INFO_MASK)
- pr_info("qede_cleanup called\n");
- unregister_netdevice_notifier(&qede_netdev_notifier);
- pci_unregister_driver(&qede_pci_driver);
- qed_put_eth_ops();
- }
- module_init(qede_init);
- module_exit(qede_cleanup);
- /* -------------------------------------------------------------------------
- * START OF FAST-PATH
- * -------------------------------------------------------------------------
- */
- /* Unmap the data and free skb */
- static int qede_free_tx_pkt(struct qede_dev *edev,
- struct qede_tx_queue *txq, int *len)
- {
- u16 idx = txq->sw_tx_cons & NUM_TX_BDS_MAX;
- struct sk_buff *skb = txq->sw_tx_ring.skbs[idx].skb;
- struct eth_tx_1st_bd *first_bd;
- struct eth_tx_bd *tx_data_bd;
- int bds_consumed = 0;
- int nbds;
- bool data_split = txq->sw_tx_ring.skbs[idx].flags & QEDE_TSO_SPLIT_BD;
- int i, split_bd_len = 0;
- if (unlikely(!skb)) {
- DP_ERR(edev,
- "skb is null for txq idx=%d txq->sw_tx_cons=%d txq->sw_tx_prod=%d\n",
- idx, txq->sw_tx_cons, txq->sw_tx_prod);
- return -1;
- }
- *len = skb->len;
- first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
- bds_consumed++;
- nbds = first_bd->data.nbds;
- if (data_split) {
- struct eth_tx_bd *split = (struct eth_tx_bd *)
- qed_chain_consume(&txq->tx_pbl);
- split_bd_len = BD_UNMAP_LEN(split);
- bds_consumed++;
- }
- dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
- BD_UNMAP_LEN(first_bd) + split_bd_len, DMA_TO_DEVICE);
- /* Unmap the data of the skb frags */
- for (i = 0; i < skb_shinfo(skb)->nr_frags; i++, bds_consumed++) {
- tx_data_bd = (struct eth_tx_bd *)
- qed_chain_consume(&txq->tx_pbl);
- dma_unmap_page(&edev->pdev->dev, BD_UNMAP_ADDR(tx_data_bd),
- BD_UNMAP_LEN(tx_data_bd), DMA_TO_DEVICE);
- }
- while (bds_consumed++ < nbds)
- qed_chain_consume(&txq->tx_pbl);
- /* Free skb */
- dev_kfree_skb_any(skb);
- txq->sw_tx_ring.skbs[idx].skb = NULL;
- txq->sw_tx_ring.skbs[idx].flags = 0;
- return 0;
- }
- /* Unmap the data and free skb when mapping failed during start_xmit */
- static void qede_free_failed_tx_pkt(struct qede_tx_queue *txq,
- struct eth_tx_1st_bd *first_bd,
- int nbd, bool data_split)
- {
- u16 idx = txq->sw_tx_prod & NUM_TX_BDS_MAX;
- struct sk_buff *skb = txq->sw_tx_ring.skbs[idx].skb;
- struct eth_tx_bd *tx_data_bd;
- int i, split_bd_len = 0;
- /* Return prod to its position before this skb was handled */
- qed_chain_set_prod(&txq->tx_pbl,
- le16_to_cpu(txq->tx_db.data.bd_prod), first_bd);
- first_bd = (struct eth_tx_1st_bd *)qed_chain_produce(&txq->tx_pbl);
- if (data_split) {
- struct eth_tx_bd *split = (struct eth_tx_bd *)
- qed_chain_produce(&txq->tx_pbl);
- split_bd_len = BD_UNMAP_LEN(split);
- nbd--;
- }
- dma_unmap_single(txq->dev, BD_UNMAP_ADDR(first_bd),
- BD_UNMAP_LEN(first_bd) + split_bd_len, DMA_TO_DEVICE);
- /* Unmap the data of the skb frags */
- for (i = 0; i < nbd; i++) {
- tx_data_bd = (struct eth_tx_bd *)
- qed_chain_produce(&txq->tx_pbl);
- if (tx_data_bd->nbytes)
- dma_unmap_page(txq->dev,
- BD_UNMAP_ADDR(tx_data_bd),
- BD_UNMAP_LEN(tx_data_bd), DMA_TO_DEVICE);
- }
- /* Return again prod to its position before this skb was handled */
- qed_chain_set_prod(&txq->tx_pbl,
- le16_to_cpu(txq->tx_db.data.bd_prod), first_bd);
- /* Free skb */
- dev_kfree_skb_any(skb);
- txq->sw_tx_ring.skbs[idx].skb = NULL;
- txq->sw_tx_ring.skbs[idx].flags = 0;
- }
- static u32 qede_xmit_type(struct sk_buff *skb, int *ipv6_ext)
- {
- u32 rc = XMIT_L4_CSUM;
- __be16 l3_proto;
- if (skb->ip_summed != CHECKSUM_PARTIAL)
- return XMIT_PLAIN;
- l3_proto = vlan_get_protocol(skb);
- if (l3_proto == htons(ETH_P_IPV6) &&
- (ipv6_hdr(skb)->nexthdr == NEXTHDR_IPV6))
- *ipv6_ext = 1;
- if (skb->encapsulation) {
- rc |= XMIT_ENC;
- if (skb_is_gso(skb)) {
- unsigned short gso_type = skb_shinfo(skb)->gso_type;
- if ((gso_type & SKB_GSO_UDP_TUNNEL_CSUM) ||
- (gso_type & SKB_GSO_GRE_CSUM))
- rc |= XMIT_ENC_GSO_L4_CSUM;
- rc |= XMIT_LSO;
- return rc;
- }
- }
- if (skb_is_gso(skb))
- rc |= XMIT_LSO;
- return rc;
- }
- static void qede_set_params_for_ipv6_ext(struct sk_buff *skb,
- struct eth_tx_2nd_bd *second_bd,
- struct eth_tx_3rd_bd *third_bd)
- {
- u8 l4_proto;
- u16 bd2_bits1 = 0, bd2_bits2 = 0;
- bd2_bits1 |= (1 << ETH_TX_DATA_2ND_BD_IPV6_EXT_SHIFT);
- bd2_bits2 |= ((((u8 *)skb_transport_header(skb) - skb->data) >> 1) &
- ETH_TX_DATA_2ND_BD_L4_HDR_START_OFFSET_W_MASK)
- << ETH_TX_DATA_2ND_BD_L4_HDR_START_OFFSET_W_SHIFT;
- bd2_bits1 |= (ETH_L4_PSEUDO_CSUM_CORRECT_LENGTH <<
- ETH_TX_DATA_2ND_BD_L4_PSEUDO_CSUM_MODE_SHIFT);
- if (vlan_get_protocol(skb) == htons(ETH_P_IPV6))
- l4_proto = ipv6_hdr(skb)->nexthdr;
- else
- l4_proto = ip_hdr(skb)->protocol;
- if (l4_proto == IPPROTO_UDP)
- bd2_bits1 |= 1 << ETH_TX_DATA_2ND_BD_L4_UDP_SHIFT;
- if (third_bd)
- third_bd->data.bitfields |=
- cpu_to_le16(((tcp_hdrlen(skb) / 4) &
- ETH_TX_DATA_3RD_BD_TCP_HDR_LEN_DW_MASK) <<
- ETH_TX_DATA_3RD_BD_TCP_HDR_LEN_DW_SHIFT);
- second_bd->data.bitfields1 = cpu_to_le16(bd2_bits1);
- second_bd->data.bitfields2 = cpu_to_le16(bd2_bits2);
- }
- static int map_frag_to_bd(struct qede_tx_queue *txq,
- skb_frag_t *frag, struct eth_tx_bd *bd)
- {
- dma_addr_t mapping;
- /* Map skb non-linear frag data for DMA */
- mapping = skb_frag_dma_map(txq->dev, frag, 0,
- skb_frag_size(frag), DMA_TO_DEVICE);
- if (unlikely(dma_mapping_error(txq->dev, mapping)))
- return -ENOMEM;
- /* Setup the data pointer of the frag data */
- BD_SET_UNMAP_ADDR_LEN(bd, mapping, skb_frag_size(frag));
- return 0;
- }
- static u16 qede_get_skb_hlen(struct sk_buff *skb, bool is_encap_pkt)
- {
- if (is_encap_pkt)
- return (skb_inner_transport_header(skb) +
- inner_tcp_hdrlen(skb) - skb->data);
- else
- return (skb_transport_header(skb) +
- tcp_hdrlen(skb) - skb->data);
- }
- /* +2 for 1st BD for headers and 2nd BD for headlen (if required) */
- #if ((MAX_SKB_FRAGS + 2) > ETH_TX_MAX_BDS_PER_NON_LSO_PACKET)
- static bool qede_pkt_req_lin(struct sk_buff *skb, u8 xmit_type)
- {
- int allowed_frags = ETH_TX_MAX_BDS_PER_NON_LSO_PACKET - 1;
- if (xmit_type & XMIT_LSO) {
- int hlen;
- hlen = qede_get_skb_hlen(skb, xmit_type & XMIT_ENC);
- /* linear payload would require its own BD */
- if (skb_headlen(skb) > hlen)
- allowed_frags--;
- }
- return (skb_shinfo(skb)->nr_frags > allowed_frags);
- }
- #endif
- static inline void qede_update_tx_producer(struct qede_tx_queue *txq)
- {
- /* wmb makes sure that the BDs data is updated before updating the
- * producer, otherwise FW may read old data from the BDs.
- */
- wmb();
- barrier();
- writel(txq->tx_db.raw, txq->doorbell_addr);
- /* mmiowb is needed to synchronize doorbell writes from more than one
- * processor. It guarantees that the write arrives to the device before
- * the queue lock is released and another start_xmit is called (possibly
- * on another CPU). Without this barrier, the next doorbell can bypass
- * this doorbell. This is applicable to IA64/Altix systems.
- */
- mmiowb();
- }
- static int qede_xdp_xmit(struct qede_dev *edev, struct qede_fastpath *fp,
- struct sw_rx_data *metadata, u16 padding, u16 length)
- {
- struct qede_tx_queue *txq = fp->xdp_tx;
- u16 idx = txq->sw_tx_prod & NUM_TX_BDS_MAX;
- struct eth_tx_1st_bd *first_bd;
- if (!qed_chain_get_elem_left(&txq->tx_pbl)) {
- txq->stopped_cnt++;
- return -ENOMEM;
- }
- first_bd = (struct eth_tx_1st_bd *)qed_chain_produce(&txq->tx_pbl);
- memset(first_bd, 0, sizeof(*first_bd));
- first_bd->data.bd_flags.bitfields =
- BIT(ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT);
- first_bd->data.bitfields |=
- (length & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK) <<
- ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT;
- first_bd->data.nbds = 1;
- /* We can safely ignore the offset, as it's 0 for XDP */
- BD_SET_UNMAP_ADDR_LEN(first_bd, metadata->mapping + padding, length);
- /* Synchronize the buffer back to device, as program [probably]
- * has changed it.
- */
- dma_sync_single_for_device(&edev->pdev->dev,
- metadata->mapping + padding,
- length, PCI_DMA_TODEVICE);
- txq->sw_tx_ring.pages[idx] = metadata->data;
- txq->sw_tx_prod++;
- /* Mark the fastpath for future XDP doorbell */
- fp->xdp_xmit = 1;
- return 0;
- }
- /* Main transmit function */
- static netdev_tx_t qede_start_xmit(struct sk_buff *skb,
- struct net_device *ndev)
- {
- struct qede_dev *edev = netdev_priv(ndev);
- struct netdev_queue *netdev_txq;
- struct qede_tx_queue *txq;
- struct eth_tx_1st_bd *first_bd;
- struct eth_tx_2nd_bd *second_bd = NULL;
- struct eth_tx_3rd_bd *third_bd = NULL;
- struct eth_tx_bd *tx_data_bd = NULL;
- u16 txq_index;
- u8 nbd = 0;
- dma_addr_t mapping;
- int rc, frag_idx = 0, ipv6_ext = 0;
- u8 xmit_type;
- u16 idx;
- u16 hlen;
- bool data_split = false;
- /* Get tx-queue context and netdev index */
- txq_index = skb_get_queue_mapping(skb);
- WARN_ON(txq_index >= QEDE_TSS_COUNT(edev));
- txq = edev->fp_array[edev->fp_num_rx + txq_index].txq;
- netdev_txq = netdev_get_tx_queue(ndev, txq_index);
- WARN_ON(qed_chain_get_elem_left(&txq->tx_pbl) < (MAX_SKB_FRAGS + 1));
- xmit_type = qede_xmit_type(skb, &ipv6_ext);
- #if ((MAX_SKB_FRAGS + 2) > ETH_TX_MAX_BDS_PER_NON_LSO_PACKET)
- if (qede_pkt_req_lin(skb, xmit_type)) {
- if (skb_linearize(skb)) {
- DP_NOTICE(edev,
- "SKB linearization failed - silently dropping this SKB\n");
- dev_kfree_skb_any(skb);
- return NETDEV_TX_OK;
- }
- }
- #endif
- /* Fill the entry in the SW ring and the BDs in the FW ring */
- idx = txq->sw_tx_prod & NUM_TX_BDS_MAX;
- txq->sw_tx_ring.skbs[idx].skb = skb;
- first_bd = (struct eth_tx_1st_bd *)
- qed_chain_produce(&txq->tx_pbl);
- memset(first_bd, 0, sizeof(*first_bd));
- first_bd->data.bd_flags.bitfields =
- 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
- /* Map skb linear data for DMA and set in the first BD */
- mapping = dma_map_single(txq->dev, skb->data,
- skb_headlen(skb), DMA_TO_DEVICE);
- if (unlikely(dma_mapping_error(txq->dev, mapping))) {
- DP_NOTICE(edev, "SKB mapping failed\n");
- qede_free_failed_tx_pkt(txq, first_bd, 0, false);
- qede_update_tx_producer(txq);
- return NETDEV_TX_OK;
- }
- nbd++;
- BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
- /* In case there is IPv6 with extension headers or LSO we need 2nd and
- * 3rd BDs.
- */
- if (unlikely((xmit_type & XMIT_LSO) | ipv6_ext)) {
- second_bd = (struct eth_tx_2nd_bd *)
- qed_chain_produce(&txq->tx_pbl);
- memset(second_bd, 0, sizeof(*second_bd));
- nbd++;
- third_bd = (struct eth_tx_3rd_bd *)
- qed_chain_produce(&txq->tx_pbl);
- memset(third_bd, 0, sizeof(*third_bd));
- nbd++;
- /* We need to fill in additional data in second_bd... */
- tx_data_bd = (struct eth_tx_bd *)second_bd;
- }
- if (skb_vlan_tag_present(skb)) {
- first_bd->data.vlan = cpu_to_le16(skb_vlan_tag_get(skb));
- first_bd->data.bd_flags.bitfields |=
- 1 << ETH_TX_1ST_BD_FLAGS_VLAN_INSERTION_SHIFT;
- }
- /* Fill the parsing flags & params according to the requested offload */
- if (xmit_type & XMIT_L4_CSUM) {
- /* We don't re-calculate IP checksum as it is already done by
- * the upper stack
- */
- first_bd->data.bd_flags.bitfields |=
- 1 << ETH_TX_1ST_BD_FLAGS_L4_CSUM_SHIFT;
- if (xmit_type & XMIT_ENC) {
- first_bd->data.bd_flags.bitfields |=
- 1 << ETH_TX_1ST_BD_FLAGS_IP_CSUM_SHIFT;
- first_bd->data.bitfields |=
- 1 << ETH_TX_DATA_1ST_BD_TUNN_FLAG_SHIFT;
- }
- /* Legacy FW had flipped behavior in regard to this bit -
- * I.e., needed to set to prevent FW from touching encapsulated
- * packets when it didn't need to.
- */
- if (unlikely(txq->is_legacy))
- first_bd->data.bitfields ^=
- 1 << ETH_TX_DATA_1ST_BD_TUNN_FLAG_SHIFT;
- /* If the packet is IPv6 with extension header, indicate that
- * to FW and pass few params, since the device cracker doesn't
- * support parsing IPv6 with extension header/s.
- */
- if (unlikely(ipv6_ext))
- qede_set_params_for_ipv6_ext(skb, second_bd, third_bd);
- }
- if (xmit_type & XMIT_LSO) {
- first_bd->data.bd_flags.bitfields |=
- (1 << ETH_TX_1ST_BD_FLAGS_LSO_SHIFT);
- third_bd->data.lso_mss =
- cpu_to_le16(skb_shinfo(skb)->gso_size);
- if (unlikely(xmit_type & XMIT_ENC)) {
- first_bd->data.bd_flags.bitfields |=
- 1 << ETH_TX_1ST_BD_FLAGS_TUNN_IP_CSUM_SHIFT;
- if (xmit_type & XMIT_ENC_GSO_L4_CSUM) {
- u8 tmp = ETH_TX_1ST_BD_FLAGS_TUNN_L4_CSUM_SHIFT;
- first_bd->data.bd_flags.bitfields |= 1 << tmp;
- }
- hlen = qede_get_skb_hlen(skb, true);
- } else {
- first_bd->data.bd_flags.bitfields |=
- 1 << ETH_TX_1ST_BD_FLAGS_IP_CSUM_SHIFT;
- hlen = qede_get_skb_hlen(skb, false);
- }
- /* @@@TBD - if will not be removed need to check */
- third_bd->data.bitfields |=
- cpu_to_le16((1 << ETH_TX_DATA_3RD_BD_HDR_NBD_SHIFT));
- /* Make life easier for FW guys who can't deal with header and
- * data on same BD. If we need to split, use the second bd...
- */
- if (unlikely(skb_headlen(skb) > hlen)) {
- DP_VERBOSE(edev, NETIF_MSG_TX_QUEUED,
- "TSO split header size is %d (%x:%x)\n",
- first_bd->nbytes, first_bd->addr.hi,
- first_bd->addr.lo);
- mapping = HILO_U64(le32_to_cpu(first_bd->addr.hi),
- le32_to_cpu(first_bd->addr.lo)) +
- hlen;
- BD_SET_UNMAP_ADDR_LEN(tx_data_bd, mapping,
- le16_to_cpu(first_bd->nbytes) -
- hlen);
- /* this marks the BD as one that has no
- * individual mapping
- */
- txq->sw_tx_ring.skbs[idx].flags |= QEDE_TSO_SPLIT_BD;
- first_bd->nbytes = cpu_to_le16(hlen);
- tx_data_bd = (struct eth_tx_bd *)third_bd;
- data_split = true;
- }
- } else {
- first_bd->data.bitfields |=
- (skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK) <<
- ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT;
- }
- /* Handle fragmented skb */
- /* special handle for frags inside 2nd and 3rd bds.. */
- while (tx_data_bd && frag_idx < skb_shinfo(skb)->nr_frags) {
- rc = map_frag_to_bd(txq,
- &skb_shinfo(skb)->frags[frag_idx],
- tx_data_bd);
- if (rc) {
- qede_free_failed_tx_pkt(txq, first_bd, nbd, data_split);
- qede_update_tx_producer(txq);
- return NETDEV_TX_OK;
- }
- if (tx_data_bd == (struct eth_tx_bd *)second_bd)
- tx_data_bd = (struct eth_tx_bd *)third_bd;
- else
- tx_data_bd = NULL;
- frag_idx++;
- }
- /* map last frags into 4th, 5th .... */
- for (; frag_idx < skb_shinfo(skb)->nr_frags; frag_idx++, nbd++) {
- tx_data_bd = (struct eth_tx_bd *)
- qed_chain_produce(&txq->tx_pbl);
- memset(tx_data_bd, 0, sizeof(*tx_data_bd));
- rc = map_frag_to_bd(txq,
- &skb_shinfo(skb)->frags[frag_idx],
- tx_data_bd);
- if (rc) {
- qede_free_failed_tx_pkt(txq, first_bd, nbd, data_split);
- qede_update_tx_producer(txq);
- return NETDEV_TX_OK;
- }
- }
- /* update the first BD with the actual num BDs */
- first_bd->data.nbds = nbd;
- netdev_tx_sent_queue(netdev_txq, skb->len);
- skb_tx_timestamp(skb);
- /* Advance packet producer only before sending the packet since mapping
- * of pages may fail.
- */
- txq->sw_tx_prod++;
- /* 'next page' entries are counted in the producer value */
- txq->tx_db.data.bd_prod =
- cpu_to_le16(qed_chain_get_prod_idx(&txq->tx_pbl));
- if (!skb->xmit_more || netif_xmit_stopped(netdev_txq))
- qede_update_tx_producer(txq);
- if (unlikely(qed_chain_get_elem_left(&txq->tx_pbl)
- < (MAX_SKB_FRAGS + 1))) {
- if (skb->xmit_more)
- qede_update_tx_producer(txq);
- netif_tx_stop_queue(netdev_txq);
- txq->stopped_cnt++;
- DP_VERBOSE(edev, NETIF_MSG_TX_QUEUED,
- "Stop queue was called\n");
- /* paired memory barrier is in qede_tx_int(), we have to keep
- * ordering of set_bit() in netif_tx_stop_queue() and read of
- * fp->bd_tx_cons
- */
- smp_mb();
- if (qed_chain_get_elem_left(&txq->tx_pbl)
- >= (MAX_SKB_FRAGS + 1) &&
- (edev->state == QEDE_STATE_OPEN)) {
- netif_tx_wake_queue(netdev_txq);
- DP_VERBOSE(edev, NETIF_MSG_TX_QUEUED,
- "Wake queue was called\n");
- }
- }
- return NETDEV_TX_OK;
- }
- int qede_txq_has_work(struct qede_tx_queue *txq)
- {
- u16 hw_bd_cons;
- /* Tell compiler that consumer and producer can change */
- barrier();
- hw_bd_cons = le16_to_cpu(*txq->hw_cons_ptr);
- if (qed_chain_get_cons_idx(&txq->tx_pbl) == hw_bd_cons + 1)
- return 0;
- return hw_bd_cons != qed_chain_get_cons_idx(&txq->tx_pbl);
- }
- static void qede_xdp_tx_int(struct qede_dev *edev, struct qede_tx_queue *txq)
- {
- struct eth_tx_1st_bd *bd;
- u16 hw_bd_cons;
- hw_bd_cons = le16_to_cpu(*txq->hw_cons_ptr);
- barrier();
- while (hw_bd_cons != qed_chain_get_cons_idx(&txq->tx_pbl)) {
- bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
- dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(bd),
- PAGE_SIZE, DMA_BIDIRECTIONAL);
- __free_page(txq->sw_tx_ring.pages[txq->sw_tx_cons &
- NUM_TX_BDS_MAX]);
- txq->sw_tx_cons++;
- txq->xmit_pkts++;
- }
- }
- static int qede_tx_int(struct qede_dev *edev, struct qede_tx_queue *txq)
- {
- struct netdev_queue *netdev_txq;
- u16 hw_bd_cons;
- unsigned int pkts_compl = 0, bytes_compl = 0;
- int rc;
- netdev_txq = netdev_get_tx_queue(edev->ndev, txq->index);
- hw_bd_cons = le16_to_cpu(*txq->hw_cons_ptr);
- barrier();
- while (hw_bd_cons != qed_chain_get_cons_idx(&txq->tx_pbl)) {
- int len = 0;
- rc = qede_free_tx_pkt(edev, txq, &len);
- if (rc) {
- DP_NOTICE(edev, "hw_bd_cons = %d, chain_cons=%d\n",
- hw_bd_cons,
- qed_chain_get_cons_idx(&txq->tx_pbl));
- break;
- }
- bytes_compl += len;
- pkts_compl++;
- txq->sw_tx_cons++;
- txq->xmit_pkts++;
- }
- netdev_tx_completed_queue(netdev_txq, pkts_compl, bytes_compl);
- /* Need to make the tx_bd_cons update visible to start_xmit()
- * before checking for netif_tx_queue_stopped(). Without the
- * memory barrier, there is a small possibility that
- * start_xmit() will miss it and cause the queue to be stopped
- * forever.
- * On the other hand we need an rmb() here to ensure the proper
- * ordering of bit testing in the following
- * netif_tx_queue_stopped(txq) call.
- */
- smp_mb();
- if (unlikely(netif_tx_queue_stopped(netdev_txq))) {
- /* Taking tx_lock is needed to prevent reenabling the queue
- * while it's empty. This could have happen if rx_action() gets
- * suspended in qede_tx_int() after the condition before
- * netif_tx_wake_queue(), while tx_action (qede_start_xmit()):
- *
- * stops the queue->sees fresh tx_bd_cons->releases the queue->
- * sends some packets consuming the whole queue again->
- * stops the queue
- */
- __netif_tx_lock(netdev_txq, smp_processor_id());
- if ((netif_tx_queue_stopped(netdev_txq)) &&
- (edev->state == QEDE_STATE_OPEN) &&
- (qed_chain_get_elem_left(&txq->tx_pbl)
- >= (MAX_SKB_FRAGS + 1))) {
- netif_tx_wake_queue(netdev_txq);
- DP_VERBOSE(edev, NETIF_MSG_TX_DONE,
- "Wake queue was called\n");
- }
- __netif_tx_unlock(netdev_txq);
- }
- return 0;
- }
- bool qede_has_rx_work(struct qede_rx_queue *rxq)
- {
- u16 hw_comp_cons, sw_comp_cons;
- /* Tell compiler that status block fields can change */
- barrier();
- hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr);
- sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
- return hw_comp_cons != sw_comp_cons;
- }
- static inline void qede_rx_bd_ring_consume(struct qede_rx_queue *rxq)
- {
- qed_chain_consume(&rxq->rx_bd_ring);
- rxq->sw_rx_cons++;
- }
- /* This function reuses the buffer(from an offset) from
- * consumer index to producer index in the bd ring
- */
- static inline void qede_reuse_page(struct qede_rx_queue *rxq,
- struct sw_rx_data *curr_cons)
- {
- struct eth_rx_bd *rx_bd_prod = qed_chain_produce(&rxq->rx_bd_ring);
- struct sw_rx_data *curr_prod;
- dma_addr_t new_mapping;
- curr_prod = &rxq->sw_rx_ring[rxq->sw_rx_prod & NUM_RX_BDS_MAX];
- *curr_prod = *curr_cons;
- new_mapping = curr_prod->mapping + curr_prod->page_offset;
- rx_bd_prod->addr.hi = cpu_to_le32(upper_32_bits(new_mapping));
- rx_bd_prod->addr.lo = cpu_to_le32(lower_32_bits(new_mapping));
- rxq->sw_rx_prod++;
- curr_cons->data = NULL;
- }
- /* In case of allocation failures reuse buffers
- * from consumer index to produce buffers for firmware
- */
- void qede_recycle_rx_bd_ring(struct qede_rx_queue *rxq, u8 count)
- {
- struct sw_rx_data *curr_cons;
- for (; count > 0; count--) {
- curr_cons = &rxq->sw_rx_ring[rxq->sw_rx_cons & NUM_RX_BDS_MAX];
- qede_reuse_page(rxq, curr_cons);
- qede_rx_bd_ring_consume(rxq);
- }
- }
- static int qede_alloc_rx_buffer(struct qede_rx_queue *rxq)
- {
- struct sw_rx_data *sw_rx_data;
- struct eth_rx_bd *rx_bd;
- dma_addr_t mapping;
- struct page *data;
- data = alloc_pages(GFP_ATOMIC, 0);
- if (unlikely(!data))
- return -ENOMEM;
- /* Map the entire page as it would be used
- * for multiple RX buffer segment size mapping.
- */
- mapping = dma_map_page(rxq->dev, data, 0,
- PAGE_SIZE, rxq->data_direction);
- if (unlikely(dma_mapping_error(rxq->dev, mapping))) {
- __free_page(data);
- return -ENOMEM;
- }
- sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_prod & NUM_RX_BDS_MAX];
- sw_rx_data->page_offset = 0;
- sw_rx_data->data = data;
- sw_rx_data->mapping = mapping;
- /* Advance PROD and get BD pointer */
- rx_bd = (struct eth_rx_bd *)qed_chain_produce(&rxq->rx_bd_ring);
- WARN_ON(!rx_bd);
- rx_bd->addr.hi = cpu_to_le32(upper_32_bits(mapping));
- rx_bd->addr.lo = cpu_to_le32(lower_32_bits(mapping));
- rxq->sw_rx_prod++;
- return 0;
- }
- static inline int qede_realloc_rx_buffer(struct qede_rx_queue *rxq,
- struct sw_rx_data *curr_cons)
- {
- /* Move to the next segment in the page */
- curr_cons->page_offset += rxq->rx_buf_seg_size;
- if (curr_cons->page_offset == PAGE_SIZE) {
- if (unlikely(qede_alloc_rx_buffer(rxq))) {
- /* Since we failed to allocate new buffer
- * current buffer can be used again.
- */
- curr_cons->page_offset -= rxq->rx_buf_seg_size;
- return -ENOMEM;
- }
- dma_unmap_page(rxq->dev, curr_cons->mapping,
- PAGE_SIZE, rxq->data_direction);
- } else {
- /* Increment refcount of the page as we don't want
- * network stack to take the ownership of the page
- * which can be recycled multiple times by the driver.
- */
- page_ref_inc(curr_cons->data);
- qede_reuse_page(rxq, curr_cons);
- }
- return 0;
- }
- void qede_update_rx_prod(struct qede_dev *edev, struct qede_rx_queue *rxq)
- {
- u16 bd_prod = qed_chain_get_prod_idx(&rxq->rx_bd_ring);
- u16 cqe_prod = qed_chain_get_prod_idx(&rxq->rx_comp_ring);
- struct eth_rx_prod_data rx_prods = {0};
- /* Update producers */
- rx_prods.bd_prod = cpu_to_le16(bd_prod);
- rx_prods.cqe_prod = cpu_to_le16(cqe_prod);
- /* Make sure that the BD and SGE data is updated before updating the
- * producers since FW might read the BD/SGE right after the producer
- * is updated.
- */
- wmb();
- internal_ram_wr(rxq->hw_rxq_prod_addr, sizeof(rx_prods),
- (u32 *)&rx_prods);
- /* mmiowb is needed to synchronize doorbell writes from more than one
- * processor. It guarantees that the write arrives to the device before
- * the napi lock is released and another qede_poll is called (possibly
- * on another CPU). Without this barrier, the next doorbell can bypass
- * this doorbell. This is applicable to IA64/Altix systems.
- */
- mmiowb();
- }
- static void qede_get_rxhash(struct sk_buff *skb, u8 bitfields, __le32 rss_hash)
- {
- enum pkt_hash_types hash_type = PKT_HASH_TYPE_NONE;
- enum rss_hash_type htype;
- u32 hash = 0;
- htype = GET_FIELD(bitfields, ETH_FAST_PATH_RX_REG_CQE_RSS_HASH_TYPE);
- if (htype) {
- hash_type = ((htype == RSS_HASH_TYPE_IPV4) ||
- (htype == RSS_HASH_TYPE_IPV6)) ?
- PKT_HASH_TYPE_L3 : PKT_HASH_TYPE_L4;
- hash = le32_to_cpu(rss_hash);
- }
- skb_set_hash(skb, hash, hash_type);
- }
- static void qede_set_skb_csum(struct sk_buff *skb, u8 csum_flag)
- {
- skb_checksum_none_assert(skb);
- if (csum_flag & QEDE_CSUM_UNNECESSARY)
- skb->ip_summed = CHECKSUM_UNNECESSARY;
- if (csum_flag & QEDE_TUNN_CSUM_UNNECESSARY)
- skb->csum_level = 1;
- }
- static inline void qede_skb_receive(struct qede_dev *edev,
- struct qede_fastpath *fp,
- struct qede_rx_queue *rxq,
- struct sk_buff *skb, u16 vlan_tag)
- {
- if (vlan_tag)
- __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan_tag);
- napi_gro_receive(&fp->napi, skb);
- fp->rxq->rcv_pkts++;
- }
- static void qede_set_gro_params(struct qede_dev *edev,
- struct sk_buff *skb,
- struct eth_fast_path_rx_tpa_start_cqe *cqe)
- {
- u16 parsing_flags = le16_to_cpu(cqe->pars_flags.flags);
- if (((parsing_flags >> PARSING_AND_ERR_FLAGS_L3TYPE_SHIFT) &
- PARSING_AND_ERR_FLAGS_L3TYPE_MASK) == 2)
- skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
- else
- skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
- skb_shinfo(skb)->gso_size = __le16_to_cpu(cqe->len_on_first_bd) -
- cqe->header_len;
- }
- static int qede_fill_frag_skb(struct qede_dev *edev,
- struct qede_rx_queue *rxq,
- u8 tpa_agg_index, u16 len_on_bd)
- {
- struct sw_rx_data *current_bd = &rxq->sw_rx_ring[rxq->sw_rx_cons &
- NUM_RX_BDS_MAX];
- struct qede_agg_info *tpa_info = &rxq->tpa_info[tpa_agg_index];
- struct sk_buff *skb = tpa_info->skb;
- if (unlikely(tpa_info->state != QEDE_AGG_STATE_START))
- goto out;
- /* Add one frag and update the appropriate fields in the skb */
- skb_fill_page_desc(skb, tpa_info->frag_id++,
- current_bd->data, current_bd->page_offset,
- len_on_bd);
- if (unlikely(qede_realloc_rx_buffer(rxq, current_bd))) {
- /* Incr page ref count to reuse on allocation failure
- * so that it doesn't get freed while freeing SKB.
- */
- page_ref_inc(current_bd->data);
- goto out;
- }
- qed_chain_consume(&rxq->rx_bd_ring);
- rxq->sw_rx_cons++;
- skb->data_len += len_on_bd;
- skb->truesize += rxq->rx_buf_seg_size;
- skb->len += len_on_bd;
- return 0;
- out:
- tpa_info->state = QEDE_AGG_STATE_ERROR;
- qede_recycle_rx_bd_ring(rxq, 1);
- return -ENOMEM;
- }
- static void qede_tpa_start(struct qede_dev *edev,
- struct qede_rx_queue *rxq,
- struct eth_fast_path_rx_tpa_start_cqe *cqe)
- {
- struct qede_agg_info *tpa_info = &rxq->tpa_info[cqe->tpa_agg_index];
- struct eth_rx_bd *rx_bd_cons = qed_chain_consume(&rxq->rx_bd_ring);
- struct eth_rx_bd *rx_bd_prod = qed_chain_produce(&rxq->rx_bd_ring);
- struct sw_rx_data *replace_buf = &tpa_info->buffer;
- dma_addr_t mapping = tpa_info->buffer_mapping;
- struct sw_rx_data *sw_rx_data_cons;
- struct sw_rx_data *sw_rx_data_prod;
- sw_rx_data_cons = &rxq->sw_rx_ring[rxq->sw_rx_cons & NUM_RX_BDS_MAX];
- sw_rx_data_prod = &rxq->sw_rx_ring[rxq->sw_rx_prod & NUM_RX_BDS_MAX];
- /* Use pre-allocated replacement buffer - we can't release the agg.
- * start until its over and we don't want to risk allocation failing
- * here, so re-allocate when aggregation will be over.
- */
- sw_rx_data_prod->mapping = replace_buf->mapping;
- sw_rx_data_prod->data = replace_buf->data;
- rx_bd_prod->addr.hi = cpu_to_le32(upper_32_bits(mapping));
- rx_bd_prod->addr.lo = cpu_to_le32(lower_32_bits(mapping));
- sw_rx_data_prod->page_offset = replace_buf->page_offset;
- rxq->sw_rx_prod++;
- /* move partial skb from cons to pool (don't unmap yet)
- * save mapping, incase we drop the packet later on.
- */
- tpa_info->buffer = *sw_rx_data_cons;
- mapping = HILO_U64(le32_to_cpu(rx_bd_cons->addr.hi),
- le32_to_cpu(rx_bd_cons->addr.lo));
- tpa_info->buffer_mapping = mapping;
- rxq->sw_rx_cons++;
- /* set tpa state to start only if we are able to allocate skb
- * for this aggregation, otherwise mark as error and aggregation will
- * be dropped
- */
- tpa_info->skb = netdev_alloc_skb(edev->ndev,
- le16_to_cpu(cqe->len_on_first_bd));
- if (unlikely(!tpa_info->skb)) {
- DP_NOTICE(edev, "Failed to allocate SKB for gro\n");
- tpa_info->state = QEDE_AGG_STATE_ERROR;
- goto cons_buf;
- }
- /* Start filling in the aggregation info */
- skb_put(tpa_info->skb, le16_to_cpu(cqe->len_on_first_bd));
- tpa_info->frag_id = 0;
- tpa_info->state = QEDE_AGG_STATE_START;
- /* Store some information from first CQE */
- tpa_info->start_cqe_placement_offset = cqe->placement_offset;
- tpa_info->start_cqe_bd_len = le16_to_cpu(cqe->len_on_first_bd);
- if ((le16_to_cpu(cqe->pars_flags.flags) >>
- PARSING_AND_ERR_FLAGS_TAG8021QEXIST_SHIFT) &
- PARSING_AND_ERR_FLAGS_TAG8021QEXIST_MASK)
- tpa_info->vlan_tag = le16_to_cpu(cqe->vlan_tag);
- else
- tpa_info->vlan_tag = 0;
- qede_get_rxhash(tpa_info->skb, cqe->bitfields, cqe->rss_hash);
- /* This is needed in order to enable forwarding support */
- qede_set_gro_params(edev, tpa_info->skb, cqe);
- cons_buf: /* We still need to handle bd_len_list to consume buffers */
- if (likely(cqe->ext_bd_len_list[0]))
- qede_fill_frag_skb(edev, rxq, cqe->tpa_agg_index,
- le16_to_cpu(cqe->ext_bd_len_list[0]));
- if (unlikely(cqe->ext_bd_len_list[1])) {
- DP_ERR(edev,
- "Unlikely - got a TPA aggregation with more than one ext_bd_len_list entry in the TPA start\n");
- tpa_info->state = QEDE_AGG_STATE_ERROR;
- }
- }
- #ifdef CONFIG_INET
- static void qede_gro_ip_csum(struct sk_buff *skb)
- {
- const struct iphdr *iph = ip_hdr(skb);
- struct tcphdr *th;
- skb_set_transport_header(skb, sizeof(struct iphdr));
- th = tcp_hdr(skb);
- th->check = ~tcp_v4_check(skb->len - skb_transport_offset(skb),
- iph->saddr, iph->daddr, 0);
- tcp_gro_complete(skb);
- }
- static void qede_gro_ipv6_csum(struct sk_buff *skb)
- {
- struct ipv6hdr *iph = ipv6_hdr(skb);
- struct tcphdr *th;
- skb_set_transport_header(skb, sizeof(struct ipv6hdr));
- th = tcp_hdr(skb);
- th->check = ~tcp_v6_check(skb->len - skb_transport_offset(skb),
- &iph->saddr, &iph->daddr, 0);
- tcp_gro_complete(skb);
- }
- #endif
- static void qede_gro_receive(struct qede_dev *edev,
- struct qede_fastpath *fp,
- struct sk_buff *skb,
- u16 vlan_tag)
- {
- /* FW can send a single MTU sized packet from gro flow
- * due to aggregation timeout/last segment etc. which
- * is not expected to be a gro packet. If a skb has zero
- * frags then simply push it in the stack as non gso skb.
- */
- if (unlikely(!skb->data_len)) {
- skb_shinfo(skb)->gso_type = 0;
- skb_shinfo(skb)->gso_size = 0;
- goto send_skb;
- }
- #ifdef CONFIG_INET
- if (skb_shinfo(skb)->gso_size) {
- skb_reset_network_header(skb);
- switch (skb->protocol) {
- case htons(ETH_P_IP):
- qede_gro_ip_csum(skb);
- break;
- case htons(ETH_P_IPV6):
- qede_gro_ipv6_csum(skb);
- break;
- default:
- DP_ERR(edev,
- "Error: FW GRO supports only IPv4/IPv6, not 0x%04x\n",
- ntohs(skb->protocol));
- }
- }
- #endif
- send_skb:
- skb_record_rx_queue(skb, fp->rxq->rxq_id);
- qede_skb_receive(edev, fp, fp->rxq, skb, vlan_tag);
- }
- static inline void qede_tpa_cont(struct qede_dev *edev,
- struct qede_rx_queue *rxq,
- struct eth_fast_path_rx_tpa_cont_cqe *cqe)
- {
- int i;
- for (i = 0; cqe->len_list[i]; i++)
- qede_fill_frag_skb(edev, rxq, cqe->tpa_agg_index,
- le16_to_cpu(cqe->len_list[i]));
- if (unlikely(i > 1))
- DP_ERR(edev,
- "Strange - TPA cont with more than a single len_list entry\n");
- }
- static void qede_tpa_end(struct qede_dev *edev,
- struct qede_fastpath *fp,
- struct eth_fast_path_rx_tpa_end_cqe *cqe)
- {
- struct qede_rx_queue *rxq = fp->rxq;
- struct qede_agg_info *tpa_info;
- struct sk_buff *skb;
- int i;
- tpa_info = &rxq->tpa_info[cqe->tpa_agg_index];
- skb = tpa_info->skb;
- for (i = 0; cqe->len_list[i]; i++)
- qede_fill_frag_skb(edev, rxq, cqe->tpa_agg_index,
- le16_to_cpu(cqe->len_list[i]));
- if (unlikely(i > 1))
- DP_ERR(edev,
- "Strange - TPA emd with more than a single len_list entry\n");
- if (unlikely(tpa_info->state != QEDE_AGG_STATE_START))
- goto err;
- /* Sanity */
- if (unlikely(cqe->num_of_bds != tpa_info->frag_id + 1))
- DP_ERR(edev,
- "Strange - TPA had %02x BDs, but SKB has only %d frags\n",
- cqe->num_of_bds, tpa_info->frag_id);
- if (unlikely(skb->len != le16_to_cpu(cqe->total_packet_len)))
- DP_ERR(edev,
- "Strange - total packet len [cqe] is %4x but SKB has len %04x\n",
- le16_to_cpu(cqe->total_packet_len), skb->len);
- memcpy(skb->data,
- page_address(tpa_info->buffer.data) +
- tpa_info->start_cqe_placement_offset +
- tpa_info->buffer.page_offset, tpa_info->start_cqe_bd_len);
- /* Finalize the SKB */
- skb->protocol = eth_type_trans(skb, edev->ndev);
- skb->ip_summed = CHECKSUM_UNNECESSARY;
- /* tcp_gro_complete() will copy NAPI_GRO_CB(skb)->count
- * to skb_shinfo(skb)->gso_segs
- */
- NAPI_GRO_CB(skb)->count = le16_to_cpu(cqe->num_of_coalesced_segs);
- qede_gro_receive(edev, fp, skb, tpa_info->vlan_tag);
- tpa_info->state = QEDE_AGG_STATE_NONE;
- return;
- err:
- tpa_info->state = QEDE_AGG_STATE_NONE;
- dev_kfree_skb_any(tpa_info->skb);
- tpa_info->skb = NULL;
- }
- static bool qede_tunn_exist(u16 flag)
- {
- return !!(flag & (PARSING_AND_ERR_FLAGS_TUNNELEXIST_MASK <<
- PARSING_AND_ERR_FLAGS_TUNNELEXIST_SHIFT));
- }
- static u8 qede_check_tunn_csum(u16 flag)
- {
- u16 csum_flag = 0;
- u8 tcsum = 0;
- if (flag & (PARSING_AND_ERR_FLAGS_TUNNELL4CHKSMWASCALCULATED_MASK <<
- PARSING_AND_ERR_FLAGS_TUNNELL4CHKSMWASCALCULATED_SHIFT))
- csum_flag |= PARSING_AND_ERR_FLAGS_TUNNELL4CHKSMERROR_MASK <<
- PARSING_AND_ERR_FLAGS_TUNNELL4CHKSMERROR_SHIFT;
- if (flag & (PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED_MASK <<
- PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED_SHIFT)) {
- csum_flag |= PARSING_AND_ERR_FLAGS_L4CHKSMERROR_MASK <<
- PARSING_AND_ERR_FLAGS_L4CHKSMERROR_SHIFT;
- tcsum = QEDE_TUNN_CSUM_UNNECESSARY;
- }
- csum_flag |= PARSING_AND_ERR_FLAGS_TUNNELIPHDRERROR_MASK <<
- PARSING_AND_ERR_FLAGS_TUNNELIPHDRERROR_SHIFT |
- PARSING_AND_ERR_FLAGS_IPHDRERROR_MASK <<
- PARSING_AND_ERR_FLAGS_IPHDRERROR_SHIFT;
- if (csum_flag & flag)
- return QEDE_CSUM_ERROR;
- return QEDE_CSUM_UNNECESSARY | tcsum;
- }
- static u8 qede_check_notunn_csum(u16 flag)
- {
- u16 csum_flag = 0;
- u8 csum = 0;
- if (flag & (PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED_MASK <<
- PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED_SHIFT)) {
- csum_flag |= PARSING_AND_ERR_FLAGS_L4CHKSMERROR_MASK <<
- PARSING_AND_ERR_FLAGS_L4CHKSMERROR_SHIFT;
- csum = QEDE_CSUM_UNNECESSARY;
- }
- csum_flag |= PARSING_AND_ERR_FLAGS_IPHDRERROR_MASK <<
- PARSING_AND_ERR_FLAGS_IPHDRERROR_SHIFT;
- if (csum_flag & flag)
- return QEDE_CSUM_ERROR;
- return csum;
- }
- static u8 qede_check_csum(u16 flag)
- {
- if (!qede_tunn_exist(flag))
- return qede_check_notunn_csum(flag);
- else
- return qede_check_tunn_csum(flag);
- }
- static bool qede_pkt_is_ip_fragmented(struct eth_fast_path_rx_reg_cqe *cqe,
- u16 flag)
- {
- u8 tun_pars_flg = cqe->tunnel_pars_flags.flags;
- if ((tun_pars_flg & (ETH_TUNNEL_PARSING_FLAGS_IPV4_FRAGMENT_MASK <<
- ETH_TUNNEL_PARSING_FLAGS_IPV4_FRAGMENT_SHIFT)) ||
- (flag & (PARSING_AND_ERR_FLAGS_IPV4FRAG_MASK <<
- PARSING_AND_ERR_FLAGS_IPV4FRAG_SHIFT)))
- return true;
- return false;
- }
- /* Return true iff packet is to be passed to stack */
- static bool qede_rx_xdp(struct qede_dev *edev,
- struct qede_fastpath *fp,
- struct qede_rx_queue *rxq,
- struct bpf_prog *prog,
- struct sw_rx_data *bd,
- struct eth_fast_path_rx_reg_cqe *cqe)
- {
- u16 len = le16_to_cpu(cqe->len_on_first_bd);
- struct xdp_buff xdp;
- enum xdp_action act;
- xdp.data = page_address(bd->data) + cqe->placement_offset;
- xdp.data_end = xdp.data + len;
- /* Queues always have a full reset currently, so for the time
- * being until there's atomic program replace just mark read
- * side for map helpers.
- */
- rcu_read_lock();
- act = bpf_prog_run_xdp(prog, &xdp);
- rcu_read_unlock();
- if (act == XDP_PASS)
- return true;
- /* Count number of packets not to be passed to stack */
- rxq->xdp_no_pass++;
- switch (act) {
- case XDP_TX:
- /* We need the replacement buffer before transmit. */
- if (qede_alloc_rx_buffer(rxq)) {
- qede_recycle_rx_bd_ring(rxq, 1);
- return false;
- }
- /* Now if there's a transmission problem, we'd still have to
- * throw current buffer, as replacement was already allocated.
- */
- if (qede_xdp_xmit(edev, fp, bd, cqe->placement_offset, len)) {
- dma_unmap_page(rxq->dev, bd->mapping,
- PAGE_SIZE, DMA_BIDIRECTIONAL);
- __free_page(bd->data);
- }
- /* Regardless, we've consumed an Rx BD */
- qede_rx_bd_ring_consume(rxq);
- return false;
- default:
- bpf_warn_invalid_xdp_action(act);
- case XDP_ABORTED:
- case XDP_DROP:
- qede_recycle_rx_bd_ring(rxq, cqe->bd_num);
- }
- return false;
- }
- static struct sk_buff *qede_rx_allocate_skb(struct qede_dev *edev,
- struct qede_rx_queue *rxq,
- struct sw_rx_data *bd, u16 len,
- u16 pad)
- {
- unsigned int offset = bd->page_offset;
- struct skb_frag_struct *frag;
- struct page *page = bd->data;
- unsigned int pull_len;
- struct sk_buff *skb;
- unsigned char *va;
- /* Allocate a new SKB with a sufficient large header len */
- skb = netdev_alloc_skb(edev->ndev, QEDE_RX_HDR_SIZE);
- if (unlikely(!skb))
- return NULL;
- /* Copy data into SKB - if it's small, we can simply copy it and
- * re-use the already allcoated & mapped memory.
- */
- if (len + pad <= edev->rx_copybreak) {
- memcpy(skb_put(skb, len),
- page_address(page) + pad + offset, len);
- qede_reuse_page(rxq, bd);
- goto out;
- }
- frag = &skb_shinfo(skb)->frags[0];
- skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
- page, pad + offset, len, rxq->rx_buf_seg_size);
- va = skb_frag_address(frag);
- pull_len = eth_get_headlen(va, QEDE_RX_HDR_SIZE);
- /* Align the pull_len to optimize memcpy */
- memcpy(skb->data, va, ALIGN(pull_len, sizeof(long)));
- /* Correct the skb & frag sizes offset after the pull */
- skb_frag_size_sub(frag, pull_len);
- frag->page_offset += pull_len;
- skb->data_len -= pull_len;
- skb->tail += pull_len;
- if (unlikely(qede_realloc_rx_buffer(rxq, bd))) {
- /* Incr page ref count to reuse on allocation failure so
- * that it doesn't get freed while freeing SKB [as its
- * already mapped there].
- */
- page_ref_inc(page);
- dev_kfree_skb_any(skb);
- return NULL;
- }
- out:
- /* We've consumed the first BD and prepared an SKB */
- qede_rx_bd_ring_consume(rxq);
- return skb;
- }
- static int qede_rx_build_jumbo(struct qede_dev *edev,
- struct qede_rx_queue *rxq,
- struct sk_buff *skb,
- struct eth_fast_path_rx_reg_cqe *cqe,
- u16 first_bd_len)
- {
- u16 pkt_len = le16_to_cpu(cqe->pkt_len);
- struct sw_rx_data *bd;
- u16 bd_cons_idx;
- u8 num_frags;
- pkt_len -= first_bd_len;
- /* We've already used one BD for the SKB. Now take care of the rest */
- for (num_frags = cqe->bd_num - 1; num_frags > 0; num_frags--) {
- u16 cur_size = pkt_len > rxq->rx_buf_size ? rxq->rx_buf_size :
- pkt_len;
- if (unlikely(!cur_size)) {
- DP_ERR(edev,
- "Still got %d BDs for mapping jumbo, but length became 0\n",
- num_frags);
- goto out;
- }
- /* We need a replacement buffer for each BD */
- if (unlikely(qede_alloc_rx_buffer(rxq)))
- goto out;
- /* Now that we've allocated the replacement buffer,
- * we can safely consume the next BD and map it to the SKB.
- */
- bd_cons_idx = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
- bd = &rxq->sw_rx_ring[bd_cons_idx];
- qede_rx_bd_ring_consume(rxq);
- dma_unmap_page(rxq->dev, bd->mapping,
- PAGE_SIZE, DMA_FROM_DEVICE);
- skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags++,
- bd->data, 0, cur_size);
- skb->truesize += PAGE_SIZE;
- skb->data_len += cur_size;
- skb->len += cur_size;
- pkt_len -= cur_size;
- }
- if (unlikely(pkt_len))
- DP_ERR(edev,
- "Mapped all BDs of jumbo, but still have %d bytes\n",
- pkt_len);
- out:
- return num_frags;
- }
- static int qede_rx_process_tpa_cqe(struct qede_dev *edev,
- struct qede_fastpath *fp,
- struct qede_rx_queue *rxq,
- union eth_rx_cqe *cqe,
- enum eth_rx_cqe_type type)
- {
- switch (type) {
- case ETH_RX_CQE_TYPE_TPA_START:
- qede_tpa_start(edev, rxq, &cqe->fast_path_tpa_start);
- return 0;
- case ETH_RX_CQE_TYPE_TPA_CONT:
- qede_tpa_cont(edev, rxq, &cqe->fast_path_tpa_cont);
- return 0;
- case ETH_RX_CQE_TYPE_TPA_END:
- qede_tpa_end(edev, fp, &cqe->fast_path_tpa_end);
- return 1;
- default:
- return 0;
- }
- }
- static int qede_rx_process_cqe(struct qede_dev *edev,
- struct qede_fastpath *fp,
- struct qede_rx_queue *rxq)
- {
- struct bpf_prog *xdp_prog = READ_ONCE(rxq->xdp_prog);
- struct eth_fast_path_rx_reg_cqe *fp_cqe;
- u16 len, pad, bd_cons_idx, parse_flag;
- enum eth_rx_cqe_type cqe_type;
- union eth_rx_cqe *cqe;
- struct sw_rx_data *bd;
- struct sk_buff *skb;
- __le16 flags;
- u8 csum_flag;
- /* Get the CQE from the completion ring */
- cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
- cqe_type = cqe->fast_path_regular.type;
- /* Process an unlikely slowpath event */
- if (unlikely(cqe_type == ETH_RX_CQE_TYPE_SLOW_PATH)) {
- struct eth_slow_path_rx_cqe *sp_cqe;
- sp_cqe = (struct eth_slow_path_rx_cqe *)cqe;
- edev->ops->eth_cqe_completion(edev->cdev, fp->id, sp_cqe);
- return 0;
- }
- /* Handle TPA cqes */
- if (cqe_type != ETH_RX_CQE_TYPE_REGULAR)
- return qede_rx_process_tpa_cqe(edev, fp, rxq, cqe, cqe_type);
- /* Get the data from the SW ring; Consume it only after it's evident
- * we wouldn't recycle it.
- */
- bd_cons_idx = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
- bd = &rxq->sw_rx_ring[bd_cons_idx];
- fp_cqe = &cqe->fast_path_regular;
- len = le16_to_cpu(fp_cqe->len_on_first_bd);
- pad = fp_cqe->placement_offset;
- /* Run eBPF program if one is attached */
- if (xdp_prog)
- if (!qede_rx_xdp(edev, fp, rxq, xdp_prog, bd, fp_cqe))
- return 1;
- /* If this is an error packet then drop it */
- flags = cqe->fast_path_regular.pars_flags.flags;
- parse_flag = le16_to_cpu(flags);
- csum_flag = qede_check_csum(parse_flag);
- if (unlikely(csum_flag == QEDE_CSUM_ERROR)) {
- if (qede_pkt_is_ip_fragmented(fp_cqe, parse_flag)) {
- rxq->rx_ip_frags++;
- } else {
- DP_NOTICE(edev,
- "CQE has error, flags = %x, dropping incoming packet\n",
- parse_flag);
- rxq->rx_hw_errors++;
- qede_recycle_rx_bd_ring(rxq, fp_cqe->bd_num);
- return 0;
- }
- }
- /* Basic validation passed; Need to prepare an SKB. This would also
- * guarantee to finally consume the first BD upon success.
- */
- skb = qede_rx_allocate_skb(edev, rxq, bd, len, pad);
- if (!skb) {
- rxq->rx_alloc_errors++;
- qede_recycle_rx_bd_ring(rxq, fp_cqe->bd_num);
- return 0;
- }
- /* In case of Jumbo packet, several PAGE_SIZEd buffers will be pointed
- * by a single cqe.
- */
- if (fp_cqe->bd_num > 1) {
- u16 unmapped_frags = qede_rx_build_jumbo(edev, rxq, skb,
- fp_cqe, len);
- if (unlikely(unmapped_frags > 0)) {
- qede_recycle_rx_bd_ring(rxq, unmapped_frags);
- dev_kfree_skb_any(skb);
- return 0;
- }
- }
- /* The SKB contains all the data. Now prepare meta-magic */
- skb->protocol = eth_type_trans(skb, edev->ndev);
- qede_get_rxhash(skb, fp_cqe->bitfields, fp_cqe->rss_hash);
- qede_set_skb_csum(skb, csum_flag);
- skb_record_rx_queue(skb, rxq->rxq_id);
- /* SKB is prepared - pass it to stack */
- qede_skb_receive(edev, fp, rxq, skb, le16_to_cpu(fp_cqe->vlan_tag));
- return 1;
- }
- static int qede_rx_int(struct qede_fastpath *fp, int budget)
- {
- struct qede_rx_queue *rxq = fp->rxq;
- struct qede_dev *edev = fp->edev;
- u16 hw_comp_cons, sw_comp_cons;
- int work_done = 0;
- hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr);
- sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
- /* Memory barrier to prevent the CPU from doing speculative reads of CQE
- * / BD in the while-loop before reading hw_comp_cons. If the CQE is
- * read before it is written by FW, then FW writes CQE and SB, and then
- * the CPU reads the hw_comp_cons, it will use an old CQE.
- */
- rmb();
- /* Loop to complete all indicated BDs */
- while ((sw_comp_cons != hw_comp_cons) && (work_done < budget)) {
- qede_rx_process_cqe(edev, fp, rxq);
- qed_chain_recycle_consumed(&rxq->rx_comp_ring);
- sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
- work_done++;
- }
- /* Update producers */
- qede_update_rx_prod(edev, rxq);
- return work_done;
- }
- static bool qede_poll_is_more_work(struct qede_fastpath *fp)
- {
- qed_sb_update_sb_idx(fp->sb_info);
- /* *_has_*_work() reads the status block, thus we need to ensure that
- * status block indices have been actually read (qed_sb_update_sb_idx)
- * prior to this check (*_has_*_work) so that we won't write the
- * "newer" value of the status block to HW (if there was a DMA right
- * after qede_has_rx_work and if there is no rmb, the memory reading
- * (qed_sb_update_sb_idx) may be postponed to right before *_ack_sb).
- * In this case there will never be another interrupt until there is
- * another update of the status block, while there is still unhandled
- * work.
- */
- rmb();
- if (likely(fp->type & QEDE_FASTPATH_RX))
- if (qede_has_rx_work(fp->rxq))
- return true;
- if (fp->type & QEDE_FASTPATH_XDP)
- if (qede_txq_has_work(fp->xdp_tx))
- return true;
- if (likely(fp->type & QEDE_FASTPATH_TX))
- if (qede_txq_has_work(fp->txq))
- return true;
- return false;
- }
- static int qede_poll(struct napi_struct *napi, int budget)
- {
- struct qede_fastpath *fp = container_of(napi, struct qede_fastpath,
- napi);
- struct qede_dev *edev = fp->edev;
- int rx_work_done = 0;
- if (likely(fp->type & QEDE_FASTPATH_TX) && qede_txq_has_work(fp->txq))
- qede_tx_int(edev, fp->txq);
- if ((fp->type & QEDE_FASTPATH_XDP) && qede_txq_has_work(fp->xdp_tx))
- qede_xdp_tx_int(edev, fp->xdp_tx);
- rx_work_done = (likely(fp->type & QEDE_FASTPATH_RX) &&
- qede_has_rx_work(fp->rxq)) ?
- qede_rx_int(fp, budget) : 0;
- if (rx_work_done < budget) {
- if (!qede_poll_is_more_work(fp)) {
- napi_complete(napi);
- /* Update and reenable interrupts */
- qed_sb_ack(fp->sb_info, IGU_INT_ENABLE, 1);
- } else {
- rx_work_done = budget;
- }
- }
- if (fp->xdp_xmit) {
- u16 xdp_prod = qed_chain_get_prod_idx(&fp->xdp_tx->tx_pbl);
- fp->xdp_xmit = 0;
- fp->xdp_tx->tx_db.data.bd_prod = cpu_to_le16(xdp_prod);
- qede_update_tx_producer(fp->xdp_tx);
- }
- return rx_work_done;
- }
- static irqreturn_t qede_msix_fp_int(int irq, void *fp_cookie)
- {
- struct qede_fastpath *fp = fp_cookie;
- qed_sb_ack(fp->sb_info, IGU_INT_DISABLE, 0 /*do not update*/);
- napi_schedule_irqoff(&fp->napi);
- return IRQ_HANDLED;
- }
- /* -------------------------------------------------------------------------
- * END OF FAST-PATH
- * -------------------------------------------------------------------------
- */
- static int qede_open(struct net_device *ndev);
- static int qede_close(struct net_device *ndev);
- static int qede_set_mac_addr(struct net_device *ndev, void *p);
- static void qede_set_rx_mode(struct net_device *ndev);
- static void qede_config_rx_mode(struct net_device *ndev);
- static int qede_set_ucast_rx_mac(struct qede_dev *edev,
- enum qed_filter_xcast_params_type opcode,
- unsigned char mac[ETH_ALEN])
- {
- struct qed_filter_params filter_cmd;
- memset(&filter_cmd, 0, sizeof(filter_cmd));
- filter_cmd.type = QED_FILTER_TYPE_UCAST;
- filter_cmd.filter.ucast.type = opcode;
- filter_cmd.filter.ucast.mac_valid = 1;
- ether_addr_copy(filter_cmd.filter.ucast.mac, mac);
- return edev->ops->filter_config(edev->cdev, &filter_cmd);
- }
- static int qede_set_ucast_rx_vlan(struct qede_dev *edev,
- enum qed_filter_xcast_params_type opcode,
- u16 vid)
- {
- struct qed_filter_params filter_cmd;
- memset(&filter_cmd, 0, sizeof(filter_cmd));
- filter_cmd.type = QED_FILTER_TYPE_UCAST;
- filter_cmd.filter.ucast.type = opcode;
- filter_cmd.filter.ucast.vlan_valid = 1;
- filter_cmd.filter.ucast.vlan = vid;
- return edev->ops->filter_config(edev->cdev, &filter_cmd);
- }
- void qede_fill_by_demand_stats(struct qede_dev *edev)
- {
- struct qed_eth_stats stats;
- edev->ops->get_vport_stats(edev->cdev, &stats);
- edev->stats.no_buff_discards = stats.no_buff_discards;
- edev->stats.packet_too_big_discard = stats.packet_too_big_discard;
- edev->stats.ttl0_discard = stats.ttl0_discard;
- edev->stats.rx_ucast_bytes = stats.rx_ucast_bytes;
- edev->stats.rx_mcast_bytes = stats.rx_mcast_bytes;
- edev->stats.rx_bcast_bytes = stats.rx_bcast_bytes;
- edev->stats.rx_ucast_pkts = stats.rx_ucast_pkts;
- edev->stats.rx_mcast_pkts = stats.rx_mcast_pkts;
- edev->stats.rx_bcast_pkts = stats.rx_bcast_pkts;
- edev->stats.mftag_filter_discards = stats.mftag_filter_discards;
- edev->stats.mac_filter_discards = stats.mac_filter_discards;
- edev->stats.tx_ucast_bytes = stats.tx_ucast_bytes;
- edev->stats.tx_mcast_bytes = stats.tx_mcast_bytes;
- edev->stats.tx_bcast_bytes = stats.tx_bcast_bytes;
- edev->stats.tx_ucast_pkts = stats.tx_ucast_pkts;
- edev->stats.tx_mcast_pkts = stats.tx_mcast_pkts;
- edev->stats.tx_bcast_pkts = stats.tx_bcast_pkts;
- edev->stats.tx_err_drop_pkts = stats.tx_err_drop_pkts;
- edev->stats.coalesced_pkts = stats.tpa_coalesced_pkts;
- edev->stats.coalesced_events = stats.tpa_coalesced_events;
- edev->stats.coalesced_aborts_num = stats.tpa_aborts_num;
- edev->stats.non_coalesced_pkts = stats.tpa_not_coalesced_pkts;
- edev->stats.coalesced_bytes = stats.tpa_coalesced_bytes;
- edev->stats.rx_64_byte_packets = stats.rx_64_byte_packets;
- edev->stats.rx_65_to_127_byte_packets = stats.rx_65_to_127_byte_packets;
- edev->stats.rx_128_to_255_byte_packets =
- stats.rx_128_to_255_byte_packets;
- edev->stats.rx_256_to_511_byte_packets =
- stats.rx_256_to_511_byte_packets;
- edev->stats.rx_512_to_1023_byte_packets =
- stats.rx_512_to_1023_byte_packets;
- edev->stats.rx_1024_to_1518_byte_packets =
- stats.rx_1024_to_1518_byte_packets;
- edev->stats.rx_1519_to_1522_byte_packets =
- stats.rx_1519_to_1522_byte_packets;
- edev->stats.rx_1519_to_2047_byte_packets =
- stats.rx_1519_to_2047_byte_packets;
- edev->stats.rx_2048_to_4095_byte_packets =
- stats.rx_2048_to_4095_byte_packets;
- edev->stats.rx_4096_to_9216_byte_packets =
- stats.rx_4096_to_9216_byte_packets;
- edev->stats.rx_9217_to_16383_byte_packets =
- stats.rx_9217_to_16383_byte_packets;
- edev->stats.rx_crc_errors = stats.rx_crc_errors;
- edev->stats.rx_mac_crtl_frames = stats.rx_mac_crtl_frames;
- edev->stats.rx_pause_frames = stats.rx_pause_frames;
- edev->stats.rx_pfc_frames = stats.rx_pfc_frames;
- edev->stats.rx_align_errors = stats.rx_align_errors;
- edev->stats.rx_carrier_errors = stats.rx_carrier_errors;
- edev->stats.rx_oversize_packets = stats.rx_oversize_packets;
- edev->stats.rx_jabbers = stats.rx_jabbers;
- edev->stats.rx_undersize_packets = stats.rx_undersize_packets;
- edev->stats.rx_fragments = stats.rx_fragments;
- edev->stats.tx_64_byte_packets = stats.tx_64_byte_packets;
- edev->stats.tx_65_to_127_byte_packets = stats.tx_65_to_127_byte_packets;
- edev->stats.tx_128_to_255_byte_packets =
- stats.tx_128_to_255_byte_packets;
- edev->stats.tx_256_to_511_byte_packets =
- stats.tx_256_to_511_byte_packets;
- edev->stats.tx_512_to_1023_byte_packets =
- stats.tx_512_to_1023_byte_packets;
- edev->stats.tx_1024_to_1518_byte_packets =
- stats.tx_1024_to_1518_byte_packets;
- edev->stats.tx_1519_to_2047_byte_packets =
- stats.tx_1519_to_2047_byte_packets;
- edev->stats.tx_2048_to_4095_byte_packets =
- stats.tx_2048_to_4095_byte_packets;
- edev->stats.tx_4096_to_9216_byte_packets =
- stats.tx_4096_to_9216_byte_packets;
- edev->stats.tx_9217_to_16383_byte_packets =
- stats.tx_9217_to_16383_byte_packets;
- edev->stats.tx_pause_frames = stats.tx_pause_frames;
- edev->stats.tx_pfc_frames = stats.tx_pfc_frames;
- edev->stats.tx_lpi_entry_count = stats.tx_lpi_entry_count;
- edev->stats.tx_total_collisions = stats.tx_total_collisions;
- edev->stats.brb_truncates = stats.brb_truncates;
- edev->stats.brb_discards = stats.brb_discards;
- edev->stats.tx_mac_ctrl_frames = stats.tx_mac_ctrl_frames;
- }
- static
- struct rtnl_link_stats64 *qede_get_stats64(struct net_device *dev,
- struct rtnl_link_stats64 *stats)
- {
- struct qede_dev *edev = netdev_priv(dev);
- qede_fill_by_demand_stats(edev);
- stats->rx_packets = edev->stats.rx_ucast_pkts +
- edev->stats.rx_mcast_pkts +
- edev->stats.rx_bcast_pkts;
- stats->tx_packets = edev->stats.tx_ucast_pkts +
- edev->stats.tx_mcast_pkts +
- edev->stats.tx_bcast_pkts;
- stats->rx_bytes = edev->stats.rx_ucast_bytes +
- edev->stats.rx_mcast_bytes +
- edev->stats.rx_bcast_bytes;
- stats->tx_bytes = edev->stats.tx_ucast_bytes +
- edev->stats.tx_mcast_bytes +
- edev->stats.tx_bcast_bytes;
- stats->tx_errors = edev->stats.tx_err_drop_pkts;
- stats->multicast = edev->stats.rx_mcast_pkts +
- edev->stats.rx_bcast_pkts;
- stats->rx_fifo_errors = edev->stats.no_buff_discards;
- stats->collisions = edev->stats.tx_total_collisions;
- stats->rx_crc_errors = edev->stats.rx_crc_errors;
- stats->rx_frame_errors = edev->stats.rx_align_errors;
- return stats;
- }
- #ifdef CONFIG_QED_SRIOV
- static int qede_get_vf_config(struct net_device *dev, int vfidx,
- struct ifla_vf_info *ivi)
- {
- struct qede_dev *edev = netdev_priv(dev);
- if (!edev->ops)
- return -EINVAL;
- return edev->ops->iov->get_config(edev->cdev, vfidx, ivi);
- }
- static int qede_set_vf_rate(struct net_device *dev, int vfidx,
- int min_tx_rate, int max_tx_rate)
- {
- struct qede_dev *edev = netdev_priv(dev);
- return edev->ops->iov->set_rate(edev->cdev, vfidx, min_tx_rate,
- max_tx_rate);
- }
- static int qede_set_vf_spoofchk(struct net_device *dev, int vfidx, bool val)
- {
- struct qede_dev *edev = netdev_priv(dev);
- if (!edev->ops)
- return -EINVAL;
- return edev->ops->iov->set_spoof(edev->cdev, vfidx, val);
- }
- static int qede_set_vf_link_state(struct net_device *dev, int vfidx,
- int link_state)
- {
- struct qede_dev *edev = netdev_priv(dev);
- if (!edev->ops)
- return -EINVAL;
- return edev->ops->iov->set_link_state(edev->cdev, vfidx, link_state);
- }
- #endif
- static void qede_config_accept_any_vlan(struct qede_dev *edev, bool action)
- {
- struct qed_update_vport_params params;
- int rc;
- /* Proceed only if action actually needs to be performed */
- if (edev->accept_any_vlan == action)
- return;
- memset(¶ms, 0, sizeof(params));
- params.vport_id = 0;
- params.accept_any_vlan = action;
- params.update_accept_any_vlan_flg = 1;
- rc = edev->ops->vport_update(edev->cdev, ¶ms);
- if (rc) {
- DP_ERR(edev, "Failed to %s accept-any-vlan\n",
- action ? "enable" : "disable");
- } else {
- DP_INFO(edev, "%s accept-any-vlan\n",
- action ? "enabled" : "disabled");
- edev->accept_any_vlan = action;
- }
- }
- static int qede_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
- {
- struct qede_dev *edev = netdev_priv(dev);
- struct qede_vlan *vlan, *tmp;
- int rc = 0;
- DP_VERBOSE(edev, NETIF_MSG_IFUP, "Adding vlan 0x%04x\n", vid);
- vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
- if (!vlan) {
- DP_INFO(edev, "Failed to allocate struct for vlan\n");
- return -ENOMEM;
- }
- INIT_LIST_HEAD(&vlan->list);
- vlan->vid = vid;
- vlan->configured = false;
- /* Verify vlan isn't already configured */
- list_for_each_entry(tmp, &edev->vlan_list, list) {
- if (tmp->vid == vlan->vid) {
- DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
- "vlan already configured\n");
- kfree(vlan);
- return -EEXIST;
- }
- }
- /* If interface is down, cache this VLAN ID and return */
- __qede_lock(edev);
- if (edev->state != QEDE_STATE_OPEN) {
- DP_VERBOSE(edev, NETIF_MSG_IFDOWN,
- "Interface is down, VLAN %d will be configured when interface is up\n",
- vid);
- if (vid != 0)
- edev->non_configured_vlans++;
- list_add(&vlan->list, &edev->vlan_list);
- goto out;
- }
- /* Check for the filter limit.
- * Note - vlan0 has a reserved filter and can be added without
- * worrying about quota
- */
- if ((edev->configured_vlans < edev->dev_info.num_vlan_filters) ||
- (vlan->vid == 0)) {
- rc = qede_set_ucast_rx_vlan(edev,
- QED_FILTER_XCAST_TYPE_ADD,
- vlan->vid);
- if (rc) {
- DP_ERR(edev, "Failed to configure VLAN %d\n",
- vlan->vid);
- kfree(vlan);
- goto out;
- }
- vlan->configured = true;
- /* vlan0 filter isn't consuming out of our quota */
- if (vlan->vid != 0)
- edev->configured_vlans++;
- } else {
- /* Out of quota; Activate accept-any-VLAN mode */
- if (!edev->non_configured_vlans)
- qede_config_accept_any_vlan(edev, true);
- edev->non_configured_vlans++;
- }
- list_add(&vlan->list, &edev->vlan_list);
- out:
- __qede_unlock(edev);
- return rc;
- }
- static void qede_del_vlan_from_list(struct qede_dev *edev,
- struct qede_vlan *vlan)
- {
- /* vlan0 filter isn't consuming out of our quota */
- if (vlan->vid != 0) {
- if (vlan->configured)
- edev->configured_vlans--;
- else
- edev->non_configured_vlans--;
- }
- list_del(&vlan->list);
- kfree(vlan);
- }
- static int qede_configure_vlan_filters(struct qede_dev *edev)
- {
- int rc = 0, real_rc = 0, accept_any_vlan = 0;
- struct qed_dev_eth_info *dev_info;
- struct qede_vlan *vlan = NULL;
- if (list_empty(&edev->vlan_list))
- return 0;
- dev_info = &edev->dev_info;
- /* Configure non-configured vlans */
- list_for_each_entry(vlan, &edev->vlan_list, list) {
- if (vlan->configured)
- continue;
- /* We have used all our credits, now enable accept_any_vlan */
- if ((vlan->vid != 0) &&
- (edev->configured_vlans == dev_info->num_vlan_filters)) {
- accept_any_vlan = 1;
- continue;
- }
- DP_VERBOSE(edev, NETIF_MSG_IFUP, "Adding vlan %d\n", vlan->vid);
- rc = qede_set_ucast_rx_vlan(edev, QED_FILTER_XCAST_TYPE_ADD,
- vlan->vid);
- if (rc) {
- DP_ERR(edev, "Failed to configure VLAN %u\n",
- vlan->vid);
- real_rc = rc;
- continue;
- }
- vlan->configured = true;
- /* vlan0 filter doesn't consume our VLAN filter's quota */
- if (vlan->vid != 0) {
- edev->non_configured_vlans--;
- edev->configured_vlans++;
- }
- }
- /* enable accept_any_vlan mode if we have more VLANs than credits,
- * or remove accept_any_vlan mode if we've actually removed
- * a non-configured vlan, and all remaining vlans are truly configured.
- */
- if (accept_any_vlan)
- qede_config_accept_any_vlan(edev, true);
- else if (!edev->non_configured_vlans)
- qede_config_accept_any_vlan(edev, false);
- return real_rc;
- }
- static int qede_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
- {
- struct qede_dev *edev = netdev_priv(dev);
- struct qede_vlan *vlan = NULL;
- int rc = 0;
- DP_VERBOSE(edev, NETIF_MSG_IFDOWN, "Removing vlan 0x%04x\n", vid);
- /* Find whether entry exists */
- __qede_lock(edev);
- list_for_each_entry(vlan, &edev->vlan_list, list)
- if (vlan->vid == vid)
- break;
- if (!vlan || (vlan->vid != vid)) {
- DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
- "Vlan isn't configured\n");
- goto out;
- }
- if (edev->state != QEDE_STATE_OPEN) {
- /* As interface is already down, we don't have a VPORT
- * instance to remove vlan filter. So just update vlan list
- */
- DP_VERBOSE(edev, NETIF_MSG_IFDOWN,
- "Interface is down, removing VLAN from list only\n");
- qede_del_vlan_from_list(edev, vlan);
- goto out;
- }
- /* Remove vlan */
- if (vlan->configured) {
- rc = qede_set_ucast_rx_vlan(edev, QED_FILTER_XCAST_TYPE_DEL,
- vid);
- if (rc) {
- DP_ERR(edev, "Failed to remove VLAN %d\n", vid);
- goto out;
- }
- }
- qede_del_vlan_from_list(edev, vlan);
- /* We have removed a VLAN - try to see if we can
- * configure non-configured VLAN from the list.
- */
- rc = qede_configure_vlan_filters(edev);
- out:
- __qede_unlock(edev);
- return rc;
- }
- static void qede_vlan_mark_nonconfigured(struct qede_dev *edev)
- {
- struct qede_vlan *vlan = NULL;
- if (list_empty(&edev->vlan_list))
- return;
- list_for_each_entry(vlan, &edev->vlan_list, list) {
- if (!vlan->configured)
- continue;
- vlan->configured = false;
- /* vlan0 filter isn't consuming out of our quota */
- if (vlan->vid != 0) {
- edev->non_configured_vlans++;
- edev->configured_vlans--;
- }
- DP_VERBOSE(edev, NETIF_MSG_IFDOWN,
- "marked vlan %d as non-configured\n", vlan->vid);
- }
- edev->accept_any_vlan = false;
- }
- static void qede_set_features_reload(struct qede_dev *edev,
- struct qede_reload_args *args)
- {
- edev->ndev->features = args->u.features;
- }
- int qede_set_features(struct net_device *dev, netdev_features_t features)
- {
- struct qede_dev *edev = netdev_priv(dev);
- netdev_features_t changes = features ^ dev->features;
- bool need_reload = false;
- /* No action needed if hardware GRO is disabled during driver load */
- if (changes & NETIF_F_GRO) {
- if (dev->features & NETIF_F_GRO)
- need_reload = !edev->gro_disable;
- else
- need_reload = edev->gro_disable;
- }
- if (need_reload) {
- struct qede_reload_args args;
- args.u.features = features;
- args.func = &qede_set_features_reload;
- /* Make sure that we definitely need to reload.
- * In case of an eBPF attached program, there will be no FW
- * aggregations, so no need to actually reload.
- */
- __qede_lock(edev);
- if (edev->xdp_prog)
- args.func(edev, &args);
- else
- qede_reload(edev, &args, true);
- __qede_unlock(edev);
- return 1;
- }
- return 0;
- }
- static void qede_udp_tunnel_add(struct net_device *dev,
- struct udp_tunnel_info *ti)
- {
- struct qede_dev *edev = netdev_priv(dev);
- u16 t_port = ntohs(ti->port);
- switch (ti->type) {
- case UDP_TUNNEL_TYPE_VXLAN:
- if (edev->vxlan_dst_port)
- return;
- edev->vxlan_dst_port = t_port;
- DP_VERBOSE(edev, QED_MSG_DEBUG, "Added vxlan port=%d\n",
- t_port);
- set_bit(QEDE_SP_VXLAN_PORT_CONFIG, &edev->sp_flags);
- break;
- case UDP_TUNNEL_TYPE_GENEVE:
- if (edev->geneve_dst_port)
- return;
- edev->geneve_dst_port = t_port;
- DP_VERBOSE(edev, QED_MSG_DEBUG, "Added geneve port=%d\n",
- t_port);
- set_bit(QEDE_SP_GENEVE_PORT_CONFIG, &edev->sp_flags);
- break;
- default:
- return;
- }
- schedule_delayed_work(&edev->sp_task, 0);
- }
- static void qede_udp_tunnel_del(struct net_device *dev,
- struct udp_tunnel_info *ti)
- {
- struct qede_dev *edev = netdev_priv(dev);
- u16 t_port = ntohs(ti->port);
- switch (ti->type) {
- case UDP_TUNNEL_TYPE_VXLAN:
- if (t_port != edev->vxlan_dst_port)
- return;
- edev->vxlan_dst_port = 0;
- DP_VERBOSE(edev, QED_MSG_DEBUG, "Deleted vxlan port=%d\n",
- t_port);
- set_bit(QEDE_SP_VXLAN_PORT_CONFIG, &edev->sp_flags);
- break;
- case UDP_TUNNEL_TYPE_GENEVE:
- if (t_port != edev->geneve_dst_port)
- return;
- edev->geneve_dst_port = 0;
- DP_VERBOSE(edev, QED_MSG_DEBUG, "Deleted geneve port=%d\n",
- t_port);
- set_bit(QEDE_SP_GENEVE_PORT_CONFIG, &edev->sp_flags);
- break;
- default:
- return;
- }
- schedule_delayed_work(&edev->sp_task, 0);
- }
- /* 8B udp header + 8B base tunnel header + 32B option length */
- #define QEDE_MAX_TUN_HDR_LEN 48
- static netdev_features_t qede_features_check(struct sk_buff *skb,
- struct net_device *dev,
- netdev_features_t features)
- {
- if (skb->encapsulation) {
- u8 l4_proto = 0;
- switch (vlan_get_protocol(skb)) {
- case htons(ETH_P_IP):
- l4_proto = ip_hdr(skb)->protocol;
- break;
- case htons(ETH_P_IPV6):
- l4_proto = ipv6_hdr(skb)->nexthdr;
- break;
- default:
- return features;
- }
- /* Disable offloads for geneve tunnels, as HW can't parse
- * the geneve header which has option length greater than 32B.
- */
- if ((l4_proto == IPPROTO_UDP) &&
- ((skb_inner_mac_header(skb) -
- skb_transport_header(skb)) > QEDE_MAX_TUN_HDR_LEN))
- return features & ~(NETIF_F_CSUM_MASK |
- NETIF_F_GSO_MASK);
- }
- return features;
- }
- static void qede_xdp_reload_func(struct qede_dev *edev,
- struct qede_reload_args *args)
- {
- struct bpf_prog *old;
- old = xchg(&edev->xdp_prog, args->u.new_prog);
- if (old)
- bpf_prog_put(old);
- }
- static int qede_xdp_set(struct qede_dev *edev, struct bpf_prog *prog)
- {
- struct qede_reload_args args;
- if (prog && prog->xdp_adjust_head) {
- DP_ERR(edev, "Does not support bpf_xdp_adjust_head()\n");
- return -EOPNOTSUPP;
- }
- /* If we're called, there was already a bpf reference increment */
- args.func = &qede_xdp_reload_func;
- args.u.new_prog = prog;
- qede_reload(edev, &args, false);
- return 0;
- }
- static int qede_xdp(struct net_device *dev, struct netdev_xdp *xdp)
- {
- struct qede_dev *edev = netdev_priv(dev);
- switch (xdp->command) {
- case XDP_SETUP_PROG:
- return qede_xdp_set(edev, xdp->prog);
- case XDP_QUERY_PROG:
- xdp->prog_attached = !!edev->xdp_prog;
- return 0;
- default:
- return -EINVAL;
- }
- }
- static const struct net_device_ops qede_netdev_ops = {
- .ndo_open = qede_open,
- .ndo_stop = qede_close,
- .ndo_start_xmit = qede_start_xmit,
- .ndo_set_rx_mode = qede_set_rx_mode,
- .ndo_set_mac_address = qede_set_mac_addr,
- .ndo_validate_addr = eth_validate_addr,
- .ndo_change_mtu = qede_change_mtu,
- #ifdef CONFIG_QED_SRIOV
- .ndo_set_vf_mac = qede_set_vf_mac,
- .ndo_set_vf_vlan = qede_set_vf_vlan,
- #endif
- .ndo_vlan_rx_add_vid = qede_vlan_rx_add_vid,
- .ndo_vlan_rx_kill_vid = qede_vlan_rx_kill_vid,
- .ndo_set_features = qede_set_features,
- .ndo_get_stats64 = qede_get_stats64,
- #ifdef CONFIG_QED_SRIOV
- .ndo_set_vf_link_state = qede_set_vf_link_state,
- .ndo_set_vf_spoofchk = qede_set_vf_spoofchk,
- .ndo_get_vf_config = qede_get_vf_config,
- .ndo_set_vf_rate = qede_set_vf_rate,
- #endif
- .ndo_udp_tunnel_add = qede_udp_tunnel_add,
- .ndo_udp_tunnel_del = qede_udp_tunnel_del,
- .ndo_features_check = qede_features_check,
- .ndo_xdp = qede_xdp,
- };
- /* -------------------------------------------------------------------------
- * START OF PROBE / REMOVE
- * -------------------------------------------------------------------------
- */
- static struct qede_dev *qede_alloc_etherdev(struct qed_dev *cdev,
- struct pci_dev *pdev,
- struct qed_dev_eth_info *info,
- u32 dp_module, u8 dp_level)
- {
- struct net_device *ndev;
- struct qede_dev *edev;
- ndev = alloc_etherdev_mqs(sizeof(*edev),
- info->num_queues, info->num_queues);
- if (!ndev) {
- pr_err("etherdev allocation failed\n");
- return NULL;
- }
- edev = netdev_priv(ndev);
- edev->ndev = ndev;
- edev->cdev = cdev;
- edev->pdev = pdev;
- edev->dp_module = dp_module;
- edev->dp_level = dp_level;
- edev->ops = qed_ops;
- edev->q_num_rx_buffers = NUM_RX_BDS_DEF;
- edev->q_num_tx_buffers = NUM_TX_BDS_DEF;
- DP_INFO(edev, "Allocated netdev with %d tx queues and %d rx queues\n",
- info->num_queues, info->num_queues);
- SET_NETDEV_DEV(ndev, &pdev->dev);
- memset(&edev->stats, 0, sizeof(edev->stats));
- memcpy(&edev->dev_info, info, sizeof(*info));
- INIT_LIST_HEAD(&edev->vlan_list);
- return edev;
- }
- static void qede_init_ndev(struct qede_dev *edev)
- {
- struct net_device *ndev = edev->ndev;
- struct pci_dev *pdev = edev->pdev;
- u32 hw_features;
- pci_set_drvdata(pdev, ndev);
- ndev->mem_start = edev->dev_info.common.pci_mem_start;
- ndev->base_addr = ndev->mem_start;
- ndev->mem_end = edev->dev_info.common.pci_mem_end;
- ndev->irq = edev->dev_info.common.pci_irq;
- ndev->watchdog_timeo = TX_TIMEOUT;
- ndev->netdev_ops = &qede_netdev_ops;
- qede_set_ethtool_ops(ndev);
- ndev->priv_flags |= IFF_UNICAST_FLT;
- /* user-changeble features */
- hw_features = NETIF_F_GRO | NETIF_F_SG |
- NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
- NETIF_F_TSO | NETIF_F_TSO6;
- /* Encap features*/
- hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
- NETIF_F_TSO_ECN | NETIF_F_GSO_UDP_TUNNEL_CSUM |
- NETIF_F_GSO_GRE_CSUM;
- ndev->hw_enc_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
- NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO_ECN |
- NETIF_F_TSO6 | NETIF_F_GSO_GRE |
- NETIF_F_GSO_UDP_TUNNEL | NETIF_F_RXCSUM |
- NETIF_F_GSO_UDP_TUNNEL_CSUM |
- NETIF_F_GSO_GRE_CSUM;
- ndev->vlan_features = hw_features | NETIF_F_RXHASH | NETIF_F_RXCSUM |
- NETIF_F_HIGHDMA;
- ndev->features = hw_features | NETIF_F_RXHASH | NETIF_F_RXCSUM |
- NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HIGHDMA |
- NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_CTAG_TX;
- ndev->hw_features = hw_features;
- /* MTU range: 46 - 9600 */
- ndev->min_mtu = ETH_ZLEN - ETH_HLEN;
- ndev->max_mtu = QEDE_MAX_JUMBO_PACKET_SIZE;
- /* Set network device HW mac */
- ether_addr_copy(edev->ndev->dev_addr, edev->dev_info.common.hw_mac);
- ndev->mtu = edev->dev_info.common.mtu;
- }
- /* This function converts from 32b param to two params of level and module
- * Input 32b decoding:
- * b31 - enable all NOTICE prints. NOTICE prints are for deviation from the
- * 'happy' flow, e.g. memory allocation failed.
- * b30 - enable all INFO prints. INFO prints are for major steps in the flow
- * and provide important parameters.
- * b29-b0 - per-module bitmap, where each bit enables VERBOSE prints of that
- * module. VERBOSE prints are for tracking the specific flow in low level.
- *
- * Notice that the level should be that of the lowest required logs.
- */
- void qede_config_debug(uint debug, u32 *p_dp_module, u8 *p_dp_level)
- {
- *p_dp_level = QED_LEVEL_NOTICE;
- *p_dp_module = 0;
- if (debug & QED_LOG_VERBOSE_MASK) {
- *p_dp_level = QED_LEVEL_VERBOSE;
- *p_dp_module = (debug & 0x3FFFFFFF);
- } else if (debug & QED_LOG_INFO_MASK) {
- *p_dp_level = QED_LEVEL_INFO;
- } else if (debug & QED_LOG_NOTICE_MASK) {
- *p_dp_level = QED_LEVEL_NOTICE;
- }
- }
- static void qede_free_fp_array(struct qede_dev *edev)
- {
- if (edev->fp_array) {
- struct qede_fastpath *fp;
- int i;
- for_each_queue(i) {
- fp = &edev->fp_array[i];
- kfree(fp->sb_info);
- kfree(fp->rxq);
- kfree(fp->xdp_tx);
- kfree(fp->txq);
- }
- kfree(edev->fp_array);
- }
- edev->num_queues = 0;
- edev->fp_num_tx = 0;
- edev->fp_num_rx = 0;
- }
- static int qede_alloc_fp_array(struct qede_dev *edev)
- {
- u8 fp_combined, fp_rx = edev->fp_num_rx;
- struct qede_fastpath *fp;
- int i;
- edev->fp_array = kcalloc(QEDE_QUEUE_CNT(edev),
- sizeof(*edev->fp_array), GFP_KERNEL);
- if (!edev->fp_array) {
- DP_NOTICE(edev, "fp array allocation failed\n");
- goto err;
- }
- fp_combined = QEDE_QUEUE_CNT(edev) - fp_rx - edev->fp_num_tx;
- /* Allocate the FP elements for Rx queues followed by combined and then
- * the Tx. This ordering should be maintained so that the respective
- * queues (Rx or Tx) will be together in the fastpath array and the
- * associated ids will be sequential.
- */
- for_each_queue(i) {
- fp = &edev->fp_array[i];
- fp->sb_info = kzalloc(sizeof(*fp->sb_info), GFP_KERNEL);
- if (!fp->sb_info) {
- DP_NOTICE(edev, "sb info struct allocation failed\n");
- goto err;
- }
- if (fp_rx) {
- fp->type = QEDE_FASTPATH_RX;
- fp_rx--;
- } else if (fp_combined) {
- fp->type = QEDE_FASTPATH_COMBINED;
- fp_combined--;
- } else {
- fp->type = QEDE_FASTPATH_TX;
- }
- if (fp->type & QEDE_FASTPATH_TX) {
- fp->txq = kzalloc(sizeof(*fp->txq), GFP_KERNEL);
- if (!fp->txq)
- goto err;
- }
- if (fp->type & QEDE_FASTPATH_RX) {
- fp->rxq = kzalloc(sizeof(*fp->rxq), GFP_KERNEL);
- if (!fp->rxq)
- goto err;
- if (edev->xdp_prog) {
- fp->xdp_tx = kzalloc(sizeof(*fp->xdp_tx),
- GFP_KERNEL);
- if (!fp->xdp_tx)
- goto err;
- fp->type |= QEDE_FASTPATH_XDP;
- }
- }
- }
- return 0;
- err:
- qede_free_fp_array(edev);
- return -ENOMEM;
- }
- static void qede_sp_task(struct work_struct *work)
- {
- struct qede_dev *edev = container_of(work, struct qede_dev,
- sp_task.work);
- struct qed_dev *cdev = edev->cdev;
- __qede_lock(edev);
- if (test_and_clear_bit(QEDE_SP_RX_MODE, &edev->sp_flags))
- if (edev->state == QEDE_STATE_OPEN)
- qede_config_rx_mode(edev->ndev);
- if (test_and_clear_bit(QEDE_SP_VXLAN_PORT_CONFIG, &edev->sp_flags)) {
- struct qed_tunn_params tunn_params;
- memset(&tunn_params, 0, sizeof(tunn_params));
- tunn_params.update_vxlan_port = 1;
- tunn_params.vxlan_port = edev->vxlan_dst_port;
- qed_ops->tunn_config(cdev, &tunn_params);
- }
- if (test_and_clear_bit(QEDE_SP_GENEVE_PORT_CONFIG, &edev->sp_flags)) {
- struct qed_tunn_params tunn_params;
- memset(&tunn_params, 0, sizeof(tunn_params));
- tunn_params.update_geneve_port = 1;
- tunn_params.geneve_port = edev->geneve_dst_port;
- qed_ops->tunn_config(cdev, &tunn_params);
- }
- __qede_unlock(edev);
- }
- static void qede_update_pf_params(struct qed_dev *cdev)
- {
- struct qed_pf_params pf_params;
- /* 64 rx + 64 tx + 64 XDP */
- memset(&pf_params, 0, sizeof(struct qed_pf_params));
- pf_params.eth_pf_params.num_cons = 192;
- qed_ops->common->update_pf_params(cdev, &pf_params);
- }
- enum qede_probe_mode {
- QEDE_PROBE_NORMAL,
- };
- static int __qede_probe(struct pci_dev *pdev, u32 dp_module, u8 dp_level,
- bool is_vf, enum qede_probe_mode mode)
- {
- struct qed_probe_params probe_params;
- struct qed_slowpath_params sp_params;
- struct qed_dev_eth_info dev_info;
- struct qede_dev *edev;
- struct qed_dev *cdev;
- int rc;
- if (unlikely(dp_level & QED_LEVEL_INFO))
- pr_notice("Starting qede probe\n");
- memset(&probe_params, 0, sizeof(probe_params));
- probe_params.protocol = QED_PROTOCOL_ETH;
- probe_params.dp_module = dp_module;
- probe_params.dp_level = dp_level;
- probe_params.is_vf = is_vf;
- cdev = qed_ops->common->probe(pdev, &probe_params);
- if (!cdev) {
- rc = -ENODEV;
- goto err0;
- }
- qede_update_pf_params(cdev);
- /* Start the Slowpath-process */
- memset(&sp_params, 0, sizeof(sp_params));
- sp_params.int_mode = QED_INT_MODE_MSIX;
- sp_params.drv_major = QEDE_MAJOR_VERSION;
- sp_params.drv_minor = QEDE_MINOR_VERSION;
- sp_params.drv_rev = QEDE_REVISION_VERSION;
- sp_params.drv_eng = QEDE_ENGINEERING_VERSION;
- strlcpy(sp_params.name, "qede LAN", QED_DRV_VER_STR_SIZE);
- rc = qed_ops->common->slowpath_start(cdev, &sp_params);
- if (rc) {
- pr_notice("Cannot start slowpath\n");
- goto err1;
- }
- /* Learn information crucial for qede to progress */
- rc = qed_ops->fill_dev_info(cdev, &dev_info);
- if (rc)
- goto err2;
- edev = qede_alloc_etherdev(cdev, pdev, &dev_info, dp_module,
- dp_level);
- if (!edev) {
- rc = -ENOMEM;
- goto err2;
- }
- if (is_vf)
- edev->flags |= QEDE_FLAG_IS_VF;
- qede_init_ndev(edev);
- rc = qede_roce_dev_add(edev);
- if (rc)
- goto err3;
- rc = register_netdev(edev->ndev);
- if (rc) {
- DP_NOTICE(edev, "Cannot register net-device\n");
- goto err4;
- }
- edev->ops->common->set_id(cdev, edev->ndev->name, DRV_MODULE_VERSION);
- edev->ops->register_ops(cdev, &qede_ll_ops, edev);
- #ifdef CONFIG_DCB
- if (!IS_VF(edev))
- qede_set_dcbnl_ops(edev->ndev);
- #endif
- INIT_DELAYED_WORK(&edev->sp_task, qede_sp_task);
- mutex_init(&edev->qede_lock);
- edev->rx_copybreak = QEDE_RX_HDR_SIZE;
- DP_INFO(edev, "Ending successfully qede probe\n");
- return 0;
- err4:
- qede_roce_dev_remove(edev);
- err3:
- free_netdev(edev->ndev);
- err2:
- qed_ops->common->slowpath_stop(cdev);
- err1:
- qed_ops->common->remove(cdev);
- err0:
- return rc;
- }
- static int qede_probe(struct pci_dev *pdev, const struct pci_device_id *id)
- {
- bool is_vf = false;
- u32 dp_module = 0;
- u8 dp_level = 0;
- switch ((enum qede_pci_private)id->driver_data) {
- case QEDE_PRIVATE_VF:
- if (debug & QED_LOG_VERBOSE_MASK)
- dev_err(&pdev->dev, "Probing a VF\n");
- is_vf = true;
- break;
- default:
- if (debug & QED_LOG_VERBOSE_MASK)
- dev_err(&pdev->dev, "Probing a PF\n");
- }
- qede_config_debug(debug, &dp_module, &dp_level);
- return __qede_probe(pdev, dp_module, dp_level, is_vf,
- QEDE_PROBE_NORMAL);
- }
- enum qede_remove_mode {
- QEDE_REMOVE_NORMAL,
- };
- static void __qede_remove(struct pci_dev *pdev, enum qede_remove_mode mode)
- {
- struct net_device *ndev = pci_get_drvdata(pdev);
- struct qede_dev *edev = netdev_priv(ndev);
- struct qed_dev *cdev = edev->cdev;
- DP_INFO(edev, "Starting qede_remove\n");
- cancel_delayed_work_sync(&edev->sp_task);
- unregister_netdev(ndev);
- qede_roce_dev_remove(edev);
- edev->ops->common->set_power_state(cdev, PCI_D0);
- pci_set_drvdata(pdev, NULL);
- /* Release edev's reference to XDP's bpf if such exist */
- if (edev->xdp_prog)
- bpf_prog_put(edev->xdp_prog);
- free_netdev(ndev);
- /* Use global ops since we've freed edev */
- qed_ops->common->slowpath_stop(cdev);
- if (system_state == SYSTEM_POWER_OFF)
- return;
- qed_ops->common->remove(cdev);
- dev_info(&pdev->dev, "Ending qede_remove successfully\n");
- }
- static void qede_remove(struct pci_dev *pdev)
- {
- __qede_remove(pdev, QEDE_REMOVE_NORMAL);
- }
- static void qede_shutdown(struct pci_dev *pdev)
- {
- __qede_remove(pdev, QEDE_REMOVE_NORMAL);
- }
- /* -------------------------------------------------------------------------
- * START OF LOAD / UNLOAD
- * -------------------------------------------------------------------------
- */
- static int qede_set_num_queues(struct qede_dev *edev)
- {
- int rc;
- u16 rss_num;
- /* Setup queues according to possible resources*/
- if (edev->req_queues)
- rss_num = edev->req_queues;
- else
- rss_num = netif_get_num_default_rss_queues() *
- edev->dev_info.common.num_hwfns;
- rss_num = min_t(u16, QEDE_MAX_RSS_CNT(edev), rss_num);
- rc = edev->ops->common->set_fp_int(edev->cdev, rss_num);
- if (rc > 0) {
- /* Managed to request interrupts for our queues */
- edev->num_queues = rc;
- DP_INFO(edev, "Managed %d [of %d] RSS queues\n",
- QEDE_QUEUE_CNT(edev), rss_num);
- rc = 0;
- }
- edev->fp_num_tx = edev->req_num_tx;
- edev->fp_num_rx = edev->req_num_rx;
- return rc;
- }
- static void qede_free_mem_sb(struct qede_dev *edev,
- struct qed_sb_info *sb_info)
- {
- if (sb_info->sb_virt)
- dma_free_coherent(&edev->pdev->dev, sizeof(*sb_info->sb_virt),
- (void *)sb_info->sb_virt, sb_info->sb_phys);
- }
- /* This function allocates fast-path status block memory */
- static int qede_alloc_mem_sb(struct qede_dev *edev,
- struct qed_sb_info *sb_info, u16 sb_id)
- {
- struct status_block *sb_virt;
- dma_addr_t sb_phys;
- int rc;
- sb_virt = dma_alloc_coherent(&edev->pdev->dev,
- sizeof(*sb_virt), &sb_phys, GFP_KERNEL);
- if (!sb_virt) {
- DP_ERR(edev, "Status block allocation failed\n");
- return -ENOMEM;
- }
- rc = edev->ops->common->sb_init(edev->cdev, sb_info,
- sb_virt, sb_phys, sb_id,
- QED_SB_TYPE_L2_QUEUE);
- if (rc) {
- DP_ERR(edev, "Status block initialization failed\n");
- dma_free_coherent(&edev->pdev->dev, sizeof(*sb_virt),
- sb_virt, sb_phys);
- return rc;
- }
- return 0;
- }
- static void qede_free_rx_buffers(struct qede_dev *edev,
- struct qede_rx_queue *rxq)
- {
- u16 i;
- for (i = rxq->sw_rx_cons; i != rxq->sw_rx_prod; i++) {
- struct sw_rx_data *rx_buf;
- struct page *data;
- rx_buf = &rxq->sw_rx_ring[i & NUM_RX_BDS_MAX];
- data = rx_buf->data;
- dma_unmap_page(&edev->pdev->dev,
- rx_buf->mapping, PAGE_SIZE, rxq->data_direction);
- rx_buf->data = NULL;
- __free_page(data);
- }
- }
- static void qede_free_sge_mem(struct qede_dev *edev, struct qede_rx_queue *rxq)
- {
- int i;
- if (edev->gro_disable)
- return;
- for (i = 0; i < ETH_TPA_MAX_AGGS_NUM; i++) {
- struct qede_agg_info *tpa_info = &rxq->tpa_info[i];
- struct sw_rx_data *replace_buf = &tpa_info->buffer;
- if (replace_buf->data) {
- dma_unmap_page(&edev->pdev->dev,
- replace_buf->mapping,
- PAGE_SIZE, DMA_FROM_DEVICE);
- __free_page(replace_buf->data);
- }
- }
- }
- static void qede_free_mem_rxq(struct qede_dev *edev, struct qede_rx_queue *rxq)
- {
- qede_free_sge_mem(edev, rxq);
- /* Free rx buffers */
- qede_free_rx_buffers(edev, rxq);
- /* Free the parallel SW ring */
- kfree(rxq->sw_rx_ring);
- /* Free the real RQ ring used by FW */
- edev->ops->common->chain_free(edev->cdev, &rxq->rx_bd_ring);
- edev->ops->common->chain_free(edev->cdev, &rxq->rx_comp_ring);
- }
- static int qede_alloc_sge_mem(struct qede_dev *edev, struct qede_rx_queue *rxq)
- {
- dma_addr_t mapping;
- int i;
- /* Don't perform FW aggregations in case of XDP */
- if (edev->xdp_prog)
- edev->gro_disable = 1;
- if (edev->gro_disable)
- return 0;
- if (edev->ndev->mtu > PAGE_SIZE) {
- edev->gro_disable = 1;
- return 0;
- }
- for (i = 0; i < ETH_TPA_MAX_AGGS_NUM; i++) {
- struct qede_agg_info *tpa_info = &rxq->tpa_info[i];
- struct sw_rx_data *replace_buf = &tpa_info->buffer;
- replace_buf->data = alloc_pages(GFP_ATOMIC, 0);
- if (unlikely(!replace_buf->data)) {
- DP_NOTICE(edev,
- "Failed to allocate TPA skb pool [replacement buffer]\n");
- goto err;
- }
- mapping = dma_map_page(&edev->pdev->dev, replace_buf->data, 0,
- PAGE_SIZE, DMA_FROM_DEVICE);
- if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
- DP_NOTICE(edev,
- "Failed to map TPA replacement buffer\n");
- goto err;
- }
- replace_buf->mapping = mapping;
- tpa_info->buffer.page_offset = 0;
- tpa_info->buffer_mapping = mapping;
- tpa_info->state = QEDE_AGG_STATE_NONE;
- }
- return 0;
- err:
- qede_free_sge_mem(edev, rxq);
- edev->gro_disable = 1;
- return -ENOMEM;
- }
- /* This function allocates all memory needed per Rx queue */
- static int qede_alloc_mem_rxq(struct qede_dev *edev, struct qede_rx_queue *rxq)
- {
- int i, rc, size;
- rxq->num_rx_buffers = edev->q_num_rx_buffers;
- rxq->rx_buf_size = NET_IP_ALIGN + ETH_OVERHEAD + edev->ndev->mtu;
- if (rxq->rx_buf_size > PAGE_SIZE)
- rxq->rx_buf_size = PAGE_SIZE;
- /* Segment size to spilt a page in multiple equal parts,
- * unless XDP is used in which case we'd use the entire page.
- */
- if (!edev->xdp_prog)
- rxq->rx_buf_seg_size = roundup_pow_of_two(rxq->rx_buf_size);
- else
- rxq->rx_buf_seg_size = PAGE_SIZE;
- /* Allocate the parallel driver ring for Rx buffers */
- size = sizeof(*rxq->sw_rx_ring) * RX_RING_SIZE;
- rxq->sw_rx_ring = kzalloc(size, GFP_KERNEL);
- if (!rxq->sw_rx_ring) {
- DP_ERR(edev, "Rx buffers ring allocation failed\n");
- rc = -ENOMEM;
- goto err;
- }
- /* Allocate FW Rx ring */
- rc = edev->ops->common->chain_alloc(edev->cdev,
- QED_CHAIN_USE_TO_CONSUME_PRODUCE,
- QED_CHAIN_MODE_NEXT_PTR,
- QED_CHAIN_CNT_TYPE_U16,
- RX_RING_SIZE,
- sizeof(struct eth_rx_bd),
- &rxq->rx_bd_ring);
- if (rc)
- goto err;
- /* Allocate FW completion ring */
- rc = edev->ops->common->chain_alloc(edev->cdev,
- QED_CHAIN_USE_TO_CONSUME,
- QED_CHAIN_MODE_PBL,
- QED_CHAIN_CNT_TYPE_U16,
- RX_RING_SIZE,
- sizeof(union eth_rx_cqe),
- &rxq->rx_comp_ring);
- if (rc)
- goto err;
- /* Allocate buffers for the Rx ring */
- for (i = 0; i < rxq->num_rx_buffers; i++) {
- rc = qede_alloc_rx_buffer(rxq);
- if (rc) {
- DP_ERR(edev,
- "Rx buffers allocation failed at index %d\n", i);
- goto err;
- }
- }
- rc = qede_alloc_sge_mem(edev, rxq);
- err:
- return rc;
- }
- static void qede_free_mem_txq(struct qede_dev *edev, struct qede_tx_queue *txq)
- {
- /* Free the parallel SW ring */
- if (txq->is_xdp)
- kfree(txq->sw_tx_ring.pages);
- else
- kfree(txq->sw_tx_ring.skbs);
- /* Free the real RQ ring used by FW */
- edev->ops->common->chain_free(edev->cdev, &txq->tx_pbl);
- }
- /* This function allocates all memory needed per Tx queue */
- static int qede_alloc_mem_txq(struct qede_dev *edev, struct qede_tx_queue *txq)
- {
- union eth_tx_bd_types *p_virt;
- int size, rc;
- txq->num_tx_buffers = edev->q_num_tx_buffers;
- /* Allocate the parallel driver ring for Tx buffers */
- if (txq->is_xdp) {
- size = sizeof(*txq->sw_tx_ring.pages) * TX_RING_SIZE;
- txq->sw_tx_ring.pages = kzalloc(size, GFP_KERNEL);
- if (!txq->sw_tx_ring.pages)
- goto err;
- } else {
- size = sizeof(*txq->sw_tx_ring.skbs) * TX_RING_SIZE;
- txq->sw_tx_ring.skbs = kzalloc(size, GFP_KERNEL);
- if (!txq->sw_tx_ring.skbs)
- goto err;
- }
- rc = edev->ops->common->chain_alloc(edev->cdev,
- QED_CHAIN_USE_TO_CONSUME_PRODUCE,
- QED_CHAIN_MODE_PBL,
- QED_CHAIN_CNT_TYPE_U16,
- TX_RING_SIZE,
- sizeof(*p_virt), &txq->tx_pbl);
- if (rc)
- goto err;
- return 0;
- err:
- qede_free_mem_txq(edev, txq);
- return -ENOMEM;
- }
- /* This function frees all memory of a single fp */
- static void qede_free_mem_fp(struct qede_dev *edev, struct qede_fastpath *fp)
- {
- qede_free_mem_sb(edev, fp->sb_info);
- if (fp->type & QEDE_FASTPATH_RX)
- qede_free_mem_rxq(edev, fp->rxq);
- if (fp->type & QEDE_FASTPATH_TX)
- qede_free_mem_txq(edev, fp->txq);
- }
- /* This function allocates all memory needed for a single fp (i.e. an entity
- * which contains status block, one rx queue and/or multiple per-TC tx queues.
- */
- static int qede_alloc_mem_fp(struct qede_dev *edev, struct qede_fastpath *fp)
- {
- int rc = 0;
- rc = qede_alloc_mem_sb(edev, fp->sb_info, fp->id);
- if (rc)
- goto out;
- if (fp->type & QEDE_FASTPATH_RX) {
- rc = qede_alloc_mem_rxq(edev, fp->rxq);
- if (rc)
- goto out;
- }
- if (fp->type & QEDE_FASTPATH_XDP) {
- rc = qede_alloc_mem_txq(edev, fp->xdp_tx);
- if (rc)
- goto out;
- }
- if (fp->type & QEDE_FASTPATH_TX) {
- rc = qede_alloc_mem_txq(edev, fp->txq);
- if (rc)
- goto out;
- }
- out:
- return rc;
- }
- static void qede_free_mem_load(struct qede_dev *edev)
- {
- int i;
- for_each_queue(i) {
- struct qede_fastpath *fp = &edev->fp_array[i];
- qede_free_mem_fp(edev, fp);
- }
- }
- /* This function allocates all qede memory at NIC load. */
- static int qede_alloc_mem_load(struct qede_dev *edev)
- {
- int rc = 0, queue_id;
- for (queue_id = 0; queue_id < QEDE_QUEUE_CNT(edev); queue_id++) {
- struct qede_fastpath *fp = &edev->fp_array[queue_id];
- rc = qede_alloc_mem_fp(edev, fp);
- if (rc) {
- DP_ERR(edev,
- "Failed to allocate memory for fastpath - rss id = %d\n",
- queue_id);
- qede_free_mem_load(edev);
- return rc;
- }
- }
- return 0;
- }
- /* This function inits fp content and resets the SB, RXQ and TXQ structures */
- static void qede_init_fp(struct qede_dev *edev)
- {
- int queue_id, rxq_index = 0, txq_index = 0;
- struct qede_fastpath *fp;
- for_each_queue(queue_id) {
- fp = &edev->fp_array[queue_id];
- fp->edev = edev;
- fp->id = queue_id;
- if (fp->type & QEDE_FASTPATH_XDP) {
- fp->xdp_tx->index = QEDE_TXQ_IDX_TO_XDP(edev,
- rxq_index);
- fp->xdp_tx->is_xdp = 1;
- }
- if (fp->type & QEDE_FASTPATH_RX) {
- fp->rxq->rxq_id = rxq_index++;
- /* Determine how to map buffers for this queue */
- if (fp->type & QEDE_FASTPATH_XDP)
- fp->rxq->data_direction = DMA_BIDIRECTIONAL;
- else
- fp->rxq->data_direction = DMA_FROM_DEVICE;
- fp->rxq->dev = &edev->pdev->dev;
- }
- if (fp->type & QEDE_FASTPATH_TX) {
- fp->txq->index = txq_index++;
- if (edev->dev_info.is_legacy)
- fp->txq->is_legacy = 1;
- fp->txq->dev = &edev->pdev->dev;
- }
- snprintf(fp->name, sizeof(fp->name), "%s-fp-%d",
- edev->ndev->name, queue_id);
- }
- edev->gro_disable = !(edev->ndev->features & NETIF_F_GRO);
- }
- static int qede_set_real_num_queues(struct qede_dev *edev)
- {
- int rc = 0;
- rc = netif_set_real_num_tx_queues(edev->ndev, QEDE_TSS_COUNT(edev));
- if (rc) {
- DP_NOTICE(edev, "Failed to set real number of Tx queues\n");
- return rc;
- }
- rc = netif_set_real_num_rx_queues(edev->ndev, QEDE_RSS_COUNT(edev));
- if (rc) {
- DP_NOTICE(edev, "Failed to set real number of Rx queues\n");
- return rc;
- }
- return 0;
- }
- static void qede_napi_disable_remove(struct qede_dev *edev)
- {
- int i;
- for_each_queue(i) {
- napi_disable(&edev->fp_array[i].napi);
- netif_napi_del(&edev->fp_array[i].napi);
- }
- }
- static void qede_napi_add_enable(struct qede_dev *edev)
- {
- int i;
- /* Add NAPI objects */
- for_each_queue(i) {
- netif_napi_add(edev->ndev, &edev->fp_array[i].napi,
- qede_poll, NAPI_POLL_WEIGHT);
- napi_enable(&edev->fp_array[i].napi);
- }
- }
- static void qede_sync_free_irqs(struct qede_dev *edev)
- {
- int i;
- for (i = 0; i < edev->int_info.used_cnt; i++) {
- if (edev->int_info.msix_cnt) {
- synchronize_irq(edev->int_info.msix[i].vector);
- free_irq(edev->int_info.msix[i].vector,
- &edev->fp_array[i]);
- } else {
- edev->ops->common->simd_handler_clean(edev->cdev, i);
- }
- }
- edev->int_info.used_cnt = 0;
- }
- static int qede_req_msix_irqs(struct qede_dev *edev)
- {
- int i, rc;
- /* Sanitize number of interrupts == number of prepared RSS queues */
- if (QEDE_QUEUE_CNT(edev) > edev->int_info.msix_cnt) {
- DP_ERR(edev,
- "Interrupt mismatch: %d RSS queues > %d MSI-x vectors\n",
- QEDE_QUEUE_CNT(edev), edev->int_info.msix_cnt);
- return -EINVAL;
- }
- for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
- rc = request_irq(edev->int_info.msix[i].vector,
- qede_msix_fp_int, 0, edev->fp_array[i].name,
- &edev->fp_array[i]);
- if (rc) {
- DP_ERR(edev, "Request fp %d irq failed\n", i);
- qede_sync_free_irqs(edev);
- return rc;
- }
- DP_VERBOSE(edev, NETIF_MSG_INTR,
- "Requested fp irq for %s [entry %d]. Cookie is at %p\n",
- edev->fp_array[i].name, i,
- &edev->fp_array[i]);
- edev->int_info.used_cnt++;
- }
- return 0;
- }
- static void qede_simd_fp_handler(void *cookie)
- {
- struct qede_fastpath *fp = (struct qede_fastpath *)cookie;
- napi_schedule_irqoff(&fp->napi);
- }
- static int qede_setup_irqs(struct qede_dev *edev)
- {
- int i, rc = 0;
- /* Learn Interrupt configuration */
- rc = edev->ops->common->get_fp_int(edev->cdev, &edev->int_info);
- if (rc)
- return rc;
- if (edev->int_info.msix_cnt) {
- rc = qede_req_msix_irqs(edev);
- if (rc)
- return rc;
- edev->ndev->irq = edev->int_info.msix[0].vector;
- } else {
- const struct qed_common_ops *ops;
- /* qed should learn receive the RSS ids and callbacks */
- ops = edev->ops->common;
- for (i = 0; i < QEDE_QUEUE_CNT(edev); i++)
- ops->simd_handler_config(edev->cdev,
- &edev->fp_array[i], i,
- qede_simd_fp_handler);
- edev->int_info.used_cnt = QEDE_QUEUE_CNT(edev);
- }
- return 0;
- }
- static int qede_drain_txq(struct qede_dev *edev,
- struct qede_tx_queue *txq, bool allow_drain)
- {
- int rc, cnt = 1000;
- while (txq->sw_tx_cons != txq->sw_tx_prod) {
- if (!cnt) {
- if (allow_drain) {
- DP_NOTICE(edev,
- "Tx queue[%d] is stuck, requesting MCP to drain\n",
- txq->index);
- rc = edev->ops->common->drain(edev->cdev);
- if (rc)
- return rc;
- return qede_drain_txq(edev, txq, false);
- }
- DP_NOTICE(edev,
- "Timeout waiting for tx queue[%d]: PROD=%d, CONS=%d\n",
- txq->index, txq->sw_tx_prod,
- txq->sw_tx_cons);
- return -ENODEV;
- }
- cnt--;
- usleep_range(1000, 2000);
- barrier();
- }
- /* FW finished processing, wait for HW to transmit all tx packets */
- usleep_range(1000, 2000);
- return 0;
- }
- static int qede_stop_txq(struct qede_dev *edev,
- struct qede_tx_queue *txq, int rss_id)
- {
- return edev->ops->q_tx_stop(edev->cdev, rss_id, txq->handle);
- }
- static int qede_stop_queues(struct qede_dev *edev)
- {
- struct qed_update_vport_params vport_update_params;
- struct qed_dev *cdev = edev->cdev;
- struct qede_fastpath *fp;
- int rc, i;
- /* Disable the vport */
- memset(&vport_update_params, 0, sizeof(vport_update_params));
- vport_update_params.vport_id = 0;
- vport_update_params.update_vport_active_flg = 1;
- vport_update_params.vport_active_flg = 0;
- vport_update_params.update_rss_flg = 0;
- rc = edev->ops->vport_update(cdev, &vport_update_params);
- if (rc) {
- DP_ERR(edev, "Failed to update vport\n");
- return rc;
- }
- /* Flush Tx queues. If needed, request drain from MCP */
- for_each_queue(i) {
- fp = &edev->fp_array[i];
- if (fp->type & QEDE_FASTPATH_TX) {
- rc = qede_drain_txq(edev, fp->txq, true);
- if (rc)
- return rc;
- }
- if (fp->type & QEDE_FASTPATH_XDP) {
- rc = qede_drain_txq(edev, fp->xdp_tx, true);
- if (rc)
- return rc;
- }
- }
- /* Stop all Queues in reverse order */
- for (i = QEDE_QUEUE_CNT(edev) - 1; i >= 0; i--) {
- fp = &edev->fp_array[i];
- /* Stop the Tx Queue(s) */
- if (fp->type & QEDE_FASTPATH_TX) {
- rc = qede_stop_txq(edev, fp->txq, i);
- if (rc)
- return rc;
- }
- /* Stop the Rx Queue */
- if (fp->type & QEDE_FASTPATH_RX) {
- rc = edev->ops->q_rx_stop(cdev, i, fp->rxq->handle);
- if (rc) {
- DP_ERR(edev, "Failed to stop RXQ #%d\n", i);
- return rc;
- }
- }
- /* Stop the XDP forwarding queue */
- if (fp->type & QEDE_FASTPATH_XDP) {
- rc = qede_stop_txq(edev, fp->xdp_tx, i);
- if (rc)
- return rc;
- bpf_prog_put(fp->rxq->xdp_prog);
- }
- }
- /* Stop the vport */
- rc = edev->ops->vport_stop(cdev, 0);
- if (rc)
- DP_ERR(edev, "Failed to stop VPORT\n");
- return rc;
- }
- static int qede_start_txq(struct qede_dev *edev,
- struct qede_fastpath *fp,
- struct qede_tx_queue *txq, u8 rss_id, u16 sb_idx)
- {
- dma_addr_t phys_table = qed_chain_get_pbl_phys(&txq->tx_pbl);
- u32 page_cnt = qed_chain_get_page_cnt(&txq->tx_pbl);
- struct qed_queue_start_common_params params;
- struct qed_txq_start_ret_params ret_params;
- int rc;
- memset(¶ms, 0, sizeof(params));
- memset(&ret_params, 0, sizeof(ret_params));
- /* Let the XDP queue share the queue-zone with one of the regular txq.
- * We don't really care about its coalescing.
- */
- if (txq->is_xdp)
- params.queue_id = QEDE_TXQ_XDP_TO_IDX(edev, txq);
- else
- params.queue_id = txq->index;
- params.sb = fp->sb_info->igu_sb_id;
- params.sb_idx = sb_idx;
- rc = edev->ops->q_tx_start(edev->cdev, rss_id, ¶ms, phys_table,
- page_cnt, &ret_params);
- if (rc) {
- DP_ERR(edev, "Start TXQ #%d failed %d\n", txq->index, rc);
- return rc;
- }
- txq->doorbell_addr = ret_params.p_doorbell;
- txq->handle = ret_params.p_handle;
- /* Determine the FW consumer address associated */
- txq->hw_cons_ptr = &fp->sb_info->sb_virt->pi_array[sb_idx];
- /* Prepare the doorbell parameters */
- SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_DEST, DB_DEST_XCM);
- SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_AGG_CMD, DB_AGG_CMD_SET);
- SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_AGG_VAL_SEL,
- DQ_XCM_ETH_TX_BD_PROD_CMD);
- txq->tx_db.data.agg_flags = DQ_XCM_ETH_DQ_CF_CMD;
- return rc;
- }
- static int qede_start_queues(struct qede_dev *edev, bool clear_stats)
- {
- int vlan_removal_en = 1;
- struct qed_dev *cdev = edev->cdev;
- struct qed_update_vport_params vport_update_params;
- struct qed_queue_start_common_params q_params;
- struct qed_dev_info *qed_info = &edev->dev_info.common;
- struct qed_start_vport_params start = {0};
- bool reset_rss_indir = false;
- int rc, i;
- if (!edev->num_queues) {
- DP_ERR(edev,
- "Cannot update V-VPORT as active as there are no Rx queues\n");
- return -EINVAL;
- }
- start.gro_enable = !edev->gro_disable;
- start.mtu = edev->ndev->mtu;
- start.vport_id = 0;
- start.drop_ttl0 = true;
- start.remove_inner_vlan = vlan_removal_en;
- start.clear_stats = clear_stats;
- rc = edev->ops->vport_start(cdev, &start);
- if (rc) {
- DP_ERR(edev, "Start V-PORT failed %d\n", rc);
- return rc;
- }
- DP_VERBOSE(edev, NETIF_MSG_IFUP,
- "Start vport ramrod passed, vport_id = %d, MTU = %d, vlan_removal_en = %d\n",
- start.vport_id, edev->ndev->mtu + 0xe, vlan_removal_en);
- for_each_queue(i) {
- struct qede_fastpath *fp = &edev->fp_array[i];
- dma_addr_t p_phys_table;
- u32 page_cnt;
- if (fp->type & QEDE_FASTPATH_RX) {
- struct qed_rxq_start_ret_params ret_params;
- struct qede_rx_queue *rxq = fp->rxq;
- __le16 *val;
- memset(&ret_params, 0, sizeof(ret_params));
- memset(&q_params, 0, sizeof(q_params));
- q_params.queue_id = rxq->rxq_id;
- q_params.vport_id = 0;
- q_params.sb = fp->sb_info->igu_sb_id;
- q_params.sb_idx = RX_PI;
- p_phys_table =
- qed_chain_get_pbl_phys(&rxq->rx_comp_ring);
- page_cnt = qed_chain_get_page_cnt(&rxq->rx_comp_ring);
- rc = edev->ops->q_rx_start(cdev, i, &q_params,
- rxq->rx_buf_size,
- rxq->rx_bd_ring.p_phys_addr,
- p_phys_table,
- page_cnt, &ret_params);
- if (rc) {
- DP_ERR(edev, "Start RXQ #%d failed %d\n", i,
- rc);
- return rc;
- }
- /* Use the return parameters */
- rxq->hw_rxq_prod_addr = ret_params.p_prod;
- rxq->handle = ret_params.p_handle;
- val = &fp->sb_info->sb_virt->pi_array[RX_PI];
- rxq->hw_cons_ptr = val;
- qede_update_rx_prod(edev, rxq);
- }
- if (fp->type & QEDE_FASTPATH_XDP) {
- rc = qede_start_txq(edev, fp, fp->xdp_tx, i, XDP_PI);
- if (rc)
- return rc;
- fp->rxq->xdp_prog = bpf_prog_add(edev->xdp_prog, 1);
- if (IS_ERR(fp->rxq->xdp_prog)) {
- rc = PTR_ERR(fp->rxq->xdp_prog);
- fp->rxq->xdp_prog = NULL;
- return rc;
- }
- }
- if (fp->type & QEDE_FASTPATH_TX) {
- rc = qede_start_txq(edev, fp, fp->txq, i, TX_PI(0));
- if (rc)
- return rc;
- }
- }
- /* Prepare and send the vport enable */
- memset(&vport_update_params, 0, sizeof(vport_update_params));
- vport_update_params.vport_id = start.vport_id;
- vport_update_params.update_vport_active_flg = 1;
- vport_update_params.vport_active_flg = 1;
- if ((qed_info->mf_mode == QED_MF_NPAR || pci_num_vf(edev->pdev)) &&
- qed_info->tx_switching) {
- vport_update_params.update_tx_switching_flg = 1;
- vport_update_params.tx_switching_flg = 1;
- }
- /* Fill struct with RSS params */
- if (QEDE_RSS_COUNT(edev) > 1) {
- vport_update_params.update_rss_flg = 1;
- /* Need to validate current RSS config uses valid entries */
- for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++) {
- if (edev->rss_params.rss_ind_table[i] >=
- QEDE_RSS_COUNT(edev)) {
- reset_rss_indir = true;
- break;
- }
- }
- if (!(edev->rss_params_inited & QEDE_RSS_INDIR_INITED) ||
- reset_rss_indir) {
- u16 val;
- for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++) {
- u16 indir_val;
- val = QEDE_RSS_COUNT(edev);
- indir_val = ethtool_rxfh_indir_default(i, val);
- edev->rss_params.rss_ind_table[i] = indir_val;
- }
- edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
- }
- if (!(edev->rss_params_inited & QEDE_RSS_KEY_INITED)) {
- netdev_rss_key_fill(edev->rss_params.rss_key,
- sizeof(edev->rss_params.rss_key));
- edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
- }
- if (!(edev->rss_params_inited & QEDE_RSS_CAPS_INITED)) {
- edev->rss_params.rss_caps = QED_RSS_IPV4 |
- QED_RSS_IPV6 |
- QED_RSS_IPV4_TCP |
- QED_RSS_IPV6_TCP;
- edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
- }
- memcpy(&vport_update_params.rss_params, &edev->rss_params,
- sizeof(vport_update_params.rss_params));
- } else {
- memset(&vport_update_params.rss_params, 0,
- sizeof(vport_update_params.rss_params));
- }
- rc = edev->ops->vport_update(cdev, &vport_update_params);
- if (rc) {
- DP_ERR(edev, "Update V-PORT failed %d\n", rc);
- return rc;
- }
- return 0;
- }
- static int qede_set_mcast_rx_mac(struct qede_dev *edev,
- enum qed_filter_xcast_params_type opcode,
- unsigned char *mac, int num_macs)
- {
- struct qed_filter_params filter_cmd;
- int i;
- memset(&filter_cmd, 0, sizeof(filter_cmd));
- filter_cmd.type = QED_FILTER_TYPE_MCAST;
- filter_cmd.filter.mcast.type = opcode;
- filter_cmd.filter.mcast.num = num_macs;
- for (i = 0; i < num_macs; i++, mac += ETH_ALEN)
- ether_addr_copy(filter_cmd.filter.mcast.mac[i], mac);
- return edev->ops->filter_config(edev->cdev, &filter_cmd);
- }
- enum qede_unload_mode {
- QEDE_UNLOAD_NORMAL,
- };
- static void qede_unload(struct qede_dev *edev, enum qede_unload_mode mode,
- bool is_locked)
- {
- struct qed_link_params link_params;
- int rc;
- DP_INFO(edev, "Starting qede unload\n");
- if (!is_locked)
- __qede_lock(edev);
- qede_roce_dev_event_close(edev);
- edev->state = QEDE_STATE_CLOSED;
- /* Close OS Tx */
- netif_tx_disable(edev->ndev);
- netif_carrier_off(edev->ndev);
- /* Reset the link */
- memset(&link_params, 0, sizeof(link_params));
- link_params.link_up = false;
- edev->ops->common->set_link(edev->cdev, &link_params);
- rc = qede_stop_queues(edev);
- if (rc) {
- qede_sync_free_irqs(edev);
- goto out;
- }
- DP_INFO(edev, "Stopped Queues\n");
- qede_vlan_mark_nonconfigured(edev);
- edev->ops->fastpath_stop(edev->cdev);
- /* Release the interrupts */
- qede_sync_free_irqs(edev);
- edev->ops->common->set_fp_int(edev->cdev, 0);
- qede_napi_disable_remove(edev);
- qede_free_mem_load(edev);
- qede_free_fp_array(edev);
- out:
- if (!is_locked)
- __qede_unlock(edev);
- DP_INFO(edev, "Ending qede unload\n");
- }
- enum qede_load_mode {
- QEDE_LOAD_NORMAL,
- QEDE_LOAD_RELOAD,
- };
- static int qede_load(struct qede_dev *edev, enum qede_load_mode mode,
- bool is_locked)
- {
- struct qed_link_params link_params;
- struct qed_link_output link_output;
- int rc;
- DP_INFO(edev, "Starting qede load\n");
- if (!is_locked)
- __qede_lock(edev);
- rc = qede_set_num_queues(edev);
- if (rc)
- goto out;
- rc = qede_alloc_fp_array(edev);
- if (rc)
- goto out;
- qede_init_fp(edev);
- rc = qede_alloc_mem_load(edev);
- if (rc)
- goto err1;
- DP_INFO(edev, "Allocated %d Rx, %d Tx queues\n",
- QEDE_RSS_COUNT(edev), QEDE_TSS_COUNT(edev));
- rc = qede_set_real_num_queues(edev);
- if (rc)
- goto err2;
- qede_napi_add_enable(edev);
- DP_INFO(edev, "Napi added and enabled\n");
- rc = qede_setup_irqs(edev);
- if (rc)
- goto err3;
- DP_INFO(edev, "Setup IRQs succeeded\n");
- rc = qede_start_queues(edev, mode != QEDE_LOAD_RELOAD);
- if (rc)
- goto err4;
- DP_INFO(edev, "Start VPORT, RXQ and TXQ succeeded\n");
- /* Add primary mac and set Rx filters */
- ether_addr_copy(edev->primary_mac, edev->ndev->dev_addr);
- /* Program un-configured VLANs */
- qede_configure_vlan_filters(edev);
- /* Ask for link-up using current configuration */
- memset(&link_params, 0, sizeof(link_params));
- link_params.link_up = true;
- edev->ops->common->set_link(edev->cdev, &link_params);
- /* Query whether link is already-up */
- memset(&link_output, 0, sizeof(link_output));
- edev->ops->common->get_link(edev->cdev, &link_output);
- qede_roce_dev_event_open(edev);
- qede_link_update(edev, &link_output);
- edev->state = QEDE_STATE_OPEN;
- DP_INFO(edev, "Ending successfully qede load\n");
- goto out;
- err4:
- qede_sync_free_irqs(edev);
- memset(&edev->int_info.msix_cnt, 0, sizeof(struct qed_int_info));
- err3:
- qede_napi_disable_remove(edev);
- err2:
- qede_free_mem_load(edev);
- err1:
- edev->ops->common->set_fp_int(edev->cdev, 0);
- qede_free_fp_array(edev);
- edev->num_queues = 0;
- edev->fp_num_tx = 0;
- edev->fp_num_rx = 0;
- out:
- if (!is_locked)
- __qede_unlock(edev);
- return rc;
- }
- /* 'func' should be able to run between unload and reload assuming interface
- * is actually running, or afterwards in case it's currently DOWN.
- */
- void qede_reload(struct qede_dev *edev,
- struct qede_reload_args *args, bool is_locked)
- {
- if (!is_locked)
- __qede_lock(edev);
- /* Since qede_lock is held, internal state wouldn't change even
- * if netdev state would start transitioning. Check whether current
- * internal configuration indicates device is up, then reload.
- */
- if (edev->state == QEDE_STATE_OPEN) {
- qede_unload(edev, QEDE_UNLOAD_NORMAL, true);
- if (args)
- args->func(edev, args);
- qede_load(edev, QEDE_LOAD_RELOAD, true);
- /* Since no one is going to do it for us, re-configure */
- qede_config_rx_mode(edev->ndev);
- } else if (args) {
- args->func(edev, args);
- }
- if (!is_locked)
- __qede_unlock(edev);
- }
- /* called with rtnl_lock */
- static int qede_open(struct net_device *ndev)
- {
- struct qede_dev *edev = netdev_priv(ndev);
- int rc;
- netif_carrier_off(ndev);
- edev->ops->common->set_power_state(edev->cdev, PCI_D0);
- rc = qede_load(edev, QEDE_LOAD_NORMAL, false);
- if (rc)
- return rc;
- udp_tunnel_get_rx_info(ndev);
- edev->ops->common->update_drv_state(edev->cdev, true);
- return 0;
- }
- static int qede_close(struct net_device *ndev)
- {
- struct qede_dev *edev = netdev_priv(ndev);
- qede_unload(edev, QEDE_UNLOAD_NORMAL, false);
- edev->ops->common->update_drv_state(edev->cdev, false);
- return 0;
- }
- static void qede_link_update(void *dev, struct qed_link_output *link)
- {
- struct qede_dev *edev = dev;
- if (!netif_running(edev->ndev)) {
- DP_VERBOSE(edev, NETIF_MSG_LINK, "Interface is not running\n");
- return;
- }
- if (link->link_up) {
- if (!netif_carrier_ok(edev->ndev)) {
- DP_NOTICE(edev, "Link is up\n");
- netif_tx_start_all_queues(edev->ndev);
- netif_carrier_on(edev->ndev);
- }
- } else {
- if (netif_carrier_ok(edev->ndev)) {
- DP_NOTICE(edev, "Link is down\n");
- netif_tx_disable(edev->ndev);
- netif_carrier_off(edev->ndev);
- }
- }
- }
- static int qede_set_mac_addr(struct net_device *ndev, void *p)
- {
- struct qede_dev *edev = netdev_priv(ndev);
- struct sockaddr *addr = p;
- int rc;
- ASSERT_RTNL(); /* @@@TBD To be removed */
- DP_INFO(edev, "Set_mac_addr called\n");
- if (!is_valid_ether_addr(addr->sa_data)) {
- DP_NOTICE(edev, "The MAC address is not valid\n");
- return -EFAULT;
- }
- if (!edev->ops->check_mac(edev->cdev, addr->sa_data)) {
- DP_NOTICE(edev, "qed prevents setting MAC\n");
- return -EINVAL;
- }
- ether_addr_copy(ndev->dev_addr, addr->sa_data);
- if (!netif_running(ndev)) {
- DP_NOTICE(edev, "The device is currently down\n");
- return 0;
- }
- /* Remove the previous primary mac */
- rc = qede_set_ucast_rx_mac(edev, QED_FILTER_XCAST_TYPE_DEL,
- edev->primary_mac);
- if (rc)
- return rc;
- edev->ops->common->update_mac(edev->cdev, addr->sa_data);
- /* Add MAC filter according to the new unicast HW MAC address */
- ether_addr_copy(edev->primary_mac, ndev->dev_addr);
- return qede_set_ucast_rx_mac(edev, QED_FILTER_XCAST_TYPE_ADD,
- edev->primary_mac);
- }
- static int
- qede_configure_mcast_filtering(struct net_device *ndev,
- enum qed_filter_rx_mode_type *accept_flags)
- {
- struct qede_dev *edev = netdev_priv(ndev);
- unsigned char *mc_macs, *temp;
- struct netdev_hw_addr *ha;
- int rc = 0, mc_count;
- size_t size;
- size = 64 * ETH_ALEN;
- mc_macs = kzalloc(size, GFP_KERNEL);
- if (!mc_macs) {
- DP_NOTICE(edev,
- "Failed to allocate memory for multicast MACs\n");
- rc = -ENOMEM;
- goto exit;
- }
- temp = mc_macs;
- /* Remove all previously configured MAC filters */
- rc = qede_set_mcast_rx_mac(edev, QED_FILTER_XCAST_TYPE_DEL,
- mc_macs, 1);
- if (rc)
- goto exit;
- netif_addr_lock_bh(ndev);
- mc_count = netdev_mc_count(ndev);
- if (mc_count < 64) {
- netdev_for_each_mc_addr(ha, ndev) {
- ether_addr_copy(temp, ha->addr);
- temp += ETH_ALEN;
- }
- }
- netif_addr_unlock_bh(ndev);
- /* Check for all multicast @@@TBD resource allocation */
- if ((ndev->flags & IFF_ALLMULTI) ||
- (mc_count > 64)) {
- if (*accept_flags == QED_FILTER_RX_MODE_TYPE_REGULAR)
- *accept_flags = QED_FILTER_RX_MODE_TYPE_MULTI_PROMISC;
- } else {
- /* Add all multicast MAC filters */
- rc = qede_set_mcast_rx_mac(edev, QED_FILTER_XCAST_TYPE_ADD,
- mc_macs, mc_count);
- }
- exit:
- kfree(mc_macs);
- return rc;
- }
- static void qede_set_rx_mode(struct net_device *ndev)
- {
- struct qede_dev *edev = netdev_priv(ndev);
- set_bit(QEDE_SP_RX_MODE, &edev->sp_flags);
- schedule_delayed_work(&edev->sp_task, 0);
- }
- /* Must be called with qede_lock held */
- static void qede_config_rx_mode(struct net_device *ndev)
- {
- enum qed_filter_rx_mode_type accept_flags = QED_FILTER_TYPE_UCAST;
- struct qede_dev *edev = netdev_priv(ndev);
- struct qed_filter_params rx_mode;
- unsigned char *uc_macs, *temp;
- struct netdev_hw_addr *ha;
- int rc, uc_count;
- size_t size;
- netif_addr_lock_bh(ndev);
- uc_count = netdev_uc_count(ndev);
- size = uc_count * ETH_ALEN;
- uc_macs = kzalloc(size, GFP_ATOMIC);
- if (!uc_macs) {
- DP_NOTICE(edev, "Failed to allocate memory for unicast MACs\n");
- netif_addr_unlock_bh(ndev);
- return;
- }
- temp = uc_macs;
- netdev_for_each_uc_addr(ha, ndev) {
- ether_addr_copy(temp, ha->addr);
- temp += ETH_ALEN;
- }
- netif_addr_unlock_bh(ndev);
- /* Configure the struct for the Rx mode */
- memset(&rx_mode, 0, sizeof(struct qed_filter_params));
- rx_mode.type = QED_FILTER_TYPE_RX_MODE;
- /* Remove all previous unicast secondary macs and multicast macs
- * (configrue / leave the primary mac)
- */
- rc = qede_set_ucast_rx_mac(edev, QED_FILTER_XCAST_TYPE_REPLACE,
- edev->primary_mac);
- if (rc)
- goto out;
- /* Check for promiscuous */
- if ((ndev->flags & IFF_PROMISC) ||
- (uc_count > edev->dev_info.num_mac_filters - 1)) {
- accept_flags = QED_FILTER_RX_MODE_TYPE_PROMISC;
- } else {
- /* Add MAC filters according to the unicast secondary macs */
- int i;
- temp = uc_macs;
- for (i = 0; i < uc_count; i++) {
- rc = qede_set_ucast_rx_mac(edev,
- QED_FILTER_XCAST_TYPE_ADD,
- temp);
- if (rc)
- goto out;
- temp += ETH_ALEN;
- }
- rc = qede_configure_mcast_filtering(ndev, &accept_flags);
- if (rc)
- goto out;
- }
- /* take care of VLAN mode */
- if (ndev->flags & IFF_PROMISC) {
- qede_config_accept_any_vlan(edev, true);
- } else if (!edev->non_configured_vlans) {
- /* It's possible that accept_any_vlan mode is set due to a
- * previous setting of IFF_PROMISC. If vlan credits are
- * sufficient, disable accept_any_vlan.
- */
- qede_config_accept_any_vlan(edev, false);
- }
- rx_mode.filter.accept_flags = accept_flags;
- edev->ops->filter_config(edev->cdev, &rx_mode);
- out:
- kfree(uc_macs);
- }
|