cxgb4vf_main.c 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459
  1. /*
  2. * This file is part of the Chelsio T4 PCI-E SR-IOV Virtual Function Ethernet
  3. * driver for Linux.
  4. *
  5. * Copyright (c) 2009-2010 Chelsio Communications, Inc. All rights reserved.
  6. *
  7. * This software is available to you under a choice of one of two
  8. * licenses. You may choose to be licensed under the terms of the GNU
  9. * General Public License (GPL) Version 2, available from the file
  10. * COPYING in the main directory of this source tree, or the
  11. * OpenIB.org BSD license below:
  12. *
  13. * Redistribution and use in source and binary forms, with or
  14. * without modification, are permitted provided that the following
  15. * conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above
  18. * copyright notice, this list of conditions and the following
  19. * disclaimer.
  20. *
  21. * - Redistributions in binary form must reproduce the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer in the documentation and/or other materials
  24. * provided with the distribution.
  25. *
  26. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  30. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  31. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  32. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  33. * SOFTWARE.
  34. */
  35. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  36. #include <linux/module.h>
  37. #include <linux/moduleparam.h>
  38. #include <linux/init.h>
  39. #include <linux/pci.h>
  40. #include <linux/dma-mapping.h>
  41. #include <linux/netdevice.h>
  42. #include <linux/etherdevice.h>
  43. #include <linux/debugfs.h>
  44. #include <linux/ethtool.h>
  45. #include <linux/mdio.h>
  46. #include "t4vf_common.h"
  47. #include "t4vf_defs.h"
  48. #include "../cxgb4/t4_regs.h"
  49. #include "../cxgb4/t4_msg.h"
  50. /*
  51. * Generic information about the driver.
  52. */
  53. #define DRV_VERSION "2.0.0-ko"
  54. #define DRV_DESC "Chelsio T4/T5/T6 Virtual Function (VF) Network Driver"
  55. /*
  56. * Module Parameters.
  57. * ==================
  58. */
  59. /*
  60. * Default ethtool "message level" for adapters.
  61. */
  62. #define DFLT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK | \
  63. NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP |\
  64. NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
  65. /*
  66. * The driver uses the best interrupt scheme available on a platform in the
  67. * order MSI-X then MSI. This parameter determines which of these schemes the
  68. * driver may consider as follows:
  69. *
  70. * msi = 2: choose from among MSI-X and MSI
  71. * msi = 1: only consider MSI interrupts
  72. *
  73. * Note that unlike the Physical Function driver, this Virtual Function driver
  74. * does _not_ support legacy INTx interrupts (this limitation is mandated by
  75. * the PCI-E SR-IOV standard).
  76. */
  77. #define MSI_MSIX 2
  78. #define MSI_MSI 1
  79. #define MSI_DEFAULT MSI_MSIX
  80. static int msi = MSI_DEFAULT;
  81. module_param(msi, int, 0644);
  82. MODULE_PARM_DESC(msi, "whether to use MSI-X or MSI");
  83. /*
  84. * Fundamental constants.
  85. * ======================
  86. */
  87. enum {
  88. MAX_TXQ_ENTRIES = 16384,
  89. MAX_RSPQ_ENTRIES = 16384,
  90. MAX_RX_BUFFERS = 16384,
  91. MIN_TXQ_ENTRIES = 32,
  92. MIN_RSPQ_ENTRIES = 128,
  93. MIN_FL_ENTRIES = 16,
  94. /*
  95. * For purposes of manipulating the Free List size we need to
  96. * recognize that Free Lists are actually Egress Queues (the host
  97. * produces free buffers which the hardware consumes), Egress Queues
  98. * indices are all in units of Egress Context Units bytes, and free
  99. * list entries are 64-bit PCI DMA addresses. And since the state of
  100. * the Producer Index == the Consumer Index implies an EMPTY list, we
  101. * always have at least one Egress Unit's worth of Free List entries
  102. * unused. See sge.c for more details ...
  103. */
  104. EQ_UNIT = SGE_EQ_IDXSIZE,
  105. FL_PER_EQ_UNIT = EQ_UNIT / sizeof(__be64),
  106. MIN_FL_RESID = FL_PER_EQ_UNIT,
  107. };
  108. /*
  109. * Global driver state.
  110. * ====================
  111. */
  112. static struct dentry *cxgb4vf_debugfs_root;
  113. /*
  114. * OS "Callback" functions.
  115. * ========================
  116. */
  117. /*
  118. * The link status has changed on the indicated "port" (Virtual Interface).
  119. */
  120. void t4vf_os_link_changed(struct adapter *adapter, int pidx, int link_ok)
  121. {
  122. struct net_device *dev = adapter->port[pidx];
  123. /*
  124. * If the port is disabled or the current recorded "link up"
  125. * status matches the new status, just return.
  126. */
  127. if (!netif_running(dev) || link_ok == netif_carrier_ok(dev))
  128. return;
  129. /*
  130. * Tell the OS that the link status has changed and print a short
  131. * informative message on the console about the event.
  132. */
  133. if (link_ok) {
  134. const char *s;
  135. const char *fc;
  136. const struct port_info *pi = netdev_priv(dev);
  137. switch (pi->link_cfg.speed) {
  138. case 100:
  139. s = "100Mbps";
  140. break;
  141. case 1000:
  142. s = "1Gbps";
  143. break;
  144. case 10000:
  145. s = "10Gbps";
  146. break;
  147. case 25000:
  148. s = "25Gbps";
  149. break;
  150. case 40000:
  151. s = "40Gbps";
  152. break;
  153. case 100000:
  154. s = "100Gbps";
  155. break;
  156. default:
  157. s = "unknown";
  158. break;
  159. }
  160. switch ((int)pi->link_cfg.fc) {
  161. case PAUSE_RX:
  162. fc = "RX";
  163. break;
  164. case PAUSE_TX:
  165. fc = "TX";
  166. break;
  167. case PAUSE_RX | PAUSE_TX:
  168. fc = "RX/TX";
  169. break;
  170. default:
  171. fc = "no";
  172. break;
  173. }
  174. netdev_info(dev, "link up, %s, full-duplex, %s PAUSE\n", s, fc);
  175. } else {
  176. netdev_info(dev, "link down\n");
  177. }
  178. }
  179. /*
  180. * THe port module type has changed on the indicated "port" (Virtual
  181. * Interface).
  182. */
  183. void t4vf_os_portmod_changed(struct adapter *adapter, int pidx)
  184. {
  185. static const char * const mod_str[] = {
  186. NULL, "LR", "SR", "ER", "passive DA", "active DA", "LRM"
  187. };
  188. const struct net_device *dev = adapter->port[pidx];
  189. const struct port_info *pi = netdev_priv(dev);
  190. if (pi->mod_type == FW_PORT_MOD_TYPE_NONE)
  191. dev_info(adapter->pdev_dev, "%s: port module unplugged\n",
  192. dev->name);
  193. else if (pi->mod_type < ARRAY_SIZE(mod_str))
  194. dev_info(adapter->pdev_dev, "%s: %s port module inserted\n",
  195. dev->name, mod_str[pi->mod_type]);
  196. else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
  197. dev_info(adapter->pdev_dev, "%s: unsupported optical port "
  198. "module inserted\n", dev->name);
  199. else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
  200. dev_info(adapter->pdev_dev, "%s: unknown port module inserted,"
  201. "forcing TWINAX\n", dev->name);
  202. else if (pi->mod_type == FW_PORT_MOD_TYPE_ERROR)
  203. dev_info(adapter->pdev_dev, "%s: transceiver module error\n",
  204. dev->name);
  205. else
  206. dev_info(adapter->pdev_dev, "%s: unknown module type %d "
  207. "inserted\n", dev->name, pi->mod_type);
  208. }
  209. /*
  210. * Net device operations.
  211. * ======================
  212. */
  213. /*
  214. * Perform the MAC and PHY actions needed to enable a "port" (Virtual
  215. * Interface).
  216. */
  217. static int link_start(struct net_device *dev)
  218. {
  219. int ret;
  220. struct port_info *pi = netdev_priv(dev);
  221. /*
  222. * We do not set address filters and promiscuity here, the stack does
  223. * that step explicitly. Enable vlan accel.
  224. */
  225. ret = t4vf_set_rxmode(pi->adapter, pi->viid, dev->mtu, -1, -1, -1, 1,
  226. true);
  227. if (ret == 0) {
  228. ret = t4vf_change_mac(pi->adapter, pi->viid,
  229. pi->xact_addr_filt, dev->dev_addr, true);
  230. if (ret >= 0) {
  231. pi->xact_addr_filt = ret;
  232. ret = 0;
  233. }
  234. }
  235. /*
  236. * We don't need to actually "start the link" itself since the
  237. * firmware will do that for us when the first Virtual Interface
  238. * is enabled on a port.
  239. */
  240. if (ret == 0)
  241. ret = t4vf_enable_pi(pi->adapter, pi, true, true);
  242. /* The Virtual Interfaces are connected to an internal switch on the
  243. * chip which allows VIs attached to the same port to talk to each
  244. * other even when the port link is down. As a result, we generally
  245. * want to always report a VI's link as being "up", provided there are
  246. * no errors in enabling vi.
  247. */
  248. if (ret == 0)
  249. netif_carrier_on(dev);
  250. return ret;
  251. }
  252. /*
  253. * Name the MSI-X interrupts.
  254. */
  255. static void name_msix_vecs(struct adapter *adapter)
  256. {
  257. int namelen = sizeof(adapter->msix_info[0].desc) - 1;
  258. int pidx;
  259. /*
  260. * Firmware events.
  261. */
  262. snprintf(adapter->msix_info[MSIX_FW].desc, namelen,
  263. "%s-FWeventq", adapter->name);
  264. adapter->msix_info[MSIX_FW].desc[namelen] = 0;
  265. /*
  266. * Ethernet queues.
  267. */
  268. for_each_port(adapter, pidx) {
  269. struct net_device *dev = adapter->port[pidx];
  270. const struct port_info *pi = netdev_priv(dev);
  271. int qs, msi;
  272. for (qs = 0, msi = MSIX_IQFLINT; qs < pi->nqsets; qs++, msi++) {
  273. snprintf(adapter->msix_info[msi].desc, namelen,
  274. "%s-%d", dev->name, qs);
  275. adapter->msix_info[msi].desc[namelen] = 0;
  276. }
  277. }
  278. }
  279. /*
  280. * Request all of our MSI-X resources.
  281. */
  282. static int request_msix_queue_irqs(struct adapter *adapter)
  283. {
  284. struct sge *s = &adapter->sge;
  285. int rxq, msi, err;
  286. /*
  287. * Firmware events.
  288. */
  289. err = request_irq(adapter->msix_info[MSIX_FW].vec, t4vf_sge_intr_msix,
  290. 0, adapter->msix_info[MSIX_FW].desc, &s->fw_evtq);
  291. if (err)
  292. return err;
  293. /*
  294. * Ethernet queues.
  295. */
  296. msi = MSIX_IQFLINT;
  297. for_each_ethrxq(s, rxq) {
  298. err = request_irq(adapter->msix_info[msi].vec,
  299. t4vf_sge_intr_msix, 0,
  300. adapter->msix_info[msi].desc,
  301. &s->ethrxq[rxq].rspq);
  302. if (err)
  303. goto err_free_irqs;
  304. msi++;
  305. }
  306. return 0;
  307. err_free_irqs:
  308. while (--rxq >= 0)
  309. free_irq(adapter->msix_info[--msi].vec, &s->ethrxq[rxq].rspq);
  310. free_irq(adapter->msix_info[MSIX_FW].vec, &s->fw_evtq);
  311. return err;
  312. }
  313. /*
  314. * Free our MSI-X resources.
  315. */
  316. static void free_msix_queue_irqs(struct adapter *adapter)
  317. {
  318. struct sge *s = &adapter->sge;
  319. int rxq, msi;
  320. free_irq(adapter->msix_info[MSIX_FW].vec, &s->fw_evtq);
  321. msi = MSIX_IQFLINT;
  322. for_each_ethrxq(s, rxq)
  323. free_irq(adapter->msix_info[msi++].vec,
  324. &s->ethrxq[rxq].rspq);
  325. }
  326. /*
  327. * Turn on NAPI and start up interrupts on a response queue.
  328. */
  329. static void qenable(struct sge_rspq *rspq)
  330. {
  331. napi_enable(&rspq->napi);
  332. /*
  333. * 0-increment the Going To Sleep register to start the timer and
  334. * enable interrupts.
  335. */
  336. t4_write_reg(rspq->adapter, T4VF_SGE_BASE_ADDR + SGE_VF_GTS,
  337. CIDXINC_V(0) |
  338. SEINTARM_V(rspq->intr_params) |
  339. INGRESSQID_V(rspq->cntxt_id));
  340. }
  341. /*
  342. * Enable NAPI scheduling and interrupt generation for all Receive Queues.
  343. */
  344. static void enable_rx(struct adapter *adapter)
  345. {
  346. int rxq;
  347. struct sge *s = &adapter->sge;
  348. for_each_ethrxq(s, rxq)
  349. qenable(&s->ethrxq[rxq].rspq);
  350. qenable(&s->fw_evtq);
  351. /*
  352. * The interrupt queue doesn't use NAPI so we do the 0-increment of
  353. * its Going To Sleep register here to get it started.
  354. */
  355. if (adapter->flags & USING_MSI)
  356. t4_write_reg(adapter, T4VF_SGE_BASE_ADDR + SGE_VF_GTS,
  357. CIDXINC_V(0) |
  358. SEINTARM_V(s->intrq.intr_params) |
  359. INGRESSQID_V(s->intrq.cntxt_id));
  360. }
  361. /*
  362. * Wait until all NAPI handlers are descheduled.
  363. */
  364. static void quiesce_rx(struct adapter *adapter)
  365. {
  366. struct sge *s = &adapter->sge;
  367. int rxq;
  368. for_each_ethrxq(s, rxq)
  369. napi_disable(&s->ethrxq[rxq].rspq.napi);
  370. napi_disable(&s->fw_evtq.napi);
  371. }
  372. /*
  373. * Response queue handler for the firmware event queue.
  374. */
  375. static int fwevtq_handler(struct sge_rspq *rspq, const __be64 *rsp,
  376. const struct pkt_gl *gl)
  377. {
  378. /*
  379. * Extract response opcode and get pointer to CPL message body.
  380. */
  381. struct adapter *adapter = rspq->adapter;
  382. u8 opcode = ((const struct rss_header *)rsp)->opcode;
  383. void *cpl = (void *)(rsp + 1);
  384. switch (opcode) {
  385. case CPL_FW6_MSG: {
  386. /*
  387. * We've received an asynchronous message from the firmware.
  388. */
  389. const struct cpl_fw6_msg *fw_msg = cpl;
  390. if (fw_msg->type == FW6_TYPE_CMD_RPL)
  391. t4vf_handle_fw_rpl(adapter, fw_msg->data);
  392. break;
  393. }
  394. case CPL_FW4_MSG: {
  395. /* FW can send EGR_UPDATEs encapsulated in a CPL_FW4_MSG.
  396. */
  397. const struct cpl_sge_egr_update *p = (void *)(rsp + 3);
  398. opcode = CPL_OPCODE_G(ntohl(p->opcode_qid));
  399. if (opcode != CPL_SGE_EGR_UPDATE) {
  400. dev_err(adapter->pdev_dev, "unexpected FW4/CPL %#x on FW event queue\n"
  401. , opcode);
  402. break;
  403. }
  404. cpl = (void *)p;
  405. /*FALLTHROUGH*/
  406. }
  407. case CPL_SGE_EGR_UPDATE: {
  408. /*
  409. * We've received an Egress Queue Status Update message. We
  410. * get these, if the SGE is configured to send these when the
  411. * firmware passes certain points in processing our TX
  412. * Ethernet Queue or if we make an explicit request for one.
  413. * We use these updates to determine when we may need to
  414. * restart a TX Ethernet Queue which was stopped for lack of
  415. * free TX Queue Descriptors ...
  416. */
  417. const struct cpl_sge_egr_update *p = cpl;
  418. unsigned int qid = EGR_QID_G(be32_to_cpu(p->opcode_qid));
  419. struct sge *s = &adapter->sge;
  420. struct sge_txq *tq;
  421. struct sge_eth_txq *txq;
  422. unsigned int eq_idx;
  423. /*
  424. * Perform sanity checking on the Queue ID to make sure it
  425. * really refers to one of our TX Ethernet Egress Queues which
  426. * is active and matches the queue's ID. None of these error
  427. * conditions should ever happen so we may want to either make
  428. * them fatal and/or conditionalized under DEBUG.
  429. */
  430. eq_idx = EQ_IDX(s, qid);
  431. if (unlikely(eq_idx >= MAX_EGRQ)) {
  432. dev_err(adapter->pdev_dev,
  433. "Egress Update QID %d out of range\n", qid);
  434. break;
  435. }
  436. tq = s->egr_map[eq_idx];
  437. if (unlikely(tq == NULL)) {
  438. dev_err(adapter->pdev_dev,
  439. "Egress Update QID %d TXQ=NULL\n", qid);
  440. break;
  441. }
  442. txq = container_of(tq, struct sge_eth_txq, q);
  443. if (unlikely(tq->abs_id != qid)) {
  444. dev_err(adapter->pdev_dev,
  445. "Egress Update QID %d refers to TXQ %d\n",
  446. qid, tq->abs_id);
  447. break;
  448. }
  449. /*
  450. * Restart a stopped TX Queue which has less than half of its
  451. * TX ring in use ...
  452. */
  453. txq->q.restarts++;
  454. netif_tx_wake_queue(txq->txq);
  455. break;
  456. }
  457. default:
  458. dev_err(adapter->pdev_dev,
  459. "unexpected CPL %#x on FW event queue\n", opcode);
  460. }
  461. return 0;
  462. }
  463. /*
  464. * Allocate SGE TX/RX response queues. Determine how many sets of SGE queues
  465. * to use and initializes them. We support multiple "Queue Sets" per port if
  466. * we have MSI-X, otherwise just one queue set per port.
  467. */
  468. static int setup_sge_queues(struct adapter *adapter)
  469. {
  470. struct sge *s = &adapter->sge;
  471. int err, pidx, msix;
  472. /*
  473. * Clear "Queue Set" Free List Starving and TX Queue Mapping Error
  474. * state.
  475. */
  476. bitmap_zero(s->starving_fl, MAX_EGRQ);
  477. /*
  478. * If we're using MSI interrupt mode we need to set up a "forwarded
  479. * interrupt" queue which we'll set up with our MSI vector. The rest
  480. * of the ingress queues will be set up to forward their interrupts to
  481. * this queue ... This must be first since t4vf_sge_alloc_rxq() uses
  482. * the intrq's queue ID as the interrupt forwarding queue for the
  483. * subsequent calls ...
  484. */
  485. if (adapter->flags & USING_MSI) {
  486. err = t4vf_sge_alloc_rxq(adapter, &s->intrq, false,
  487. adapter->port[0], 0, NULL, NULL);
  488. if (err)
  489. goto err_free_queues;
  490. }
  491. /*
  492. * Allocate our ingress queue for asynchronous firmware messages.
  493. */
  494. err = t4vf_sge_alloc_rxq(adapter, &s->fw_evtq, true, adapter->port[0],
  495. MSIX_FW, NULL, fwevtq_handler);
  496. if (err)
  497. goto err_free_queues;
  498. /*
  499. * Allocate each "port"'s initial Queue Sets. These can be changed
  500. * later on ... up to the point where any interface on the adapter is
  501. * brought up at which point lots of things get nailed down
  502. * permanently ...
  503. */
  504. msix = MSIX_IQFLINT;
  505. for_each_port(adapter, pidx) {
  506. struct net_device *dev = adapter->port[pidx];
  507. struct port_info *pi = netdev_priv(dev);
  508. struct sge_eth_rxq *rxq = &s->ethrxq[pi->first_qset];
  509. struct sge_eth_txq *txq = &s->ethtxq[pi->first_qset];
  510. int qs;
  511. for (qs = 0; qs < pi->nqsets; qs++, rxq++, txq++) {
  512. err = t4vf_sge_alloc_rxq(adapter, &rxq->rspq, false,
  513. dev, msix++,
  514. &rxq->fl, t4vf_ethrx_handler);
  515. if (err)
  516. goto err_free_queues;
  517. err = t4vf_sge_alloc_eth_txq(adapter, txq, dev,
  518. netdev_get_tx_queue(dev, qs),
  519. s->fw_evtq.cntxt_id);
  520. if (err)
  521. goto err_free_queues;
  522. rxq->rspq.idx = qs;
  523. memset(&rxq->stats, 0, sizeof(rxq->stats));
  524. }
  525. }
  526. /*
  527. * Create the reverse mappings for the queues.
  528. */
  529. s->egr_base = s->ethtxq[0].q.abs_id - s->ethtxq[0].q.cntxt_id;
  530. s->ingr_base = s->ethrxq[0].rspq.abs_id - s->ethrxq[0].rspq.cntxt_id;
  531. IQ_MAP(s, s->fw_evtq.abs_id) = &s->fw_evtq;
  532. for_each_port(adapter, pidx) {
  533. struct net_device *dev = adapter->port[pidx];
  534. struct port_info *pi = netdev_priv(dev);
  535. struct sge_eth_rxq *rxq = &s->ethrxq[pi->first_qset];
  536. struct sge_eth_txq *txq = &s->ethtxq[pi->first_qset];
  537. int qs;
  538. for (qs = 0; qs < pi->nqsets; qs++, rxq++, txq++) {
  539. IQ_MAP(s, rxq->rspq.abs_id) = &rxq->rspq;
  540. EQ_MAP(s, txq->q.abs_id) = &txq->q;
  541. /*
  542. * The FW_IQ_CMD doesn't return the Absolute Queue IDs
  543. * for Free Lists but since all of the Egress Queues
  544. * (including Free Lists) have Relative Queue IDs
  545. * which are computed as Absolute - Base Queue ID, we
  546. * can synthesize the Absolute Queue IDs for the Free
  547. * Lists. This is useful for debugging purposes when
  548. * we want to dump Queue Contexts via the PF Driver.
  549. */
  550. rxq->fl.abs_id = rxq->fl.cntxt_id + s->egr_base;
  551. EQ_MAP(s, rxq->fl.abs_id) = &rxq->fl;
  552. }
  553. }
  554. return 0;
  555. err_free_queues:
  556. t4vf_free_sge_resources(adapter);
  557. return err;
  558. }
  559. /*
  560. * Set up Receive Side Scaling (RSS) to distribute packets to multiple receive
  561. * queues. We configure the RSS CPU lookup table to distribute to the number
  562. * of HW receive queues, and the response queue lookup table to narrow that
  563. * down to the response queues actually configured for each "port" (Virtual
  564. * Interface). We always configure the RSS mapping for all ports since the
  565. * mapping table has plenty of entries.
  566. */
  567. static int setup_rss(struct adapter *adapter)
  568. {
  569. int pidx;
  570. for_each_port(adapter, pidx) {
  571. struct port_info *pi = adap2pinfo(adapter, pidx);
  572. struct sge_eth_rxq *rxq = &adapter->sge.ethrxq[pi->first_qset];
  573. u16 rss[MAX_PORT_QSETS];
  574. int qs, err;
  575. for (qs = 0; qs < pi->nqsets; qs++)
  576. rss[qs] = rxq[qs].rspq.abs_id;
  577. err = t4vf_config_rss_range(adapter, pi->viid,
  578. 0, pi->rss_size, rss, pi->nqsets);
  579. if (err)
  580. return err;
  581. /*
  582. * Perform Global RSS Mode-specific initialization.
  583. */
  584. switch (adapter->params.rss.mode) {
  585. case FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL:
  586. /*
  587. * If Tunnel All Lookup isn't specified in the global
  588. * RSS Configuration, then we need to specify a
  589. * default Ingress Queue for any ingress packets which
  590. * aren't hashed. We'll use our first ingress queue
  591. * ...
  592. */
  593. if (!adapter->params.rss.u.basicvirtual.tnlalllookup) {
  594. union rss_vi_config config;
  595. err = t4vf_read_rss_vi_config(adapter,
  596. pi->viid,
  597. &config);
  598. if (err)
  599. return err;
  600. config.basicvirtual.defaultq =
  601. rxq[0].rspq.abs_id;
  602. err = t4vf_write_rss_vi_config(adapter,
  603. pi->viid,
  604. &config);
  605. if (err)
  606. return err;
  607. }
  608. break;
  609. }
  610. }
  611. return 0;
  612. }
  613. /*
  614. * Bring the adapter up. Called whenever we go from no "ports" open to having
  615. * one open. This function performs the actions necessary to make an adapter
  616. * operational, such as completing the initialization of HW modules, and
  617. * enabling interrupts. Must be called with the rtnl lock held. (Note that
  618. * this is called "cxgb_up" in the PF Driver.)
  619. */
  620. static int adapter_up(struct adapter *adapter)
  621. {
  622. int err;
  623. /*
  624. * If this is the first time we've been called, perform basic
  625. * adapter setup. Once we've done this, many of our adapter
  626. * parameters can no longer be changed ...
  627. */
  628. if ((adapter->flags & FULL_INIT_DONE) == 0) {
  629. err = setup_sge_queues(adapter);
  630. if (err)
  631. return err;
  632. err = setup_rss(adapter);
  633. if (err) {
  634. t4vf_free_sge_resources(adapter);
  635. return err;
  636. }
  637. if (adapter->flags & USING_MSIX)
  638. name_msix_vecs(adapter);
  639. /* Initialize hash mac addr list*/
  640. INIT_LIST_HEAD(&adapter->mac_hlist);
  641. adapter->flags |= FULL_INIT_DONE;
  642. }
  643. /*
  644. * Acquire our interrupt resources. We only support MSI-X and MSI.
  645. */
  646. BUG_ON((adapter->flags & (USING_MSIX|USING_MSI)) == 0);
  647. if (adapter->flags & USING_MSIX)
  648. err = request_msix_queue_irqs(adapter);
  649. else
  650. err = request_irq(adapter->pdev->irq,
  651. t4vf_intr_handler(adapter), 0,
  652. adapter->name, adapter);
  653. if (err) {
  654. dev_err(adapter->pdev_dev, "request_irq failed, err %d\n",
  655. err);
  656. return err;
  657. }
  658. /*
  659. * Enable NAPI ingress processing and return success.
  660. */
  661. enable_rx(adapter);
  662. t4vf_sge_start(adapter);
  663. return 0;
  664. }
  665. /*
  666. * Bring the adapter down. Called whenever the last "port" (Virtual
  667. * Interface) closed. (Note that this routine is called "cxgb_down" in the PF
  668. * Driver.)
  669. */
  670. static void adapter_down(struct adapter *adapter)
  671. {
  672. /*
  673. * Free interrupt resources.
  674. */
  675. if (adapter->flags & USING_MSIX)
  676. free_msix_queue_irqs(adapter);
  677. else
  678. free_irq(adapter->pdev->irq, adapter);
  679. /*
  680. * Wait for NAPI handlers to finish.
  681. */
  682. quiesce_rx(adapter);
  683. }
  684. /*
  685. * Start up a net device.
  686. */
  687. static int cxgb4vf_open(struct net_device *dev)
  688. {
  689. int err;
  690. struct port_info *pi = netdev_priv(dev);
  691. struct adapter *adapter = pi->adapter;
  692. /*
  693. * If this is the first interface that we're opening on the "adapter",
  694. * bring the "adapter" up now.
  695. */
  696. if (adapter->open_device_map == 0) {
  697. err = adapter_up(adapter);
  698. if (err)
  699. return err;
  700. }
  701. /*
  702. * Note that this interface is up and start everything up ...
  703. */
  704. err = link_start(dev);
  705. if (err)
  706. goto err_unwind;
  707. pi->vlan_id = t4vf_get_vf_vlan_acl(adapter);
  708. netif_tx_start_all_queues(dev);
  709. set_bit(pi->port_id, &adapter->open_device_map);
  710. return 0;
  711. err_unwind:
  712. if (adapter->open_device_map == 0)
  713. adapter_down(adapter);
  714. return err;
  715. }
  716. /*
  717. * Shut down a net device. This routine is called "cxgb_close" in the PF
  718. * Driver ...
  719. */
  720. static int cxgb4vf_stop(struct net_device *dev)
  721. {
  722. struct port_info *pi = netdev_priv(dev);
  723. struct adapter *adapter = pi->adapter;
  724. netif_tx_stop_all_queues(dev);
  725. netif_carrier_off(dev);
  726. t4vf_enable_pi(adapter, pi, false, false);
  727. clear_bit(pi->port_id, &adapter->open_device_map);
  728. if (adapter->open_device_map == 0)
  729. adapter_down(adapter);
  730. return 0;
  731. }
  732. /*
  733. * Translate our basic statistics into the standard "ifconfig" statistics.
  734. */
  735. static struct net_device_stats *cxgb4vf_get_stats(struct net_device *dev)
  736. {
  737. struct t4vf_port_stats stats;
  738. struct port_info *pi = netdev2pinfo(dev);
  739. struct adapter *adapter = pi->adapter;
  740. struct net_device_stats *ns = &dev->stats;
  741. int err;
  742. spin_lock(&adapter->stats_lock);
  743. err = t4vf_get_port_stats(adapter, pi->pidx, &stats);
  744. spin_unlock(&adapter->stats_lock);
  745. memset(ns, 0, sizeof(*ns));
  746. if (err)
  747. return ns;
  748. ns->tx_bytes = (stats.tx_bcast_bytes + stats.tx_mcast_bytes +
  749. stats.tx_ucast_bytes + stats.tx_offload_bytes);
  750. ns->tx_packets = (stats.tx_bcast_frames + stats.tx_mcast_frames +
  751. stats.tx_ucast_frames + stats.tx_offload_frames);
  752. ns->rx_bytes = (stats.rx_bcast_bytes + stats.rx_mcast_bytes +
  753. stats.rx_ucast_bytes);
  754. ns->rx_packets = (stats.rx_bcast_frames + stats.rx_mcast_frames +
  755. stats.rx_ucast_frames);
  756. ns->multicast = stats.rx_mcast_frames;
  757. ns->tx_errors = stats.tx_drop_frames;
  758. ns->rx_errors = stats.rx_err_frames;
  759. return ns;
  760. }
  761. static inline int cxgb4vf_set_addr_hash(struct port_info *pi)
  762. {
  763. struct adapter *adapter = pi->adapter;
  764. u64 vec = 0;
  765. bool ucast = false;
  766. struct hash_mac_addr *entry;
  767. /* Calculate the hash vector for the updated list and program it */
  768. list_for_each_entry(entry, &adapter->mac_hlist, list) {
  769. ucast |= is_unicast_ether_addr(entry->addr);
  770. vec |= (1ULL << hash_mac_addr(entry->addr));
  771. }
  772. return t4vf_set_addr_hash(adapter, pi->viid, ucast, vec, false);
  773. }
  774. static int cxgb4vf_mac_sync(struct net_device *netdev, const u8 *mac_addr)
  775. {
  776. struct port_info *pi = netdev_priv(netdev);
  777. struct adapter *adapter = pi->adapter;
  778. int ret;
  779. u64 mhash = 0;
  780. u64 uhash = 0;
  781. bool free = false;
  782. bool ucast = is_unicast_ether_addr(mac_addr);
  783. const u8 *maclist[1] = {mac_addr};
  784. struct hash_mac_addr *new_entry;
  785. ret = t4vf_alloc_mac_filt(adapter, pi->viid, free, 1, maclist,
  786. NULL, ucast ? &uhash : &mhash, false);
  787. if (ret < 0)
  788. goto out;
  789. /* if hash != 0, then add the addr to hash addr list
  790. * so on the end we will calculate the hash for the
  791. * list and program it
  792. */
  793. if (uhash || mhash) {
  794. new_entry = kzalloc(sizeof(*new_entry), GFP_ATOMIC);
  795. if (!new_entry)
  796. return -ENOMEM;
  797. ether_addr_copy(new_entry->addr, mac_addr);
  798. list_add_tail(&new_entry->list, &adapter->mac_hlist);
  799. ret = cxgb4vf_set_addr_hash(pi);
  800. }
  801. out:
  802. return ret < 0 ? ret : 0;
  803. }
  804. static int cxgb4vf_mac_unsync(struct net_device *netdev, const u8 *mac_addr)
  805. {
  806. struct port_info *pi = netdev_priv(netdev);
  807. struct adapter *adapter = pi->adapter;
  808. int ret;
  809. const u8 *maclist[1] = {mac_addr};
  810. struct hash_mac_addr *entry, *tmp;
  811. /* If the MAC address to be removed is in the hash addr
  812. * list, delete it from the list and update hash vector
  813. */
  814. list_for_each_entry_safe(entry, tmp, &adapter->mac_hlist, list) {
  815. if (ether_addr_equal(entry->addr, mac_addr)) {
  816. list_del(&entry->list);
  817. kfree(entry);
  818. return cxgb4vf_set_addr_hash(pi);
  819. }
  820. }
  821. ret = t4vf_free_mac_filt(adapter, pi->viid, 1, maclist, false);
  822. return ret < 0 ? -EINVAL : 0;
  823. }
  824. /*
  825. * Set RX properties of a port, such as promiscruity, address filters, and MTU.
  826. * If @mtu is -1 it is left unchanged.
  827. */
  828. static int set_rxmode(struct net_device *dev, int mtu, bool sleep_ok)
  829. {
  830. struct port_info *pi = netdev_priv(dev);
  831. __dev_uc_sync(dev, cxgb4vf_mac_sync, cxgb4vf_mac_unsync);
  832. __dev_mc_sync(dev, cxgb4vf_mac_sync, cxgb4vf_mac_unsync);
  833. return t4vf_set_rxmode(pi->adapter, pi->viid, -1,
  834. (dev->flags & IFF_PROMISC) != 0,
  835. (dev->flags & IFF_ALLMULTI) != 0,
  836. 1, -1, sleep_ok);
  837. }
  838. /*
  839. * Set the current receive modes on the device.
  840. */
  841. static void cxgb4vf_set_rxmode(struct net_device *dev)
  842. {
  843. /* unfortunately we can't return errors to the stack */
  844. set_rxmode(dev, -1, false);
  845. }
  846. /*
  847. * Find the entry in the interrupt holdoff timer value array which comes
  848. * closest to the specified interrupt holdoff value.
  849. */
  850. static int closest_timer(const struct sge *s, int us)
  851. {
  852. int i, timer_idx = 0, min_delta = INT_MAX;
  853. for (i = 0; i < ARRAY_SIZE(s->timer_val); i++) {
  854. int delta = us - s->timer_val[i];
  855. if (delta < 0)
  856. delta = -delta;
  857. if (delta < min_delta) {
  858. min_delta = delta;
  859. timer_idx = i;
  860. }
  861. }
  862. return timer_idx;
  863. }
  864. static int closest_thres(const struct sge *s, int thres)
  865. {
  866. int i, delta, pktcnt_idx = 0, min_delta = INT_MAX;
  867. for (i = 0; i < ARRAY_SIZE(s->counter_val); i++) {
  868. delta = thres - s->counter_val[i];
  869. if (delta < 0)
  870. delta = -delta;
  871. if (delta < min_delta) {
  872. min_delta = delta;
  873. pktcnt_idx = i;
  874. }
  875. }
  876. return pktcnt_idx;
  877. }
  878. /*
  879. * Return a queue's interrupt hold-off time in us. 0 means no timer.
  880. */
  881. static unsigned int qtimer_val(const struct adapter *adapter,
  882. const struct sge_rspq *rspq)
  883. {
  884. unsigned int timer_idx = QINTR_TIMER_IDX_G(rspq->intr_params);
  885. return timer_idx < SGE_NTIMERS
  886. ? adapter->sge.timer_val[timer_idx]
  887. : 0;
  888. }
  889. /**
  890. * set_rxq_intr_params - set a queue's interrupt holdoff parameters
  891. * @adapter: the adapter
  892. * @rspq: the RX response queue
  893. * @us: the hold-off time in us, or 0 to disable timer
  894. * @cnt: the hold-off packet count, or 0 to disable counter
  895. *
  896. * Sets an RX response queue's interrupt hold-off time and packet count.
  897. * At least one of the two needs to be enabled for the queue to generate
  898. * interrupts.
  899. */
  900. static int set_rxq_intr_params(struct adapter *adapter, struct sge_rspq *rspq,
  901. unsigned int us, unsigned int cnt)
  902. {
  903. unsigned int timer_idx;
  904. /*
  905. * If both the interrupt holdoff timer and count are specified as
  906. * zero, default to a holdoff count of 1 ...
  907. */
  908. if ((us | cnt) == 0)
  909. cnt = 1;
  910. /*
  911. * If an interrupt holdoff count has been specified, then find the
  912. * closest configured holdoff count and use that. If the response
  913. * queue has already been created, then update its queue context
  914. * parameters ...
  915. */
  916. if (cnt) {
  917. int err;
  918. u32 v, pktcnt_idx;
  919. pktcnt_idx = closest_thres(&adapter->sge, cnt);
  920. if (rspq->desc && rspq->pktcnt_idx != pktcnt_idx) {
  921. v = FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DMAQ) |
  922. FW_PARAMS_PARAM_X_V(
  923. FW_PARAMS_PARAM_DMAQ_IQ_INTCNTTHRESH) |
  924. FW_PARAMS_PARAM_YZ_V(rspq->cntxt_id);
  925. err = t4vf_set_params(adapter, 1, &v, &pktcnt_idx);
  926. if (err)
  927. return err;
  928. }
  929. rspq->pktcnt_idx = pktcnt_idx;
  930. }
  931. /*
  932. * Compute the closest holdoff timer index from the supplied holdoff
  933. * timer value.
  934. */
  935. timer_idx = (us == 0
  936. ? SGE_TIMER_RSTRT_CNTR
  937. : closest_timer(&adapter->sge, us));
  938. /*
  939. * Update the response queue's interrupt coalescing parameters and
  940. * return success.
  941. */
  942. rspq->intr_params = (QINTR_TIMER_IDX_V(timer_idx) |
  943. QINTR_CNT_EN_V(cnt > 0));
  944. return 0;
  945. }
  946. /*
  947. * Return a version number to identify the type of adapter. The scheme is:
  948. * - bits 0..9: chip version
  949. * - bits 10..15: chip revision
  950. */
  951. static inline unsigned int mk_adap_vers(const struct adapter *adapter)
  952. {
  953. /*
  954. * Chip version 4, revision 0x3f (cxgb4vf).
  955. */
  956. return CHELSIO_CHIP_VERSION(adapter->params.chip) | (0x3f << 10);
  957. }
  958. /*
  959. * Execute the specified ioctl command.
  960. */
  961. static int cxgb4vf_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  962. {
  963. int ret = 0;
  964. switch (cmd) {
  965. /*
  966. * The VF Driver doesn't have access to any of the other
  967. * common Ethernet device ioctl()'s (like reading/writing
  968. * PHY registers, etc.
  969. */
  970. default:
  971. ret = -EOPNOTSUPP;
  972. break;
  973. }
  974. return ret;
  975. }
  976. /*
  977. * Change the device's MTU.
  978. */
  979. static int cxgb4vf_change_mtu(struct net_device *dev, int new_mtu)
  980. {
  981. int ret;
  982. struct port_info *pi = netdev_priv(dev);
  983. ret = t4vf_set_rxmode(pi->adapter, pi->viid, new_mtu,
  984. -1, -1, -1, -1, true);
  985. if (!ret)
  986. dev->mtu = new_mtu;
  987. return ret;
  988. }
  989. static netdev_features_t cxgb4vf_fix_features(struct net_device *dev,
  990. netdev_features_t features)
  991. {
  992. /*
  993. * Since there is no support for separate rx/tx vlan accel
  994. * enable/disable make sure tx flag is always in same state as rx.
  995. */
  996. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  997. features |= NETIF_F_HW_VLAN_CTAG_TX;
  998. else
  999. features &= ~NETIF_F_HW_VLAN_CTAG_TX;
  1000. return features;
  1001. }
  1002. static int cxgb4vf_set_features(struct net_device *dev,
  1003. netdev_features_t features)
  1004. {
  1005. struct port_info *pi = netdev_priv(dev);
  1006. netdev_features_t changed = dev->features ^ features;
  1007. if (changed & NETIF_F_HW_VLAN_CTAG_RX)
  1008. t4vf_set_rxmode(pi->adapter, pi->viid, -1, -1, -1, -1,
  1009. features & NETIF_F_HW_VLAN_CTAG_TX, 0);
  1010. return 0;
  1011. }
  1012. /*
  1013. * Change the devices MAC address.
  1014. */
  1015. static int cxgb4vf_set_mac_addr(struct net_device *dev, void *_addr)
  1016. {
  1017. int ret;
  1018. struct sockaddr *addr = _addr;
  1019. struct port_info *pi = netdev_priv(dev);
  1020. if (!is_valid_ether_addr(addr->sa_data))
  1021. return -EADDRNOTAVAIL;
  1022. ret = t4vf_change_mac(pi->adapter, pi->viid, pi->xact_addr_filt,
  1023. addr->sa_data, true);
  1024. if (ret < 0)
  1025. return ret;
  1026. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  1027. pi->xact_addr_filt = ret;
  1028. return 0;
  1029. }
  1030. #ifdef CONFIG_NET_POLL_CONTROLLER
  1031. /*
  1032. * Poll all of our receive queues. This is called outside of normal interrupt
  1033. * context.
  1034. */
  1035. static void cxgb4vf_poll_controller(struct net_device *dev)
  1036. {
  1037. struct port_info *pi = netdev_priv(dev);
  1038. struct adapter *adapter = pi->adapter;
  1039. if (adapter->flags & USING_MSIX) {
  1040. struct sge_eth_rxq *rxq;
  1041. int nqsets;
  1042. rxq = &adapter->sge.ethrxq[pi->first_qset];
  1043. for (nqsets = pi->nqsets; nqsets; nqsets--) {
  1044. t4vf_sge_intr_msix(0, &rxq->rspq);
  1045. rxq++;
  1046. }
  1047. } else
  1048. t4vf_intr_handler(adapter)(0, adapter);
  1049. }
  1050. #endif
  1051. /*
  1052. * Ethtool operations.
  1053. * ===================
  1054. *
  1055. * Note that we don't support any ethtool operations which change the physical
  1056. * state of the port to which we're linked.
  1057. */
  1058. /**
  1059. * from_fw_port_mod_type - translate Firmware Port/Module type to Ethtool
  1060. * @port_type: Firmware Port Type
  1061. * @mod_type: Firmware Module Type
  1062. *
  1063. * Translate Firmware Port/Module type to Ethtool Port Type.
  1064. */
  1065. static int from_fw_port_mod_type(enum fw_port_type port_type,
  1066. enum fw_port_module_type mod_type)
  1067. {
  1068. if (port_type == FW_PORT_TYPE_BT_SGMII ||
  1069. port_type == FW_PORT_TYPE_BT_XFI ||
  1070. port_type == FW_PORT_TYPE_BT_XAUI) {
  1071. return PORT_TP;
  1072. } else if (port_type == FW_PORT_TYPE_FIBER_XFI ||
  1073. port_type == FW_PORT_TYPE_FIBER_XAUI) {
  1074. return PORT_FIBRE;
  1075. } else if (port_type == FW_PORT_TYPE_SFP ||
  1076. port_type == FW_PORT_TYPE_QSFP_10G ||
  1077. port_type == FW_PORT_TYPE_QSA ||
  1078. port_type == FW_PORT_TYPE_QSFP ||
  1079. port_type == FW_PORT_TYPE_CR4_QSFP ||
  1080. port_type == FW_PORT_TYPE_CR_QSFP ||
  1081. port_type == FW_PORT_TYPE_CR2_QSFP ||
  1082. port_type == FW_PORT_TYPE_SFP28) {
  1083. if (mod_type == FW_PORT_MOD_TYPE_LR ||
  1084. mod_type == FW_PORT_MOD_TYPE_SR ||
  1085. mod_type == FW_PORT_MOD_TYPE_ER ||
  1086. mod_type == FW_PORT_MOD_TYPE_LRM)
  1087. return PORT_FIBRE;
  1088. else if (mod_type == FW_PORT_MOD_TYPE_TWINAX_PASSIVE ||
  1089. mod_type == FW_PORT_MOD_TYPE_TWINAX_ACTIVE)
  1090. return PORT_DA;
  1091. else
  1092. return PORT_OTHER;
  1093. } else if (port_type == FW_PORT_TYPE_KR4_100G ||
  1094. port_type == FW_PORT_TYPE_KR_SFP28 ||
  1095. port_type == FW_PORT_TYPE_KR_XLAUI) {
  1096. return PORT_NONE;
  1097. }
  1098. return PORT_OTHER;
  1099. }
  1100. /**
  1101. * fw_caps_to_lmm - translate Firmware to ethtool Link Mode Mask
  1102. * @port_type: Firmware Port Type
  1103. * @fw_caps: Firmware Port Capabilities
  1104. * @link_mode_mask: ethtool Link Mode Mask
  1105. *
  1106. * Translate a Firmware Port Capabilities specification to an ethtool
  1107. * Link Mode Mask.
  1108. */
  1109. static void fw_caps_to_lmm(enum fw_port_type port_type,
  1110. unsigned int fw_caps,
  1111. unsigned long *link_mode_mask)
  1112. {
  1113. #define SET_LMM(__lmm_name) \
  1114. __set_bit(ETHTOOL_LINK_MODE_ ## __lmm_name ## _BIT, \
  1115. link_mode_mask)
  1116. #define FW_CAPS_TO_LMM(__fw_name, __lmm_name) \
  1117. do { \
  1118. if (fw_caps & FW_PORT_CAP32_ ## __fw_name) \
  1119. SET_LMM(__lmm_name); \
  1120. } while (0)
  1121. switch (port_type) {
  1122. case FW_PORT_TYPE_BT_SGMII:
  1123. case FW_PORT_TYPE_BT_XFI:
  1124. case FW_PORT_TYPE_BT_XAUI:
  1125. SET_LMM(TP);
  1126. FW_CAPS_TO_LMM(SPEED_100M, 100baseT_Full);
  1127. FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
  1128. FW_CAPS_TO_LMM(SPEED_10G, 10000baseT_Full);
  1129. break;
  1130. case FW_PORT_TYPE_KX4:
  1131. case FW_PORT_TYPE_KX:
  1132. SET_LMM(Backplane);
  1133. FW_CAPS_TO_LMM(SPEED_1G, 1000baseKX_Full);
  1134. FW_CAPS_TO_LMM(SPEED_10G, 10000baseKX4_Full);
  1135. break;
  1136. case FW_PORT_TYPE_KR:
  1137. SET_LMM(Backplane);
  1138. FW_CAPS_TO_LMM(SPEED_10G, 10000baseKR_Full);
  1139. break;
  1140. case FW_PORT_TYPE_BP_AP:
  1141. SET_LMM(Backplane);
  1142. FW_CAPS_TO_LMM(SPEED_1G, 1000baseKX_Full);
  1143. FW_CAPS_TO_LMM(SPEED_10G, 10000baseR_FEC);
  1144. FW_CAPS_TO_LMM(SPEED_10G, 10000baseKR_Full);
  1145. break;
  1146. case FW_PORT_TYPE_BP4_AP:
  1147. SET_LMM(Backplane);
  1148. FW_CAPS_TO_LMM(SPEED_1G, 1000baseKX_Full);
  1149. FW_CAPS_TO_LMM(SPEED_10G, 10000baseR_FEC);
  1150. FW_CAPS_TO_LMM(SPEED_10G, 10000baseKR_Full);
  1151. FW_CAPS_TO_LMM(SPEED_10G, 10000baseKX4_Full);
  1152. break;
  1153. case FW_PORT_TYPE_FIBER_XFI:
  1154. case FW_PORT_TYPE_FIBER_XAUI:
  1155. case FW_PORT_TYPE_SFP:
  1156. case FW_PORT_TYPE_QSFP_10G:
  1157. case FW_PORT_TYPE_QSA:
  1158. SET_LMM(FIBRE);
  1159. FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
  1160. FW_CAPS_TO_LMM(SPEED_10G, 10000baseT_Full);
  1161. break;
  1162. case FW_PORT_TYPE_BP40_BA:
  1163. case FW_PORT_TYPE_QSFP:
  1164. SET_LMM(FIBRE);
  1165. FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
  1166. FW_CAPS_TO_LMM(SPEED_10G, 10000baseT_Full);
  1167. FW_CAPS_TO_LMM(SPEED_40G, 40000baseSR4_Full);
  1168. break;
  1169. case FW_PORT_TYPE_CR_QSFP:
  1170. case FW_PORT_TYPE_SFP28:
  1171. SET_LMM(FIBRE);
  1172. FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
  1173. FW_CAPS_TO_LMM(SPEED_10G, 10000baseT_Full);
  1174. FW_CAPS_TO_LMM(SPEED_25G, 25000baseCR_Full);
  1175. break;
  1176. case FW_PORT_TYPE_KR_SFP28:
  1177. SET_LMM(Backplane);
  1178. FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
  1179. FW_CAPS_TO_LMM(SPEED_10G, 10000baseKR_Full);
  1180. FW_CAPS_TO_LMM(SPEED_25G, 25000baseKR_Full);
  1181. break;
  1182. case FW_PORT_TYPE_KR_XLAUI:
  1183. SET_LMM(Backplane);
  1184. FW_CAPS_TO_LMM(SPEED_1G, 1000baseKX_Full);
  1185. FW_CAPS_TO_LMM(SPEED_10G, 10000baseKR_Full);
  1186. FW_CAPS_TO_LMM(SPEED_40G, 40000baseKR4_Full);
  1187. break;
  1188. case FW_PORT_TYPE_CR2_QSFP:
  1189. SET_LMM(FIBRE);
  1190. FW_CAPS_TO_LMM(SPEED_50G, 50000baseSR2_Full);
  1191. break;
  1192. case FW_PORT_TYPE_KR4_100G:
  1193. case FW_PORT_TYPE_CR4_QSFP:
  1194. SET_LMM(FIBRE);
  1195. FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
  1196. FW_CAPS_TO_LMM(SPEED_10G, 10000baseSR_Full);
  1197. FW_CAPS_TO_LMM(SPEED_40G, 40000baseSR4_Full);
  1198. FW_CAPS_TO_LMM(SPEED_25G, 25000baseCR_Full);
  1199. FW_CAPS_TO_LMM(SPEED_50G, 50000baseCR2_Full);
  1200. FW_CAPS_TO_LMM(SPEED_100G, 100000baseCR4_Full);
  1201. break;
  1202. default:
  1203. break;
  1204. }
  1205. FW_CAPS_TO_LMM(ANEG, Autoneg);
  1206. FW_CAPS_TO_LMM(802_3_PAUSE, Pause);
  1207. FW_CAPS_TO_LMM(802_3_ASM_DIR, Asym_Pause);
  1208. #undef FW_CAPS_TO_LMM
  1209. #undef SET_LMM
  1210. }
  1211. static int cxgb4vf_get_link_ksettings(struct net_device *dev,
  1212. struct ethtool_link_ksettings *link_ksettings)
  1213. {
  1214. struct port_info *pi = netdev_priv(dev);
  1215. struct ethtool_link_settings *base = &link_ksettings->base;
  1216. /* For the nonce, the Firmware doesn't send up Port State changes
  1217. * when the Virtual Interface attached to the Port is down. So
  1218. * if it's down, let's grab any changes.
  1219. */
  1220. if (!netif_running(dev))
  1221. (void)t4vf_update_port_info(pi);
  1222. ethtool_link_ksettings_zero_link_mode(link_ksettings, supported);
  1223. ethtool_link_ksettings_zero_link_mode(link_ksettings, advertising);
  1224. ethtool_link_ksettings_zero_link_mode(link_ksettings, lp_advertising);
  1225. base->port = from_fw_port_mod_type(pi->port_type, pi->mod_type);
  1226. if (pi->mdio_addr >= 0) {
  1227. base->phy_address = pi->mdio_addr;
  1228. base->mdio_support = (pi->port_type == FW_PORT_TYPE_BT_SGMII
  1229. ? ETH_MDIO_SUPPORTS_C22
  1230. : ETH_MDIO_SUPPORTS_C45);
  1231. } else {
  1232. base->phy_address = 255;
  1233. base->mdio_support = 0;
  1234. }
  1235. fw_caps_to_lmm(pi->port_type, pi->link_cfg.pcaps,
  1236. link_ksettings->link_modes.supported);
  1237. fw_caps_to_lmm(pi->port_type, pi->link_cfg.acaps,
  1238. link_ksettings->link_modes.advertising);
  1239. fw_caps_to_lmm(pi->port_type, pi->link_cfg.lpacaps,
  1240. link_ksettings->link_modes.lp_advertising);
  1241. if (netif_carrier_ok(dev)) {
  1242. base->speed = pi->link_cfg.speed;
  1243. base->duplex = DUPLEX_FULL;
  1244. } else {
  1245. base->speed = SPEED_UNKNOWN;
  1246. base->duplex = DUPLEX_UNKNOWN;
  1247. }
  1248. if (pi->link_cfg.fc & PAUSE_RX) {
  1249. if (pi->link_cfg.fc & PAUSE_TX) {
  1250. ethtool_link_ksettings_add_link_mode(link_ksettings,
  1251. advertising,
  1252. Pause);
  1253. } else {
  1254. ethtool_link_ksettings_add_link_mode(link_ksettings,
  1255. advertising,
  1256. Asym_Pause);
  1257. }
  1258. } else if (pi->link_cfg.fc & PAUSE_TX) {
  1259. ethtool_link_ksettings_add_link_mode(link_ksettings,
  1260. advertising,
  1261. Asym_Pause);
  1262. }
  1263. base->autoneg = pi->link_cfg.autoneg;
  1264. if (pi->link_cfg.pcaps & FW_PORT_CAP32_ANEG)
  1265. ethtool_link_ksettings_add_link_mode(link_ksettings,
  1266. supported, Autoneg);
  1267. if (pi->link_cfg.autoneg)
  1268. ethtool_link_ksettings_add_link_mode(link_ksettings,
  1269. advertising, Autoneg);
  1270. return 0;
  1271. }
  1272. /* Translate the Firmware FEC value into the ethtool value. */
  1273. static inline unsigned int fwcap_to_eth_fec(unsigned int fw_fec)
  1274. {
  1275. unsigned int eth_fec = 0;
  1276. if (fw_fec & FW_PORT_CAP32_FEC_RS)
  1277. eth_fec |= ETHTOOL_FEC_RS;
  1278. if (fw_fec & FW_PORT_CAP32_FEC_BASER_RS)
  1279. eth_fec |= ETHTOOL_FEC_BASER;
  1280. /* if nothing is set, then FEC is off */
  1281. if (!eth_fec)
  1282. eth_fec = ETHTOOL_FEC_OFF;
  1283. return eth_fec;
  1284. }
  1285. /* Translate Common Code FEC value into ethtool value. */
  1286. static inline unsigned int cc_to_eth_fec(unsigned int cc_fec)
  1287. {
  1288. unsigned int eth_fec = 0;
  1289. if (cc_fec & FEC_AUTO)
  1290. eth_fec |= ETHTOOL_FEC_AUTO;
  1291. if (cc_fec & FEC_RS)
  1292. eth_fec |= ETHTOOL_FEC_RS;
  1293. if (cc_fec & FEC_BASER_RS)
  1294. eth_fec |= ETHTOOL_FEC_BASER;
  1295. /* if nothing is set, then FEC is off */
  1296. if (!eth_fec)
  1297. eth_fec = ETHTOOL_FEC_OFF;
  1298. return eth_fec;
  1299. }
  1300. static int cxgb4vf_get_fecparam(struct net_device *dev,
  1301. struct ethtool_fecparam *fec)
  1302. {
  1303. const struct port_info *pi = netdev_priv(dev);
  1304. const struct link_config *lc = &pi->link_cfg;
  1305. /* Translate the Firmware FEC Support into the ethtool value. We
  1306. * always support IEEE 802.3 "automatic" selection of Link FEC type if
  1307. * any FEC is supported.
  1308. */
  1309. fec->fec = fwcap_to_eth_fec(lc->pcaps);
  1310. if (fec->fec != ETHTOOL_FEC_OFF)
  1311. fec->fec |= ETHTOOL_FEC_AUTO;
  1312. /* Translate the current internal FEC parameters into the
  1313. * ethtool values.
  1314. */
  1315. fec->active_fec = cc_to_eth_fec(lc->fec);
  1316. return 0;
  1317. }
  1318. /*
  1319. * Return our driver information.
  1320. */
  1321. static void cxgb4vf_get_drvinfo(struct net_device *dev,
  1322. struct ethtool_drvinfo *drvinfo)
  1323. {
  1324. struct adapter *adapter = netdev2adap(dev);
  1325. strlcpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
  1326. strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
  1327. strlcpy(drvinfo->bus_info, pci_name(to_pci_dev(dev->dev.parent)),
  1328. sizeof(drvinfo->bus_info));
  1329. snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
  1330. "%u.%u.%u.%u, TP %u.%u.%u.%u",
  1331. FW_HDR_FW_VER_MAJOR_G(adapter->params.dev.fwrev),
  1332. FW_HDR_FW_VER_MINOR_G(adapter->params.dev.fwrev),
  1333. FW_HDR_FW_VER_MICRO_G(adapter->params.dev.fwrev),
  1334. FW_HDR_FW_VER_BUILD_G(adapter->params.dev.fwrev),
  1335. FW_HDR_FW_VER_MAJOR_G(adapter->params.dev.tprev),
  1336. FW_HDR_FW_VER_MINOR_G(adapter->params.dev.tprev),
  1337. FW_HDR_FW_VER_MICRO_G(adapter->params.dev.tprev),
  1338. FW_HDR_FW_VER_BUILD_G(adapter->params.dev.tprev));
  1339. }
  1340. /*
  1341. * Return current adapter message level.
  1342. */
  1343. static u32 cxgb4vf_get_msglevel(struct net_device *dev)
  1344. {
  1345. return netdev2adap(dev)->msg_enable;
  1346. }
  1347. /*
  1348. * Set current adapter message level.
  1349. */
  1350. static void cxgb4vf_set_msglevel(struct net_device *dev, u32 msglevel)
  1351. {
  1352. netdev2adap(dev)->msg_enable = msglevel;
  1353. }
  1354. /*
  1355. * Return the device's current Queue Set ring size parameters along with the
  1356. * allowed maximum values. Since ethtool doesn't understand the concept of
  1357. * multi-queue devices, we just return the current values associated with the
  1358. * first Queue Set.
  1359. */
  1360. static void cxgb4vf_get_ringparam(struct net_device *dev,
  1361. struct ethtool_ringparam *rp)
  1362. {
  1363. const struct port_info *pi = netdev_priv(dev);
  1364. const struct sge *s = &pi->adapter->sge;
  1365. rp->rx_max_pending = MAX_RX_BUFFERS;
  1366. rp->rx_mini_max_pending = MAX_RSPQ_ENTRIES;
  1367. rp->rx_jumbo_max_pending = 0;
  1368. rp->tx_max_pending = MAX_TXQ_ENTRIES;
  1369. rp->rx_pending = s->ethrxq[pi->first_qset].fl.size - MIN_FL_RESID;
  1370. rp->rx_mini_pending = s->ethrxq[pi->first_qset].rspq.size;
  1371. rp->rx_jumbo_pending = 0;
  1372. rp->tx_pending = s->ethtxq[pi->first_qset].q.size;
  1373. }
  1374. /*
  1375. * Set the Queue Set ring size parameters for the device. Again, since
  1376. * ethtool doesn't allow for the concept of multiple queues per device, we'll
  1377. * apply these new values across all of the Queue Sets associated with the
  1378. * device -- after vetting them of course!
  1379. */
  1380. static int cxgb4vf_set_ringparam(struct net_device *dev,
  1381. struct ethtool_ringparam *rp)
  1382. {
  1383. const struct port_info *pi = netdev_priv(dev);
  1384. struct adapter *adapter = pi->adapter;
  1385. struct sge *s = &adapter->sge;
  1386. int qs;
  1387. if (rp->rx_pending > MAX_RX_BUFFERS ||
  1388. rp->rx_jumbo_pending ||
  1389. rp->tx_pending > MAX_TXQ_ENTRIES ||
  1390. rp->rx_mini_pending > MAX_RSPQ_ENTRIES ||
  1391. rp->rx_mini_pending < MIN_RSPQ_ENTRIES ||
  1392. rp->rx_pending < MIN_FL_ENTRIES ||
  1393. rp->tx_pending < MIN_TXQ_ENTRIES)
  1394. return -EINVAL;
  1395. if (adapter->flags & FULL_INIT_DONE)
  1396. return -EBUSY;
  1397. for (qs = pi->first_qset; qs < pi->first_qset + pi->nqsets; qs++) {
  1398. s->ethrxq[qs].fl.size = rp->rx_pending + MIN_FL_RESID;
  1399. s->ethrxq[qs].rspq.size = rp->rx_mini_pending;
  1400. s->ethtxq[qs].q.size = rp->tx_pending;
  1401. }
  1402. return 0;
  1403. }
  1404. /*
  1405. * Return the interrupt holdoff timer and count for the first Queue Set on the
  1406. * device. Our extension ioctl() (the cxgbtool interface) allows the
  1407. * interrupt holdoff timer to be read on all of the device's Queue Sets.
  1408. */
  1409. static int cxgb4vf_get_coalesce(struct net_device *dev,
  1410. struct ethtool_coalesce *coalesce)
  1411. {
  1412. const struct port_info *pi = netdev_priv(dev);
  1413. const struct adapter *adapter = pi->adapter;
  1414. const struct sge_rspq *rspq = &adapter->sge.ethrxq[pi->first_qset].rspq;
  1415. coalesce->rx_coalesce_usecs = qtimer_val(adapter, rspq);
  1416. coalesce->rx_max_coalesced_frames =
  1417. ((rspq->intr_params & QINTR_CNT_EN_F)
  1418. ? adapter->sge.counter_val[rspq->pktcnt_idx]
  1419. : 0);
  1420. return 0;
  1421. }
  1422. /*
  1423. * Set the RX interrupt holdoff timer and count for the first Queue Set on the
  1424. * interface. Our extension ioctl() (the cxgbtool interface) allows us to set
  1425. * the interrupt holdoff timer on any of the device's Queue Sets.
  1426. */
  1427. static int cxgb4vf_set_coalesce(struct net_device *dev,
  1428. struct ethtool_coalesce *coalesce)
  1429. {
  1430. const struct port_info *pi = netdev_priv(dev);
  1431. struct adapter *adapter = pi->adapter;
  1432. return set_rxq_intr_params(adapter,
  1433. &adapter->sge.ethrxq[pi->first_qset].rspq,
  1434. coalesce->rx_coalesce_usecs,
  1435. coalesce->rx_max_coalesced_frames);
  1436. }
  1437. /*
  1438. * Report current port link pause parameter settings.
  1439. */
  1440. static void cxgb4vf_get_pauseparam(struct net_device *dev,
  1441. struct ethtool_pauseparam *pauseparam)
  1442. {
  1443. struct port_info *pi = netdev_priv(dev);
  1444. pauseparam->autoneg = (pi->link_cfg.requested_fc & PAUSE_AUTONEG) != 0;
  1445. pauseparam->rx_pause = (pi->link_cfg.fc & PAUSE_RX) != 0;
  1446. pauseparam->tx_pause = (pi->link_cfg.fc & PAUSE_TX) != 0;
  1447. }
  1448. /*
  1449. * Identify the port by blinking the port's LED.
  1450. */
  1451. static int cxgb4vf_phys_id(struct net_device *dev,
  1452. enum ethtool_phys_id_state state)
  1453. {
  1454. unsigned int val;
  1455. struct port_info *pi = netdev_priv(dev);
  1456. if (state == ETHTOOL_ID_ACTIVE)
  1457. val = 0xffff;
  1458. else if (state == ETHTOOL_ID_INACTIVE)
  1459. val = 0;
  1460. else
  1461. return -EINVAL;
  1462. return t4vf_identify_port(pi->adapter, pi->viid, val);
  1463. }
  1464. /*
  1465. * Port stats maintained per queue of the port.
  1466. */
  1467. struct queue_port_stats {
  1468. u64 tso;
  1469. u64 tx_csum;
  1470. u64 rx_csum;
  1471. u64 vlan_ex;
  1472. u64 vlan_ins;
  1473. u64 lro_pkts;
  1474. u64 lro_merged;
  1475. };
  1476. /*
  1477. * Strings for the ETH_SS_STATS statistics set ("ethtool -S"). Note that
  1478. * these need to match the order of statistics returned by
  1479. * t4vf_get_port_stats().
  1480. */
  1481. static const char stats_strings[][ETH_GSTRING_LEN] = {
  1482. /*
  1483. * These must match the layout of the t4vf_port_stats structure.
  1484. */
  1485. "TxBroadcastBytes ",
  1486. "TxBroadcastFrames ",
  1487. "TxMulticastBytes ",
  1488. "TxMulticastFrames ",
  1489. "TxUnicastBytes ",
  1490. "TxUnicastFrames ",
  1491. "TxDroppedFrames ",
  1492. "TxOffloadBytes ",
  1493. "TxOffloadFrames ",
  1494. "RxBroadcastBytes ",
  1495. "RxBroadcastFrames ",
  1496. "RxMulticastBytes ",
  1497. "RxMulticastFrames ",
  1498. "RxUnicastBytes ",
  1499. "RxUnicastFrames ",
  1500. "RxErrorFrames ",
  1501. /*
  1502. * These are accumulated per-queue statistics and must match the
  1503. * order of the fields in the queue_port_stats structure.
  1504. */
  1505. "TSO ",
  1506. "TxCsumOffload ",
  1507. "RxCsumGood ",
  1508. "VLANextractions ",
  1509. "VLANinsertions ",
  1510. "GROPackets ",
  1511. "GROMerged ",
  1512. };
  1513. /*
  1514. * Return the number of statistics in the specified statistics set.
  1515. */
  1516. static int cxgb4vf_get_sset_count(struct net_device *dev, int sset)
  1517. {
  1518. switch (sset) {
  1519. case ETH_SS_STATS:
  1520. return ARRAY_SIZE(stats_strings);
  1521. default:
  1522. return -EOPNOTSUPP;
  1523. }
  1524. /*NOTREACHED*/
  1525. }
  1526. /*
  1527. * Return the strings for the specified statistics set.
  1528. */
  1529. static void cxgb4vf_get_strings(struct net_device *dev,
  1530. u32 sset,
  1531. u8 *data)
  1532. {
  1533. switch (sset) {
  1534. case ETH_SS_STATS:
  1535. memcpy(data, stats_strings, sizeof(stats_strings));
  1536. break;
  1537. }
  1538. }
  1539. /*
  1540. * Small utility routine to accumulate queue statistics across the queues of
  1541. * a "port".
  1542. */
  1543. static void collect_sge_port_stats(const struct adapter *adapter,
  1544. const struct port_info *pi,
  1545. struct queue_port_stats *stats)
  1546. {
  1547. const struct sge_eth_txq *txq = &adapter->sge.ethtxq[pi->first_qset];
  1548. const struct sge_eth_rxq *rxq = &adapter->sge.ethrxq[pi->first_qset];
  1549. int qs;
  1550. memset(stats, 0, sizeof(*stats));
  1551. for (qs = 0; qs < pi->nqsets; qs++, rxq++, txq++) {
  1552. stats->tso += txq->tso;
  1553. stats->tx_csum += txq->tx_cso;
  1554. stats->rx_csum += rxq->stats.rx_cso;
  1555. stats->vlan_ex += rxq->stats.vlan_ex;
  1556. stats->vlan_ins += txq->vlan_ins;
  1557. stats->lro_pkts += rxq->stats.lro_pkts;
  1558. stats->lro_merged += rxq->stats.lro_merged;
  1559. }
  1560. }
  1561. /*
  1562. * Return the ETH_SS_STATS statistics set.
  1563. */
  1564. static void cxgb4vf_get_ethtool_stats(struct net_device *dev,
  1565. struct ethtool_stats *stats,
  1566. u64 *data)
  1567. {
  1568. struct port_info *pi = netdev2pinfo(dev);
  1569. struct adapter *adapter = pi->adapter;
  1570. int err = t4vf_get_port_stats(adapter, pi->pidx,
  1571. (struct t4vf_port_stats *)data);
  1572. if (err)
  1573. memset(data, 0, sizeof(struct t4vf_port_stats));
  1574. data += sizeof(struct t4vf_port_stats) / sizeof(u64);
  1575. collect_sge_port_stats(adapter, pi, (struct queue_port_stats *)data);
  1576. }
  1577. /*
  1578. * Return the size of our register map.
  1579. */
  1580. static int cxgb4vf_get_regs_len(struct net_device *dev)
  1581. {
  1582. return T4VF_REGMAP_SIZE;
  1583. }
  1584. /*
  1585. * Dump a block of registers, start to end inclusive, into a buffer.
  1586. */
  1587. static void reg_block_dump(struct adapter *adapter, void *regbuf,
  1588. unsigned int start, unsigned int end)
  1589. {
  1590. u32 *bp = regbuf + start - T4VF_REGMAP_START;
  1591. for ( ; start <= end; start += sizeof(u32)) {
  1592. /*
  1593. * Avoid reading the Mailbox Control register since that
  1594. * can trigger a Mailbox Ownership Arbitration cycle and
  1595. * interfere with communication with the firmware.
  1596. */
  1597. if (start == T4VF_CIM_BASE_ADDR + CIM_VF_EXT_MAILBOX_CTRL)
  1598. *bp++ = 0xffff;
  1599. else
  1600. *bp++ = t4_read_reg(adapter, start);
  1601. }
  1602. }
  1603. /*
  1604. * Copy our entire register map into the provided buffer.
  1605. */
  1606. static void cxgb4vf_get_regs(struct net_device *dev,
  1607. struct ethtool_regs *regs,
  1608. void *regbuf)
  1609. {
  1610. struct adapter *adapter = netdev2adap(dev);
  1611. regs->version = mk_adap_vers(adapter);
  1612. /*
  1613. * Fill in register buffer with our register map.
  1614. */
  1615. memset(regbuf, 0, T4VF_REGMAP_SIZE);
  1616. reg_block_dump(adapter, regbuf,
  1617. T4VF_SGE_BASE_ADDR + T4VF_MOD_MAP_SGE_FIRST,
  1618. T4VF_SGE_BASE_ADDR + T4VF_MOD_MAP_SGE_LAST);
  1619. reg_block_dump(adapter, regbuf,
  1620. T4VF_MPS_BASE_ADDR + T4VF_MOD_MAP_MPS_FIRST,
  1621. T4VF_MPS_BASE_ADDR + T4VF_MOD_MAP_MPS_LAST);
  1622. /* T5 adds new registers in the PL Register map.
  1623. */
  1624. reg_block_dump(adapter, regbuf,
  1625. T4VF_PL_BASE_ADDR + T4VF_MOD_MAP_PL_FIRST,
  1626. T4VF_PL_BASE_ADDR + (is_t4(adapter->params.chip)
  1627. ? PL_VF_WHOAMI_A : PL_VF_REVISION_A));
  1628. reg_block_dump(adapter, regbuf,
  1629. T4VF_CIM_BASE_ADDR + T4VF_MOD_MAP_CIM_FIRST,
  1630. T4VF_CIM_BASE_ADDR + T4VF_MOD_MAP_CIM_LAST);
  1631. reg_block_dump(adapter, regbuf,
  1632. T4VF_MBDATA_BASE_ADDR + T4VF_MBDATA_FIRST,
  1633. T4VF_MBDATA_BASE_ADDR + T4VF_MBDATA_LAST);
  1634. }
  1635. /*
  1636. * Report current Wake On LAN settings.
  1637. */
  1638. static void cxgb4vf_get_wol(struct net_device *dev,
  1639. struct ethtool_wolinfo *wol)
  1640. {
  1641. wol->supported = 0;
  1642. wol->wolopts = 0;
  1643. memset(&wol->sopass, 0, sizeof(wol->sopass));
  1644. }
  1645. /*
  1646. * TCP Segmentation Offload flags which we support.
  1647. */
  1648. #define TSO_FLAGS (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN)
  1649. static const struct ethtool_ops cxgb4vf_ethtool_ops = {
  1650. .get_link_ksettings = cxgb4vf_get_link_ksettings,
  1651. .get_fecparam = cxgb4vf_get_fecparam,
  1652. .get_drvinfo = cxgb4vf_get_drvinfo,
  1653. .get_msglevel = cxgb4vf_get_msglevel,
  1654. .set_msglevel = cxgb4vf_set_msglevel,
  1655. .get_ringparam = cxgb4vf_get_ringparam,
  1656. .set_ringparam = cxgb4vf_set_ringparam,
  1657. .get_coalesce = cxgb4vf_get_coalesce,
  1658. .set_coalesce = cxgb4vf_set_coalesce,
  1659. .get_pauseparam = cxgb4vf_get_pauseparam,
  1660. .get_link = ethtool_op_get_link,
  1661. .get_strings = cxgb4vf_get_strings,
  1662. .set_phys_id = cxgb4vf_phys_id,
  1663. .get_sset_count = cxgb4vf_get_sset_count,
  1664. .get_ethtool_stats = cxgb4vf_get_ethtool_stats,
  1665. .get_regs_len = cxgb4vf_get_regs_len,
  1666. .get_regs = cxgb4vf_get_regs,
  1667. .get_wol = cxgb4vf_get_wol,
  1668. };
  1669. /*
  1670. * /sys/kernel/debug/cxgb4vf support code and data.
  1671. * ================================================
  1672. */
  1673. /*
  1674. * Show Firmware Mailbox Command/Reply Log
  1675. *
  1676. * Note that we don't do any locking when dumping the Firmware Mailbox Log so
  1677. * it's possible that we can catch things during a log update and therefore
  1678. * see partially corrupted log entries. But i9t's probably Good Enough(tm).
  1679. * If we ever decide that we want to make sure that we're dumping a coherent
  1680. * log, we'd need to perform locking in the mailbox logging and in
  1681. * mboxlog_open() where we'd need to grab the entire mailbox log in one go
  1682. * like we do for the Firmware Device Log. But as stated above, meh ...
  1683. */
  1684. static int mboxlog_show(struct seq_file *seq, void *v)
  1685. {
  1686. struct adapter *adapter = seq->private;
  1687. struct mbox_cmd_log *log = adapter->mbox_log;
  1688. struct mbox_cmd *entry;
  1689. int entry_idx, i;
  1690. if (v == SEQ_START_TOKEN) {
  1691. seq_printf(seq,
  1692. "%10s %15s %5s %5s %s\n",
  1693. "Seq#", "Tstamp", "Atime", "Etime",
  1694. "Command/Reply");
  1695. return 0;
  1696. }
  1697. entry_idx = log->cursor + ((uintptr_t)v - 2);
  1698. if (entry_idx >= log->size)
  1699. entry_idx -= log->size;
  1700. entry = mbox_cmd_log_entry(log, entry_idx);
  1701. /* skip over unused entries */
  1702. if (entry->timestamp == 0)
  1703. return 0;
  1704. seq_printf(seq, "%10u %15llu %5d %5d",
  1705. entry->seqno, entry->timestamp,
  1706. entry->access, entry->execute);
  1707. for (i = 0; i < MBOX_LEN / 8; i++) {
  1708. u64 flit = entry->cmd[i];
  1709. u32 hi = (u32)(flit >> 32);
  1710. u32 lo = (u32)flit;
  1711. seq_printf(seq, " %08x %08x", hi, lo);
  1712. }
  1713. seq_puts(seq, "\n");
  1714. return 0;
  1715. }
  1716. static inline void *mboxlog_get_idx(struct seq_file *seq, loff_t pos)
  1717. {
  1718. struct adapter *adapter = seq->private;
  1719. struct mbox_cmd_log *log = adapter->mbox_log;
  1720. return ((pos <= log->size) ? (void *)(uintptr_t)(pos + 1) : NULL);
  1721. }
  1722. static void *mboxlog_start(struct seq_file *seq, loff_t *pos)
  1723. {
  1724. return *pos ? mboxlog_get_idx(seq, *pos) : SEQ_START_TOKEN;
  1725. }
  1726. static void *mboxlog_next(struct seq_file *seq, void *v, loff_t *pos)
  1727. {
  1728. ++*pos;
  1729. return mboxlog_get_idx(seq, *pos);
  1730. }
  1731. static void mboxlog_stop(struct seq_file *seq, void *v)
  1732. {
  1733. }
  1734. static const struct seq_operations mboxlog_seq_ops = {
  1735. .start = mboxlog_start,
  1736. .next = mboxlog_next,
  1737. .stop = mboxlog_stop,
  1738. .show = mboxlog_show
  1739. };
  1740. static int mboxlog_open(struct inode *inode, struct file *file)
  1741. {
  1742. int res = seq_open(file, &mboxlog_seq_ops);
  1743. if (!res) {
  1744. struct seq_file *seq = file->private_data;
  1745. seq->private = inode->i_private;
  1746. }
  1747. return res;
  1748. }
  1749. static const struct file_operations mboxlog_fops = {
  1750. .owner = THIS_MODULE,
  1751. .open = mboxlog_open,
  1752. .read = seq_read,
  1753. .llseek = seq_lseek,
  1754. .release = seq_release,
  1755. };
  1756. /*
  1757. * Show SGE Queue Set information. We display QPL Queues Sets per line.
  1758. */
  1759. #define QPL 4
  1760. static int sge_qinfo_show(struct seq_file *seq, void *v)
  1761. {
  1762. struct adapter *adapter = seq->private;
  1763. int eth_entries = DIV_ROUND_UP(adapter->sge.ethqsets, QPL);
  1764. int qs, r = (uintptr_t)v - 1;
  1765. if (r)
  1766. seq_putc(seq, '\n');
  1767. #define S3(fmt_spec, s, v) \
  1768. do {\
  1769. seq_printf(seq, "%-12s", s); \
  1770. for (qs = 0; qs < n; ++qs) \
  1771. seq_printf(seq, " %16" fmt_spec, v); \
  1772. seq_putc(seq, '\n'); \
  1773. } while (0)
  1774. #define S(s, v) S3("s", s, v)
  1775. #define T(s, v) S3("u", s, txq[qs].v)
  1776. #define R(s, v) S3("u", s, rxq[qs].v)
  1777. if (r < eth_entries) {
  1778. const struct sge_eth_rxq *rxq = &adapter->sge.ethrxq[r * QPL];
  1779. const struct sge_eth_txq *txq = &adapter->sge.ethtxq[r * QPL];
  1780. int n = min(QPL, adapter->sge.ethqsets - QPL * r);
  1781. S("QType:", "Ethernet");
  1782. S("Interface:",
  1783. (rxq[qs].rspq.netdev
  1784. ? rxq[qs].rspq.netdev->name
  1785. : "N/A"));
  1786. S3("d", "Port:",
  1787. (rxq[qs].rspq.netdev
  1788. ? ((struct port_info *)
  1789. netdev_priv(rxq[qs].rspq.netdev))->port_id
  1790. : -1));
  1791. T("TxQ ID:", q.abs_id);
  1792. T("TxQ size:", q.size);
  1793. T("TxQ inuse:", q.in_use);
  1794. T("TxQ PIdx:", q.pidx);
  1795. T("TxQ CIdx:", q.cidx);
  1796. R("RspQ ID:", rspq.abs_id);
  1797. R("RspQ size:", rspq.size);
  1798. R("RspQE size:", rspq.iqe_len);
  1799. S3("u", "Intr delay:", qtimer_val(adapter, &rxq[qs].rspq));
  1800. S3("u", "Intr pktcnt:",
  1801. adapter->sge.counter_val[rxq[qs].rspq.pktcnt_idx]);
  1802. R("RspQ CIdx:", rspq.cidx);
  1803. R("RspQ Gen:", rspq.gen);
  1804. R("FL ID:", fl.abs_id);
  1805. R("FL size:", fl.size - MIN_FL_RESID);
  1806. R("FL avail:", fl.avail);
  1807. R("FL PIdx:", fl.pidx);
  1808. R("FL CIdx:", fl.cidx);
  1809. return 0;
  1810. }
  1811. r -= eth_entries;
  1812. if (r == 0) {
  1813. const struct sge_rspq *evtq = &adapter->sge.fw_evtq;
  1814. seq_printf(seq, "%-12s %16s\n", "QType:", "FW event queue");
  1815. seq_printf(seq, "%-12s %16u\n", "RspQ ID:", evtq->abs_id);
  1816. seq_printf(seq, "%-12s %16u\n", "Intr delay:",
  1817. qtimer_val(adapter, evtq));
  1818. seq_printf(seq, "%-12s %16u\n", "Intr pktcnt:",
  1819. adapter->sge.counter_val[evtq->pktcnt_idx]);
  1820. seq_printf(seq, "%-12s %16u\n", "RspQ Cidx:", evtq->cidx);
  1821. seq_printf(seq, "%-12s %16u\n", "RspQ Gen:", evtq->gen);
  1822. } else if (r == 1) {
  1823. const struct sge_rspq *intrq = &adapter->sge.intrq;
  1824. seq_printf(seq, "%-12s %16s\n", "QType:", "Interrupt Queue");
  1825. seq_printf(seq, "%-12s %16u\n", "RspQ ID:", intrq->abs_id);
  1826. seq_printf(seq, "%-12s %16u\n", "Intr delay:",
  1827. qtimer_val(adapter, intrq));
  1828. seq_printf(seq, "%-12s %16u\n", "Intr pktcnt:",
  1829. adapter->sge.counter_val[intrq->pktcnt_idx]);
  1830. seq_printf(seq, "%-12s %16u\n", "RspQ Cidx:", intrq->cidx);
  1831. seq_printf(seq, "%-12s %16u\n", "RspQ Gen:", intrq->gen);
  1832. }
  1833. #undef R
  1834. #undef T
  1835. #undef S
  1836. #undef S3
  1837. return 0;
  1838. }
  1839. /*
  1840. * Return the number of "entries" in our "file". We group the multi-Queue
  1841. * sections with QPL Queue Sets per "entry". The sections of the output are:
  1842. *
  1843. * Ethernet RX/TX Queue Sets
  1844. * Firmware Event Queue
  1845. * Forwarded Interrupt Queue (if in MSI mode)
  1846. */
  1847. static int sge_queue_entries(const struct adapter *adapter)
  1848. {
  1849. return DIV_ROUND_UP(adapter->sge.ethqsets, QPL) + 1 +
  1850. ((adapter->flags & USING_MSI) != 0);
  1851. }
  1852. static void *sge_queue_start(struct seq_file *seq, loff_t *pos)
  1853. {
  1854. int entries = sge_queue_entries(seq->private);
  1855. return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
  1856. }
  1857. static void sge_queue_stop(struct seq_file *seq, void *v)
  1858. {
  1859. }
  1860. static void *sge_queue_next(struct seq_file *seq, void *v, loff_t *pos)
  1861. {
  1862. int entries = sge_queue_entries(seq->private);
  1863. ++*pos;
  1864. return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
  1865. }
  1866. static const struct seq_operations sge_qinfo_seq_ops = {
  1867. .start = sge_queue_start,
  1868. .next = sge_queue_next,
  1869. .stop = sge_queue_stop,
  1870. .show = sge_qinfo_show
  1871. };
  1872. static int sge_qinfo_open(struct inode *inode, struct file *file)
  1873. {
  1874. int res = seq_open(file, &sge_qinfo_seq_ops);
  1875. if (!res) {
  1876. struct seq_file *seq = file->private_data;
  1877. seq->private = inode->i_private;
  1878. }
  1879. return res;
  1880. }
  1881. static const struct file_operations sge_qinfo_debugfs_fops = {
  1882. .owner = THIS_MODULE,
  1883. .open = sge_qinfo_open,
  1884. .read = seq_read,
  1885. .llseek = seq_lseek,
  1886. .release = seq_release,
  1887. };
  1888. /*
  1889. * Show SGE Queue Set statistics. We display QPL Queues Sets per line.
  1890. */
  1891. #define QPL 4
  1892. static int sge_qstats_show(struct seq_file *seq, void *v)
  1893. {
  1894. struct adapter *adapter = seq->private;
  1895. int eth_entries = DIV_ROUND_UP(adapter->sge.ethqsets, QPL);
  1896. int qs, r = (uintptr_t)v - 1;
  1897. if (r)
  1898. seq_putc(seq, '\n');
  1899. #define S3(fmt, s, v) \
  1900. do { \
  1901. seq_printf(seq, "%-16s", s); \
  1902. for (qs = 0; qs < n; ++qs) \
  1903. seq_printf(seq, " %8" fmt, v); \
  1904. seq_putc(seq, '\n'); \
  1905. } while (0)
  1906. #define S(s, v) S3("s", s, v)
  1907. #define T3(fmt, s, v) S3(fmt, s, txq[qs].v)
  1908. #define T(s, v) T3("lu", s, v)
  1909. #define R3(fmt, s, v) S3(fmt, s, rxq[qs].v)
  1910. #define R(s, v) R3("lu", s, v)
  1911. if (r < eth_entries) {
  1912. const struct sge_eth_rxq *rxq = &adapter->sge.ethrxq[r * QPL];
  1913. const struct sge_eth_txq *txq = &adapter->sge.ethtxq[r * QPL];
  1914. int n = min(QPL, adapter->sge.ethqsets - QPL * r);
  1915. S("QType:", "Ethernet");
  1916. S("Interface:",
  1917. (rxq[qs].rspq.netdev
  1918. ? rxq[qs].rspq.netdev->name
  1919. : "N/A"));
  1920. R3("u", "RspQNullInts:", rspq.unhandled_irqs);
  1921. R("RxPackets:", stats.pkts);
  1922. R("RxCSO:", stats.rx_cso);
  1923. R("VLANxtract:", stats.vlan_ex);
  1924. R("LROmerged:", stats.lro_merged);
  1925. R("LROpackets:", stats.lro_pkts);
  1926. R("RxDrops:", stats.rx_drops);
  1927. T("TSO:", tso);
  1928. T("TxCSO:", tx_cso);
  1929. T("VLANins:", vlan_ins);
  1930. T("TxQFull:", q.stops);
  1931. T("TxQRestarts:", q.restarts);
  1932. T("TxMapErr:", mapping_err);
  1933. R("FLAllocErr:", fl.alloc_failed);
  1934. R("FLLrgAlcErr:", fl.large_alloc_failed);
  1935. R("FLStarving:", fl.starving);
  1936. return 0;
  1937. }
  1938. r -= eth_entries;
  1939. if (r == 0) {
  1940. const struct sge_rspq *evtq = &adapter->sge.fw_evtq;
  1941. seq_printf(seq, "%-8s %16s\n", "QType:", "FW event queue");
  1942. seq_printf(seq, "%-16s %8u\n", "RspQNullInts:",
  1943. evtq->unhandled_irqs);
  1944. seq_printf(seq, "%-16s %8u\n", "RspQ CIdx:", evtq->cidx);
  1945. seq_printf(seq, "%-16s %8u\n", "RspQ Gen:", evtq->gen);
  1946. } else if (r == 1) {
  1947. const struct sge_rspq *intrq = &adapter->sge.intrq;
  1948. seq_printf(seq, "%-8s %16s\n", "QType:", "Interrupt Queue");
  1949. seq_printf(seq, "%-16s %8u\n", "RspQNullInts:",
  1950. intrq->unhandled_irqs);
  1951. seq_printf(seq, "%-16s %8u\n", "RspQ CIdx:", intrq->cidx);
  1952. seq_printf(seq, "%-16s %8u\n", "RspQ Gen:", intrq->gen);
  1953. }
  1954. #undef R
  1955. #undef T
  1956. #undef S
  1957. #undef R3
  1958. #undef T3
  1959. #undef S3
  1960. return 0;
  1961. }
  1962. /*
  1963. * Return the number of "entries" in our "file". We group the multi-Queue
  1964. * sections with QPL Queue Sets per "entry". The sections of the output are:
  1965. *
  1966. * Ethernet RX/TX Queue Sets
  1967. * Firmware Event Queue
  1968. * Forwarded Interrupt Queue (if in MSI mode)
  1969. */
  1970. static int sge_qstats_entries(const struct adapter *adapter)
  1971. {
  1972. return DIV_ROUND_UP(adapter->sge.ethqsets, QPL) + 1 +
  1973. ((adapter->flags & USING_MSI) != 0);
  1974. }
  1975. static void *sge_qstats_start(struct seq_file *seq, loff_t *pos)
  1976. {
  1977. int entries = sge_qstats_entries(seq->private);
  1978. return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
  1979. }
  1980. static void sge_qstats_stop(struct seq_file *seq, void *v)
  1981. {
  1982. }
  1983. static void *sge_qstats_next(struct seq_file *seq, void *v, loff_t *pos)
  1984. {
  1985. int entries = sge_qstats_entries(seq->private);
  1986. (*pos)++;
  1987. return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
  1988. }
  1989. static const struct seq_operations sge_qstats_seq_ops = {
  1990. .start = sge_qstats_start,
  1991. .next = sge_qstats_next,
  1992. .stop = sge_qstats_stop,
  1993. .show = sge_qstats_show
  1994. };
  1995. static int sge_qstats_open(struct inode *inode, struct file *file)
  1996. {
  1997. int res = seq_open(file, &sge_qstats_seq_ops);
  1998. if (res == 0) {
  1999. struct seq_file *seq = file->private_data;
  2000. seq->private = inode->i_private;
  2001. }
  2002. return res;
  2003. }
  2004. static const struct file_operations sge_qstats_proc_fops = {
  2005. .owner = THIS_MODULE,
  2006. .open = sge_qstats_open,
  2007. .read = seq_read,
  2008. .llseek = seq_lseek,
  2009. .release = seq_release,
  2010. };
  2011. /*
  2012. * Show PCI-E SR-IOV Virtual Function Resource Limits.
  2013. */
  2014. static int resources_show(struct seq_file *seq, void *v)
  2015. {
  2016. struct adapter *adapter = seq->private;
  2017. struct vf_resources *vfres = &adapter->params.vfres;
  2018. #define S(desc, fmt, var) \
  2019. seq_printf(seq, "%-60s " fmt "\n", \
  2020. desc " (" #var "):", vfres->var)
  2021. S("Virtual Interfaces", "%d", nvi);
  2022. S("Egress Queues", "%d", neq);
  2023. S("Ethernet Control", "%d", nethctrl);
  2024. S("Ingress Queues/w Free Lists/Interrupts", "%d", niqflint);
  2025. S("Ingress Queues", "%d", niq);
  2026. S("Traffic Class", "%d", tc);
  2027. S("Port Access Rights Mask", "%#x", pmask);
  2028. S("MAC Address Filters", "%d", nexactf);
  2029. S("Firmware Command Read Capabilities", "%#x", r_caps);
  2030. S("Firmware Command Write/Execute Capabilities", "%#x", wx_caps);
  2031. #undef S
  2032. return 0;
  2033. }
  2034. static int resources_open(struct inode *inode, struct file *file)
  2035. {
  2036. return single_open(file, resources_show, inode->i_private);
  2037. }
  2038. static const struct file_operations resources_proc_fops = {
  2039. .owner = THIS_MODULE,
  2040. .open = resources_open,
  2041. .read = seq_read,
  2042. .llseek = seq_lseek,
  2043. .release = single_release,
  2044. };
  2045. /*
  2046. * Show Virtual Interfaces.
  2047. */
  2048. static int interfaces_show(struct seq_file *seq, void *v)
  2049. {
  2050. if (v == SEQ_START_TOKEN) {
  2051. seq_puts(seq, "Interface Port VIID\n");
  2052. } else {
  2053. struct adapter *adapter = seq->private;
  2054. int pidx = (uintptr_t)v - 2;
  2055. struct net_device *dev = adapter->port[pidx];
  2056. struct port_info *pi = netdev_priv(dev);
  2057. seq_printf(seq, "%9s %4d %#5x\n",
  2058. dev->name, pi->port_id, pi->viid);
  2059. }
  2060. return 0;
  2061. }
  2062. static inline void *interfaces_get_idx(struct adapter *adapter, loff_t pos)
  2063. {
  2064. return pos <= adapter->params.nports
  2065. ? (void *)(uintptr_t)(pos + 1)
  2066. : NULL;
  2067. }
  2068. static void *interfaces_start(struct seq_file *seq, loff_t *pos)
  2069. {
  2070. return *pos
  2071. ? interfaces_get_idx(seq->private, *pos)
  2072. : SEQ_START_TOKEN;
  2073. }
  2074. static void *interfaces_next(struct seq_file *seq, void *v, loff_t *pos)
  2075. {
  2076. (*pos)++;
  2077. return interfaces_get_idx(seq->private, *pos);
  2078. }
  2079. static void interfaces_stop(struct seq_file *seq, void *v)
  2080. {
  2081. }
  2082. static const struct seq_operations interfaces_seq_ops = {
  2083. .start = interfaces_start,
  2084. .next = interfaces_next,
  2085. .stop = interfaces_stop,
  2086. .show = interfaces_show
  2087. };
  2088. static int interfaces_open(struct inode *inode, struct file *file)
  2089. {
  2090. int res = seq_open(file, &interfaces_seq_ops);
  2091. if (res == 0) {
  2092. struct seq_file *seq = file->private_data;
  2093. seq->private = inode->i_private;
  2094. }
  2095. return res;
  2096. }
  2097. static const struct file_operations interfaces_proc_fops = {
  2098. .owner = THIS_MODULE,
  2099. .open = interfaces_open,
  2100. .read = seq_read,
  2101. .llseek = seq_lseek,
  2102. .release = seq_release,
  2103. };
  2104. /*
  2105. * /sys/kernel/debugfs/cxgb4vf/ files list.
  2106. */
  2107. struct cxgb4vf_debugfs_entry {
  2108. const char *name; /* name of debugfs node */
  2109. umode_t mode; /* file system mode */
  2110. const struct file_operations *fops;
  2111. };
  2112. static struct cxgb4vf_debugfs_entry debugfs_files[] = {
  2113. { "mboxlog", 0444, &mboxlog_fops },
  2114. { "sge_qinfo", 0444, &sge_qinfo_debugfs_fops },
  2115. { "sge_qstats", 0444, &sge_qstats_proc_fops },
  2116. { "resources", 0444, &resources_proc_fops },
  2117. { "interfaces", 0444, &interfaces_proc_fops },
  2118. };
  2119. /*
  2120. * Module and device initialization and cleanup code.
  2121. * ==================================================
  2122. */
  2123. /*
  2124. * Set up out /sys/kernel/debug/cxgb4vf sub-nodes. We assume that the
  2125. * directory (debugfs_root) has already been set up.
  2126. */
  2127. static int setup_debugfs(struct adapter *adapter)
  2128. {
  2129. int i;
  2130. BUG_ON(IS_ERR_OR_NULL(adapter->debugfs_root));
  2131. /*
  2132. * Debugfs support is best effort.
  2133. */
  2134. for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
  2135. (void)debugfs_create_file(debugfs_files[i].name,
  2136. debugfs_files[i].mode,
  2137. adapter->debugfs_root,
  2138. (void *)adapter,
  2139. debugfs_files[i].fops);
  2140. return 0;
  2141. }
  2142. /*
  2143. * Tear down the /sys/kernel/debug/cxgb4vf sub-nodes created above. We leave
  2144. * it to our caller to tear down the directory (debugfs_root).
  2145. */
  2146. static void cleanup_debugfs(struct adapter *adapter)
  2147. {
  2148. BUG_ON(IS_ERR_OR_NULL(adapter->debugfs_root));
  2149. /*
  2150. * Unlike our sister routine cleanup_proc(), we don't need to remove
  2151. * individual entries because a call will be made to
  2152. * debugfs_remove_recursive(). We just need to clean up any ancillary
  2153. * persistent state.
  2154. */
  2155. /* nothing to do */
  2156. }
  2157. /* Figure out how many Ports and Queue Sets we can support. This depends on
  2158. * knowing our Virtual Function Resources and may be called a second time if
  2159. * we fall back from MSI-X to MSI Interrupt Mode.
  2160. */
  2161. static void size_nports_qsets(struct adapter *adapter)
  2162. {
  2163. struct vf_resources *vfres = &adapter->params.vfres;
  2164. unsigned int ethqsets, pmask_nports;
  2165. /* The number of "ports" which we support is equal to the number of
  2166. * Virtual Interfaces with which we've been provisioned.
  2167. */
  2168. adapter->params.nports = vfres->nvi;
  2169. if (adapter->params.nports > MAX_NPORTS) {
  2170. dev_warn(adapter->pdev_dev, "only using %d of %d maximum"
  2171. " allowed virtual interfaces\n", MAX_NPORTS,
  2172. adapter->params.nports);
  2173. adapter->params.nports = MAX_NPORTS;
  2174. }
  2175. /* We may have been provisioned with more VIs than the number of
  2176. * ports we're allowed to access (our Port Access Rights Mask).
  2177. * This is obviously a configuration conflict but we don't want to
  2178. * crash the kernel or anything silly just because of that.
  2179. */
  2180. pmask_nports = hweight32(adapter->params.vfres.pmask);
  2181. if (pmask_nports < adapter->params.nports) {
  2182. dev_warn(adapter->pdev_dev, "only using %d of %d provisioned"
  2183. " virtual interfaces; limited by Port Access Rights"
  2184. " mask %#x\n", pmask_nports, adapter->params.nports,
  2185. adapter->params.vfres.pmask);
  2186. adapter->params.nports = pmask_nports;
  2187. }
  2188. /* We need to reserve an Ingress Queue for the Asynchronous Firmware
  2189. * Event Queue. And if we're using MSI Interrupts, we'll also need to
  2190. * reserve an Ingress Queue for a Forwarded Interrupts.
  2191. *
  2192. * The rest of the FL/Intr-capable ingress queues will be matched up
  2193. * one-for-one with Ethernet/Control egress queues in order to form
  2194. * "Queue Sets" which will be aportioned between the "ports". For
  2195. * each Queue Set, we'll need the ability to allocate two Egress
  2196. * Contexts -- one for the Ingress Queue Free List and one for the TX
  2197. * Ethernet Queue.
  2198. *
  2199. * Note that even if we're currently configured to use MSI-X
  2200. * Interrupts (module variable msi == MSI_MSIX) we may get downgraded
  2201. * to MSI Interrupts if we can't get enough MSI-X Interrupts. If that
  2202. * happens we'll need to adjust things later.
  2203. */
  2204. ethqsets = vfres->niqflint - 1 - (msi == MSI_MSI);
  2205. if (vfres->nethctrl != ethqsets)
  2206. ethqsets = min(vfres->nethctrl, ethqsets);
  2207. if (vfres->neq < ethqsets*2)
  2208. ethqsets = vfres->neq/2;
  2209. if (ethqsets > MAX_ETH_QSETS)
  2210. ethqsets = MAX_ETH_QSETS;
  2211. adapter->sge.max_ethqsets = ethqsets;
  2212. if (adapter->sge.max_ethqsets < adapter->params.nports) {
  2213. dev_warn(adapter->pdev_dev, "only using %d of %d available"
  2214. " virtual interfaces (too few Queue Sets)\n",
  2215. adapter->sge.max_ethqsets, adapter->params.nports);
  2216. adapter->params.nports = adapter->sge.max_ethqsets;
  2217. }
  2218. }
  2219. /*
  2220. * Perform early "adapter" initialization. This is where we discover what
  2221. * adapter parameters we're going to be using and initialize basic adapter
  2222. * hardware support.
  2223. */
  2224. static int adap_init0(struct adapter *adapter)
  2225. {
  2226. struct sge_params *sge_params = &adapter->params.sge;
  2227. struct sge *s = &adapter->sge;
  2228. int err;
  2229. u32 param, val = 0;
  2230. /*
  2231. * Some environments do not properly handle PCIE FLRs -- e.g. in Linux
  2232. * 2.6.31 and later we can't call pci_reset_function() in order to
  2233. * issue an FLR because of a self- deadlock on the device semaphore.
  2234. * Meanwhile, the OS infrastructure doesn't issue FLRs in all the
  2235. * cases where they're needed -- for instance, some versions of KVM
  2236. * fail to reset "Assigned Devices" when the VM reboots. Therefore we
  2237. * use the firmware based reset in order to reset any per function
  2238. * state.
  2239. */
  2240. err = t4vf_fw_reset(adapter);
  2241. if (err < 0) {
  2242. dev_err(adapter->pdev_dev, "FW reset failed: err=%d\n", err);
  2243. return err;
  2244. }
  2245. /*
  2246. * Grab basic operational parameters. These will predominantly have
  2247. * been set up by the Physical Function Driver or will be hard coded
  2248. * into the adapter. We just have to live with them ... Note that
  2249. * we _must_ get our VPD parameters before our SGE parameters because
  2250. * we need to know the adapter's core clock from the VPD in order to
  2251. * properly decode the SGE Timer Values.
  2252. */
  2253. err = t4vf_get_dev_params(adapter);
  2254. if (err) {
  2255. dev_err(adapter->pdev_dev, "unable to retrieve adapter"
  2256. " device parameters: err=%d\n", err);
  2257. return err;
  2258. }
  2259. err = t4vf_get_vpd_params(adapter);
  2260. if (err) {
  2261. dev_err(adapter->pdev_dev, "unable to retrieve adapter"
  2262. " VPD parameters: err=%d\n", err);
  2263. return err;
  2264. }
  2265. err = t4vf_get_sge_params(adapter);
  2266. if (err) {
  2267. dev_err(adapter->pdev_dev, "unable to retrieve adapter"
  2268. " SGE parameters: err=%d\n", err);
  2269. return err;
  2270. }
  2271. err = t4vf_get_rss_glb_config(adapter);
  2272. if (err) {
  2273. dev_err(adapter->pdev_dev, "unable to retrieve adapter"
  2274. " RSS parameters: err=%d\n", err);
  2275. return err;
  2276. }
  2277. if (adapter->params.rss.mode !=
  2278. FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL) {
  2279. dev_err(adapter->pdev_dev, "unable to operate with global RSS"
  2280. " mode %d\n", adapter->params.rss.mode);
  2281. return -EINVAL;
  2282. }
  2283. err = t4vf_sge_init(adapter);
  2284. if (err) {
  2285. dev_err(adapter->pdev_dev, "unable to use adapter parameters:"
  2286. " err=%d\n", err);
  2287. return err;
  2288. }
  2289. /* If we're running on newer firmware, let it know that we're
  2290. * prepared to deal with encapsulated CPL messages. Older
  2291. * firmware won't understand this and we'll just get
  2292. * unencapsulated messages ...
  2293. */
  2294. param = FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) |
  2295. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_CPLFW4MSG_ENCAP);
  2296. val = 1;
  2297. (void) t4vf_set_params(adapter, 1, &param, &val);
  2298. /*
  2299. * Retrieve our RX interrupt holdoff timer values and counter
  2300. * threshold values from the SGE parameters.
  2301. */
  2302. s->timer_val[0] = core_ticks_to_us(adapter,
  2303. TIMERVALUE0_G(sge_params->sge_timer_value_0_and_1));
  2304. s->timer_val[1] = core_ticks_to_us(adapter,
  2305. TIMERVALUE1_G(sge_params->sge_timer_value_0_and_1));
  2306. s->timer_val[2] = core_ticks_to_us(adapter,
  2307. TIMERVALUE0_G(sge_params->sge_timer_value_2_and_3));
  2308. s->timer_val[3] = core_ticks_to_us(adapter,
  2309. TIMERVALUE1_G(sge_params->sge_timer_value_2_and_3));
  2310. s->timer_val[4] = core_ticks_to_us(adapter,
  2311. TIMERVALUE0_G(sge_params->sge_timer_value_4_and_5));
  2312. s->timer_val[5] = core_ticks_to_us(adapter,
  2313. TIMERVALUE1_G(sge_params->sge_timer_value_4_and_5));
  2314. s->counter_val[0] = THRESHOLD_0_G(sge_params->sge_ingress_rx_threshold);
  2315. s->counter_val[1] = THRESHOLD_1_G(sge_params->sge_ingress_rx_threshold);
  2316. s->counter_val[2] = THRESHOLD_2_G(sge_params->sge_ingress_rx_threshold);
  2317. s->counter_val[3] = THRESHOLD_3_G(sge_params->sge_ingress_rx_threshold);
  2318. /*
  2319. * Grab our Virtual Interface resource allocation, extract the
  2320. * features that we're interested in and do a bit of sanity testing on
  2321. * what we discover.
  2322. */
  2323. err = t4vf_get_vfres(adapter);
  2324. if (err) {
  2325. dev_err(adapter->pdev_dev, "unable to get virtual interface"
  2326. " resources: err=%d\n", err);
  2327. return err;
  2328. }
  2329. /* Check for various parameter sanity issues */
  2330. if (adapter->params.vfres.pmask == 0) {
  2331. dev_err(adapter->pdev_dev, "no port access configured\n"
  2332. "usable!\n");
  2333. return -EINVAL;
  2334. }
  2335. if (adapter->params.vfres.nvi == 0) {
  2336. dev_err(adapter->pdev_dev, "no virtual interfaces configured/"
  2337. "usable!\n");
  2338. return -EINVAL;
  2339. }
  2340. /* Initialize nports and max_ethqsets now that we have our Virtual
  2341. * Function Resources.
  2342. */
  2343. size_nports_qsets(adapter);
  2344. return 0;
  2345. }
  2346. static inline void init_rspq(struct sge_rspq *rspq, u8 timer_idx,
  2347. u8 pkt_cnt_idx, unsigned int size,
  2348. unsigned int iqe_size)
  2349. {
  2350. rspq->intr_params = (QINTR_TIMER_IDX_V(timer_idx) |
  2351. (pkt_cnt_idx < SGE_NCOUNTERS ?
  2352. QINTR_CNT_EN_F : 0));
  2353. rspq->pktcnt_idx = (pkt_cnt_idx < SGE_NCOUNTERS
  2354. ? pkt_cnt_idx
  2355. : 0);
  2356. rspq->iqe_len = iqe_size;
  2357. rspq->size = size;
  2358. }
  2359. /*
  2360. * Perform default configuration of DMA queues depending on the number and
  2361. * type of ports we found and the number of available CPUs. Most settings can
  2362. * be modified by the admin via ethtool and cxgbtool prior to the adapter
  2363. * being brought up for the first time.
  2364. */
  2365. static void cfg_queues(struct adapter *adapter)
  2366. {
  2367. struct sge *s = &adapter->sge;
  2368. int q10g, n10g, qidx, pidx, qs;
  2369. size_t iqe_size;
  2370. /*
  2371. * We should not be called till we know how many Queue Sets we can
  2372. * support. In particular, this means that we need to know what kind
  2373. * of interrupts we'll be using ...
  2374. */
  2375. BUG_ON((adapter->flags & (USING_MSIX|USING_MSI)) == 0);
  2376. /*
  2377. * Count the number of 10GbE Virtual Interfaces that we have.
  2378. */
  2379. n10g = 0;
  2380. for_each_port(adapter, pidx)
  2381. n10g += is_x_10g_port(&adap2pinfo(adapter, pidx)->link_cfg);
  2382. /*
  2383. * We default to 1 queue per non-10G port and up to # of cores queues
  2384. * per 10G port.
  2385. */
  2386. if (n10g == 0)
  2387. q10g = 0;
  2388. else {
  2389. int n1g = (adapter->params.nports - n10g);
  2390. q10g = (adapter->sge.max_ethqsets - n1g) / n10g;
  2391. if (q10g > num_online_cpus())
  2392. q10g = num_online_cpus();
  2393. }
  2394. /*
  2395. * Allocate the "Queue Sets" to the various Virtual Interfaces.
  2396. * The layout will be established in setup_sge_queues() when the
  2397. * adapter is brough up for the first time.
  2398. */
  2399. qidx = 0;
  2400. for_each_port(adapter, pidx) {
  2401. struct port_info *pi = adap2pinfo(adapter, pidx);
  2402. pi->first_qset = qidx;
  2403. pi->nqsets = is_x_10g_port(&pi->link_cfg) ? q10g : 1;
  2404. qidx += pi->nqsets;
  2405. }
  2406. s->ethqsets = qidx;
  2407. /*
  2408. * The Ingress Queue Entry Size for our various Response Queues needs
  2409. * to be big enough to accommodate the largest message we can receive
  2410. * from the chip/firmware; which is 64 bytes ...
  2411. */
  2412. iqe_size = 64;
  2413. /*
  2414. * Set up default Queue Set parameters ... Start off with the
  2415. * shortest interrupt holdoff timer.
  2416. */
  2417. for (qs = 0; qs < s->max_ethqsets; qs++) {
  2418. struct sge_eth_rxq *rxq = &s->ethrxq[qs];
  2419. struct sge_eth_txq *txq = &s->ethtxq[qs];
  2420. init_rspq(&rxq->rspq, 0, 0, 1024, iqe_size);
  2421. rxq->fl.size = 72;
  2422. txq->q.size = 1024;
  2423. }
  2424. /*
  2425. * The firmware event queue is used for link state changes and
  2426. * notifications of TX DMA completions.
  2427. */
  2428. init_rspq(&s->fw_evtq, SGE_TIMER_RSTRT_CNTR, 0, 512, iqe_size);
  2429. /*
  2430. * The forwarded interrupt queue is used when we're in MSI interrupt
  2431. * mode. In this mode all interrupts associated with RX queues will
  2432. * be forwarded to a single queue which we'll associate with our MSI
  2433. * interrupt vector. The messages dropped in the forwarded interrupt
  2434. * queue will indicate which ingress queue needs servicing ... This
  2435. * queue needs to be large enough to accommodate all of the ingress
  2436. * queues which are forwarding their interrupt (+1 to prevent the PIDX
  2437. * from equalling the CIDX if every ingress queue has an outstanding
  2438. * interrupt). The queue doesn't need to be any larger because no
  2439. * ingress queue will ever have more than one outstanding interrupt at
  2440. * any time ...
  2441. */
  2442. init_rspq(&s->intrq, SGE_TIMER_RSTRT_CNTR, 0, MSIX_ENTRIES + 1,
  2443. iqe_size);
  2444. }
  2445. /*
  2446. * Reduce the number of Ethernet queues across all ports to at most n.
  2447. * n provides at least one queue per port.
  2448. */
  2449. static void reduce_ethqs(struct adapter *adapter, int n)
  2450. {
  2451. int i;
  2452. struct port_info *pi;
  2453. /*
  2454. * While we have too many active Ether Queue Sets, interate across the
  2455. * "ports" and reduce their individual Queue Set allocations.
  2456. */
  2457. BUG_ON(n < adapter->params.nports);
  2458. while (n < adapter->sge.ethqsets)
  2459. for_each_port(adapter, i) {
  2460. pi = adap2pinfo(adapter, i);
  2461. if (pi->nqsets > 1) {
  2462. pi->nqsets--;
  2463. adapter->sge.ethqsets--;
  2464. if (adapter->sge.ethqsets <= n)
  2465. break;
  2466. }
  2467. }
  2468. /*
  2469. * Reassign the starting Queue Sets for each of the "ports" ...
  2470. */
  2471. n = 0;
  2472. for_each_port(adapter, i) {
  2473. pi = adap2pinfo(adapter, i);
  2474. pi->first_qset = n;
  2475. n += pi->nqsets;
  2476. }
  2477. }
  2478. /*
  2479. * We need to grab enough MSI-X vectors to cover our interrupt needs. Ideally
  2480. * we get a separate MSI-X vector for every "Queue Set" plus any extras we
  2481. * need. Minimally we need one for every Virtual Interface plus those needed
  2482. * for our "extras". Note that this process may lower the maximum number of
  2483. * allowed Queue Sets ...
  2484. */
  2485. static int enable_msix(struct adapter *adapter)
  2486. {
  2487. int i, want, need, nqsets;
  2488. struct msix_entry entries[MSIX_ENTRIES];
  2489. struct sge *s = &adapter->sge;
  2490. for (i = 0; i < MSIX_ENTRIES; ++i)
  2491. entries[i].entry = i;
  2492. /*
  2493. * We _want_ enough MSI-X interrupts to cover all of our "Queue Sets"
  2494. * plus those needed for our "extras" (for example, the firmware
  2495. * message queue). We _need_ at least one "Queue Set" per Virtual
  2496. * Interface plus those needed for our "extras". So now we get to see
  2497. * if the song is right ...
  2498. */
  2499. want = s->max_ethqsets + MSIX_EXTRAS;
  2500. need = adapter->params.nports + MSIX_EXTRAS;
  2501. want = pci_enable_msix_range(adapter->pdev, entries, need, want);
  2502. if (want < 0)
  2503. return want;
  2504. nqsets = want - MSIX_EXTRAS;
  2505. if (nqsets < s->max_ethqsets) {
  2506. dev_warn(adapter->pdev_dev, "only enough MSI-X vectors"
  2507. " for %d Queue Sets\n", nqsets);
  2508. s->max_ethqsets = nqsets;
  2509. if (nqsets < s->ethqsets)
  2510. reduce_ethqs(adapter, nqsets);
  2511. }
  2512. for (i = 0; i < want; ++i)
  2513. adapter->msix_info[i].vec = entries[i].vector;
  2514. return 0;
  2515. }
  2516. static const struct net_device_ops cxgb4vf_netdev_ops = {
  2517. .ndo_open = cxgb4vf_open,
  2518. .ndo_stop = cxgb4vf_stop,
  2519. .ndo_start_xmit = t4vf_eth_xmit,
  2520. .ndo_get_stats = cxgb4vf_get_stats,
  2521. .ndo_set_rx_mode = cxgb4vf_set_rxmode,
  2522. .ndo_set_mac_address = cxgb4vf_set_mac_addr,
  2523. .ndo_validate_addr = eth_validate_addr,
  2524. .ndo_do_ioctl = cxgb4vf_do_ioctl,
  2525. .ndo_change_mtu = cxgb4vf_change_mtu,
  2526. .ndo_fix_features = cxgb4vf_fix_features,
  2527. .ndo_set_features = cxgb4vf_set_features,
  2528. #ifdef CONFIG_NET_POLL_CONTROLLER
  2529. .ndo_poll_controller = cxgb4vf_poll_controller,
  2530. #endif
  2531. };
  2532. /*
  2533. * "Probe" a device: initialize a device and construct all kernel and driver
  2534. * state needed to manage the device. This routine is called "init_one" in
  2535. * the PF Driver ...
  2536. */
  2537. static int cxgb4vf_pci_probe(struct pci_dev *pdev,
  2538. const struct pci_device_id *ent)
  2539. {
  2540. int pci_using_dac;
  2541. int err, pidx;
  2542. unsigned int pmask;
  2543. struct adapter *adapter;
  2544. struct port_info *pi;
  2545. struct net_device *netdev;
  2546. unsigned int pf;
  2547. /*
  2548. * Print our driver banner the first time we're called to initialize a
  2549. * device.
  2550. */
  2551. pr_info_once("%s - version %s\n", DRV_DESC, DRV_VERSION);
  2552. /*
  2553. * Initialize generic PCI device state.
  2554. */
  2555. err = pci_enable_device(pdev);
  2556. if (err) {
  2557. dev_err(&pdev->dev, "cannot enable PCI device\n");
  2558. return err;
  2559. }
  2560. /*
  2561. * Reserve PCI resources for the device. If we can't get them some
  2562. * other driver may have already claimed the device ...
  2563. */
  2564. err = pci_request_regions(pdev, KBUILD_MODNAME);
  2565. if (err) {
  2566. dev_err(&pdev->dev, "cannot obtain PCI resources\n");
  2567. goto err_disable_device;
  2568. }
  2569. /*
  2570. * Set up our DMA mask: try for 64-bit address masking first and
  2571. * fall back to 32-bit if we can't get 64 bits ...
  2572. */
  2573. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  2574. if (err == 0) {
  2575. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  2576. if (err) {
  2577. dev_err(&pdev->dev, "unable to obtain 64-bit DMA for"
  2578. " coherent allocations\n");
  2579. goto err_release_regions;
  2580. }
  2581. pci_using_dac = 1;
  2582. } else {
  2583. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  2584. if (err != 0) {
  2585. dev_err(&pdev->dev, "no usable DMA configuration\n");
  2586. goto err_release_regions;
  2587. }
  2588. pci_using_dac = 0;
  2589. }
  2590. /*
  2591. * Enable bus mastering for the device ...
  2592. */
  2593. pci_set_master(pdev);
  2594. /*
  2595. * Allocate our adapter data structure and attach it to the device.
  2596. */
  2597. adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
  2598. if (!adapter) {
  2599. err = -ENOMEM;
  2600. goto err_release_regions;
  2601. }
  2602. pci_set_drvdata(pdev, adapter);
  2603. adapter->pdev = pdev;
  2604. adapter->pdev_dev = &pdev->dev;
  2605. adapter->mbox_log = kzalloc(sizeof(*adapter->mbox_log) +
  2606. (sizeof(struct mbox_cmd) *
  2607. T4VF_OS_LOG_MBOX_CMDS),
  2608. GFP_KERNEL);
  2609. if (!adapter->mbox_log) {
  2610. err = -ENOMEM;
  2611. goto err_free_adapter;
  2612. }
  2613. adapter->mbox_log->size = T4VF_OS_LOG_MBOX_CMDS;
  2614. /*
  2615. * Initialize SMP data synchronization resources.
  2616. */
  2617. spin_lock_init(&adapter->stats_lock);
  2618. spin_lock_init(&adapter->mbox_lock);
  2619. INIT_LIST_HEAD(&adapter->mlist.list);
  2620. /*
  2621. * Map our I/O registers in BAR0.
  2622. */
  2623. adapter->regs = pci_ioremap_bar(pdev, 0);
  2624. if (!adapter->regs) {
  2625. dev_err(&pdev->dev, "cannot map device registers\n");
  2626. err = -ENOMEM;
  2627. goto err_free_adapter;
  2628. }
  2629. /* Wait for the device to become ready before proceeding ...
  2630. */
  2631. err = t4vf_prep_adapter(adapter);
  2632. if (err) {
  2633. dev_err(adapter->pdev_dev, "device didn't become ready:"
  2634. " err=%d\n", err);
  2635. goto err_unmap_bar0;
  2636. }
  2637. /* For T5 and later we want to use the new BAR-based User Doorbells,
  2638. * so we need to map BAR2 here ...
  2639. */
  2640. if (!is_t4(adapter->params.chip)) {
  2641. adapter->bar2 = ioremap_wc(pci_resource_start(pdev, 2),
  2642. pci_resource_len(pdev, 2));
  2643. if (!adapter->bar2) {
  2644. dev_err(adapter->pdev_dev, "cannot map BAR2 doorbells\n");
  2645. err = -ENOMEM;
  2646. goto err_unmap_bar0;
  2647. }
  2648. }
  2649. /*
  2650. * Initialize adapter level features.
  2651. */
  2652. adapter->name = pci_name(pdev);
  2653. adapter->msg_enable = DFLT_MSG_ENABLE;
  2654. /* If possible, we use PCIe Relaxed Ordering Attribute to deliver
  2655. * Ingress Packet Data to Free List Buffers in order to allow for
  2656. * chipset performance optimizations between the Root Complex and
  2657. * Memory Controllers. (Messages to the associated Ingress Queue
  2658. * notifying new Packet Placement in the Free Lists Buffers will be
  2659. * send without the Relaxed Ordering Attribute thus guaranteeing that
  2660. * all preceding PCIe Transaction Layer Packets will be processed
  2661. * first.) But some Root Complexes have various issues with Upstream
  2662. * Transaction Layer Packets with the Relaxed Ordering Attribute set.
  2663. * The PCIe devices which under the Root Complexes will be cleared the
  2664. * Relaxed Ordering bit in the configuration space, So we check our
  2665. * PCIe configuration space to see if it's flagged with advice against
  2666. * using Relaxed Ordering.
  2667. */
  2668. if (!pcie_relaxed_ordering_enabled(pdev))
  2669. adapter->flags |= ROOT_NO_RELAXED_ORDERING;
  2670. err = adap_init0(adapter);
  2671. if (err)
  2672. goto err_unmap_bar;
  2673. /*
  2674. * Allocate our "adapter ports" and stitch everything together.
  2675. */
  2676. pmask = adapter->params.vfres.pmask;
  2677. pf = t4vf_get_pf_from_vf(adapter);
  2678. for_each_port(adapter, pidx) {
  2679. int port_id, viid;
  2680. u8 mac[ETH_ALEN];
  2681. unsigned int naddr = 1;
  2682. /*
  2683. * We simplistically allocate our virtual interfaces
  2684. * sequentially across the port numbers to which we have
  2685. * access rights. This should be configurable in some manner
  2686. * ...
  2687. */
  2688. if (pmask == 0)
  2689. break;
  2690. port_id = ffs(pmask) - 1;
  2691. pmask &= ~(1 << port_id);
  2692. viid = t4vf_alloc_vi(adapter, port_id);
  2693. if (viid < 0) {
  2694. dev_err(&pdev->dev, "cannot allocate VI for port %d:"
  2695. " err=%d\n", port_id, viid);
  2696. err = viid;
  2697. goto err_free_dev;
  2698. }
  2699. /*
  2700. * Allocate our network device and stitch things together.
  2701. */
  2702. netdev = alloc_etherdev_mq(sizeof(struct port_info),
  2703. MAX_PORT_QSETS);
  2704. if (netdev == NULL) {
  2705. t4vf_free_vi(adapter, viid);
  2706. err = -ENOMEM;
  2707. goto err_free_dev;
  2708. }
  2709. adapter->port[pidx] = netdev;
  2710. SET_NETDEV_DEV(netdev, &pdev->dev);
  2711. pi = netdev_priv(netdev);
  2712. pi->adapter = adapter;
  2713. pi->pidx = pidx;
  2714. pi->port_id = port_id;
  2715. pi->viid = viid;
  2716. /*
  2717. * Initialize the starting state of our "port" and register
  2718. * it.
  2719. */
  2720. pi->xact_addr_filt = -1;
  2721. netif_carrier_off(netdev);
  2722. netdev->irq = pdev->irq;
  2723. netdev->hw_features = NETIF_F_SG | TSO_FLAGS |
  2724. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  2725. NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_RXCSUM;
  2726. netdev->vlan_features = NETIF_F_SG | TSO_FLAGS |
  2727. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  2728. NETIF_F_HIGHDMA;
  2729. netdev->features = netdev->hw_features |
  2730. NETIF_F_HW_VLAN_CTAG_TX;
  2731. if (pci_using_dac)
  2732. netdev->features |= NETIF_F_HIGHDMA;
  2733. netdev->priv_flags |= IFF_UNICAST_FLT;
  2734. netdev->min_mtu = 81;
  2735. netdev->max_mtu = ETH_MAX_MTU;
  2736. netdev->netdev_ops = &cxgb4vf_netdev_ops;
  2737. netdev->ethtool_ops = &cxgb4vf_ethtool_ops;
  2738. netdev->dev_port = pi->port_id;
  2739. /*
  2740. * Initialize the hardware/software state for the port.
  2741. */
  2742. err = t4vf_port_init(adapter, pidx);
  2743. if (err) {
  2744. dev_err(&pdev->dev, "cannot initialize port %d\n",
  2745. pidx);
  2746. goto err_free_dev;
  2747. }
  2748. err = t4vf_get_vf_mac_acl(adapter, pf, &naddr, mac);
  2749. if (err) {
  2750. dev_err(&pdev->dev,
  2751. "unable to determine MAC ACL address, "
  2752. "continuing anyway.. (status %d)\n", err);
  2753. } else if (naddr && adapter->params.vfres.nvi == 1) {
  2754. struct sockaddr addr;
  2755. ether_addr_copy(addr.sa_data, mac);
  2756. err = cxgb4vf_set_mac_addr(netdev, &addr);
  2757. if (err) {
  2758. dev_err(&pdev->dev,
  2759. "unable to set MAC address %pM\n",
  2760. mac);
  2761. goto err_free_dev;
  2762. }
  2763. dev_info(&pdev->dev,
  2764. "Using assigned MAC ACL: %pM\n", mac);
  2765. }
  2766. }
  2767. /* See what interrupts we'll be using. If we've been configured to
  2768. * use MSI-X interrupts, try to enable them but fall back to using
  2769. * MSI interrupts if we can't enable MSI-X interrupts. If we can't
  2770. * get MSI interrupts we bail with the error.
  2771. */
  2772. if (msi == MSI_MSIX && enable_msix(adapter) == 0)
  2773. adapter->flags |= USING_MSIX;
  2774. else {
  2775. if (msi == MSI_MSIX) {
  2776. dev_info(adapter->pdev_dev,
  2777. "Unable to use MSI-X Interrupts; falling "
  2778. "back to MSI Interrupts\n");
  2779. /* We're going to need a Forwarded Interrupt Queue so
  2780. * that may cut into how many Queue Sets we can
  2781. * support.
  2782. */
  2783. msi = MSI_MSI;
  2784. size_nports_qsets(adapter);
  2785. }
  2786. err = pci_enable_msi(pdev);
  2787. if (err) {
  2788. dev_err(&pdev->dev, "Unable to allocate MSI Interrupts;"
  2789. " err=%d\n", err);
  2790. goto err_free_dev;
  2791. }
  2792. adapter->flags |= USING_MSI;
  2793. }
  2794. /* Now that we know how many "ports" we have and what interrupt
  2795. * mechanism we're going to use, we can configure our queue resources.
  2796. */
  2797. cfg_queues(adapter);
  2798. /*
  2799. * The "card" is now ready to go. If any errors occur during device
  2800. * registration we do not fail the whole "card" but rather proceed
  2801. * only with the ports we manage to register successfully. However we
  2802. * must register at least one net device.
  2803. */
  2804. for_each_port(adapter, pidx) {
  2805. struct port_info *pi = netdev_priv(adapter->port[pidx]);
  2806. netdev = adapter->port[pidx];
  2807. if (netdev == NULL)
  2808. continue;
  2809. netif_set_real_num_tx_queues(netdev, pi->nqsets);
  2810. netif_set_real_num_rx_queues(netdev, pi->nqsets);
  2811. err = register_netdev(netdev);
  2812. if (err) {
  2813. dev_warn(&pdev->dev, "cannot register net device %s,"
  2814. " skipping\n", netdev->name);
  2815. continue;
  2816. }
  2817. set_bit(pidx, &adapter->registered_device_map);
  2818. }
  2819. if (adapter->registered_device_map == 0) {
  2820. dev_err(&pdev->dev, "could not register any net devices\n");
  2821. goto err_disable_interrupts;
  2822. }
  2823. /*
  2824. * Set up our debugfs entries.
  2825. */
  2826. if (!IS_ERR_OR_NULL(cxgb4vf_debugfs_root)) {
  2827. adapter->debugfs_root =
  2828. debugfs_create_dir(pci_name(pdev),
  2829. cxgb4vf_debugfs_root);
  2830. if (IS_ERR_OR_NULL(adapter->debugfs_root))
  2831. dev_warn(&pdev->dev, "could not create debugfs"
  2832. " directory");
  2833. else
  2834. setup_debugfs(adapter);
  2835. }
  2836. /*
  2837. * Print a short notice on the existence and configuration of the new
  2838. * VF network device ...
  2839. */
  2840. for_each_port(adapter, pidx) {
  2841. dev_info(adapter->pdev_dev, "%s: Chelsio VF NIC PCIe %s\n",
  2842. adapter->port[pidx]->name,
  2843. (adapter->flags & USING_MSIX) ? "MSI-X" :
  2844. (adapter->flags & USING_MSI) ? "MSI" : "");
  2845. }
  2846. /*
  2847. * Return success!
  2848. */
  2849. return 0;
  2850. /*
  2851. * Error recovery and exit code. Unwind state that's been created
  2852. * so far and return the error.
  2853. */
  2854. err_disable_interrupts:
  2855. if (adapter->flags & USING_MSIX) {
  2856. pci_disable_msix(adapter->pdev);
  2857. adapter->flags &= ~USING_MSIX;
  2858. } else if (adapter->flags & USING_MSI) {
  2859. pci_disable_msi(adapter->pdev);
  2860. adapter->flags &= ~USING_MSI;
  2861. }
  2862. err_free_dev:
  2863. for_each_port(adapter, pidx) {
  2864. netdev = adapter->port[pidx];
  2865. if (netdev == NULL)
  2866. continue;
  2867. pi = netdev_priv(netdev);
  2868. t4vf_free_vi(adapter, pi->viid);
  2869. if (test_bit(pidx, &adapter->registered_device_map))
  2870. unregister_netdev(netdev);
  2871. free_netdev(netdev);
  2872. }
  2873. err_unmap_bar:
  2874. if (!is_t4(adapter->params.chip))
  2875. iounmap(adapter->bar2);
  2876. err_unmap_bar0:
  2877. iounmap(adapter->regs);
  2878. err_free_adapter:
  2879. kfree(adapter->mbox_log);
  2880. kfree(adapter);
  2881. err_release_regions:
  2882. pci_release_regions(pdev);
  2883. pci_clear_master(pdev);
  2884. err_disable_device:
  2885. pci_disable_device(pdev);
  2886. return err;
  2887. }
  2888. /*
  2889. * "Remove" a device: tear down all kernel and driver state created in the
  2890. * "probe" routine and quiesce the device (disable interrupts, etc.). (Note
  2891. * that this is called "remove_one" in the PF Driver.)
  2892. */
  2893. static void cxgb4vf_pci_remove(struct pci_dev *pdev)
  2894. {
  2895. struct adapter *adapter = pci_get_drvdata(pdev);
  2896. /*
  2897. * Tear down driver state associated with device.
  2898. */
  2899. if (adapter) {
  2900. int pidx;
  2901. /*
  2902. * Stop all of our activity. Unregister network port,
  2903. * disable interrupts, etc.
  2904. */
  2905. for_each_port(adapter, pidx)
  2906. if (test_bit(pidx, &adapter->registered_device_map))
  2907. unregister_netdev(adapter->port[pidx]);
  2908. t4vf_sge_stop(adapter);
  2909. if (adapter->flags & USING_MSIX) {
  2910. pci_disable_msix(adapter->pdev);
  2911. adapter->flags &= ~USING_MSIX;
  2912. } else if (adapter->flags & USING_MSI) {
  2913. pci_disable_msi(adapter->pdev);
  2914. adapter->flags &= ~USING_MSI;
  2915. }
  2916. /*
  2917. * Tear down our debugfs entries.
  2918. */
  2919. if (!IS_ERR_OR_NULL(adapter->debugfs_root)) {
  2920. cleanup_debugfs(adapter);
  2921. debugfs_remove_recursive(adapter->debugfs_root);
  2922. }
  2923. /*
  2924. * Free all of the various resources which we've acquired ...
  2925. */
  2926. t4vf_free_sge_resources(adapter);
  2927. for_each_port(adapter, pidx) {
  2928. struct net_device *netdev = adapter->port[pidx];
  2929. struct port_info *pi;
  2930. if (netdev == NULL)
  2931. continue;
  2932. pi = netdev_priv(netdev);
  2933. t4vf_free_vi(adapter, pi->viid);
  2934. free_netdev(netdev);
  2935. }
  2936. iounmap(adapter->regs);
  2937. if (!is_t4(adapter->params.chip))
  2938. iounmap(adapter->bar2);
  2939. kfree(adapter->mbox_log);
  2940. kfree(adapter);
  2941. }
  2942. /*
  2943. * Disable the device and release its PCI resources.
  2944. */
  2945. pci_disable_device(pdev);
  2946. pci_clear_master(pdev);
  2947. pci_release_regions(pdev);
  2948. }
  2949. /*
  2950. * "Shutdown" quiesce the device, stopping Ingress Packet and Interrupt
  2951. * delivery.
  2952. */
  2953. static void cxgb4vf_pci_shutdown(struct pci_dev *pdev)
  2954. {
  2955. struct adapter *adapter;
  2956. int pidx;
  2957. adapter = pci_get_drvdata(pdev);
  2958. if (!adapter)
  2959. return;
  2960. /* Disable all Virtual Interfaces. This will shut down the
  2961. * delivery of all ingress packets into the chip for these
  2962. * Virtual Interfaces.
  2963. */
  2964. for_each_port(adapter, pidx)
  2965. if (test_bit(pidx, &adapter->registered_device_map))
  2966. unregister_netdev(adapter->port[pidx]);
  2967. /* Free up all Queues which will prevent further DMA and
  2968. * Interrupts allowing various internal pathways to drain.
  2969. */
  2970. t4vf_sge_stop(adapter);
  2971. if (adapter->flags & USING_MSIX) {
  2972. pci_disable_msix(adapter->pdev);
  2973. adapter->flags &= ~USING_MSIX;
  2974. } else if (adapter->flags & USING_MSI) {
  2975. pci_disable_msi(adapter->pdev);
  2976. adapter->flags &= ~USING_MSI;
  2977. }
  2978. /*
  2979. * Free up all Queues which will prevent further DMA and
  2980. * Interrupts allowing various internal pathways to drain.
  2981. */
  2982. t4vf_free_sge_resources(adapter);
  2983. pci_set_drvdata(pdev, NULL);
  2984. }
  2985. /* Macros needed to support the PCI Device ID Table ...
  2986. */
  2987. #define CH_PCI_DEVICE_ID_TABLE_DEFINE_BEGIN \
  2988. static const struct pci_device_id cxgb4vf_pci_tbl[] = {
  2989. #define CH_PCI_DEVICE_ID_FUNCTION 0x8
  2990. #define CH_PCI_ID_TABLE_ENTRY(devid) \
  2991. { PCI_VDEVICE(CHELSIO, (devid)), 0 }
  2992. #define CH_PCI_DEVICE_ID_TABLE_DEFINE_END { 0, } }
  2993. #include "../cxgb4/t4_pci_id_tbl.h"
  2994. MODULE_DESCRIPTION(DRV_DESC);
  2995. MODULE_AUTHOR("Chelsio Communications");
  2996. MODULE_LICENSE("Dual BSD/GPL");
  2997. MODULE_VERSION(DRV_VERSION);
  2998. MODULE_DEVICE_TABLE(pci, cxgb4vf_pci_tbl);
  2999. static struct pci_driver cxgb4vf_driver = {
  3000. .name = KBUILD_MODNAME,
  3001. .id_table = cxgb4vf_pci_tbl,
  3002. .probe = cxgb4vf_pci_probe,
  3003. .remove = cxgb4vf_pci_remove,
  3004. .shutdown = cxgb4vf_pci_shutdown,
  3005. };
  3006. /*
  3007. * Initialize global driver state.
  3008. */
  3009. static int __init cxgb4vf_module_init(void)
  3010. {
  3011. int ret;
  3012. /*
  3013. * Vet our module parameters.
  3014. */
  3015. if (msi != MSI_MSIX && msi != MSI_MSI) {
  3016. pr_warn("bad module parameter msi=%d; must be %d (MSI-X or MSI) or %d (MSI)\n",
  3017. msi, MSI_MSIX, MSI_MSI);
  3018. return -EINVAL;
  3019. }
  3020. /* Debugfs support is optional, just warn if this fails */
  3021. cxgb4vf_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
  3022. if (IS_ERR_OR_NULL(cxgb4vf_debugfs_root))
  3023. pr_warn("could not create debugfs entry, continuing\n");
  3024. ret = pci_register_driver(&cxgb4vf_driver);
  3025. if (ret < 0 && !IS_ERR_OR_NULL(cxgb4vf_debugfs_root))
  3026. debugfs_remove(cxgb4vf_debugfs_root);
  3027. return ret;
  3028. }
  3029. /*
  3030. * Tear down global driver state.
  3031. */
  3032. static void __exit cxgb4vf_module_exit(void)
  3033. {
  3034. pci_unregister_driver(&cxgb4vf_driver);
  3035. debugfs_remove(cxgb4vf_debugfs_root);
  3036. }
  3037. module_init(cxgb4vf_module_init);
  3038. module_exit(cxgb4vf_module_exit);