cxgb4vf_main.c 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980
  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. #include <linux/version.h>
  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 "t4vf_common.h"
  46. #include "t4vf_defs.h"
  47. #include "../cxgb4/t4_regs.h"
  48. #include "../cxgb4/t4_msg.h"
  49. /*
  50. * Generic information about the driver.
  51. */
  52. #define DRV_VERSION "1.0.0"
  53. #define DRV_DESC "Chelsio T4 Virtual Function (VF) Network Driver"
  54. /*
  55. * Module Parameters.
  56. * ==================
  57. */
  58. /*
  59. * Default ethtool "message level" for adapters.
  60. */
  61. #define DFLT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK | \
  62. NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP |\
  63. NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
  64. static int dflt_msg_enable = DFLT_MSG_ENABLE;
  65. module_param(dflt_msg_enable, int, 0644);
  66. MODULE_PARM_DESC(dflt_msg_enable,
  67. "default adapter ethtool message level bitmap");
  68. /*
  69. * The driver uses the best interrupt scheme available on a platform in the
  70. * order MSI-X then MSI. This parameter determines which of these schemes the
  71. * driver may consider as follows:
  72. *
  73. * msi = 2: choose from among MSI-X and MSI
  74. * msi = 1: only consider MSI interrupts
  75. *
  76. * Note that unlike the Physical Function driver, this Virtual Function driver
  77. * does _not_ support legacy INTx interrupts (this limitation is mandated by
  78. * the PCI-E SR-IOV standard).
  79. */
  80. #define MSI_MSIX 2
  81. #define MSI_MSI 1
  82. #define MSI_DEFAULT MSI_MSIX
  83. static int msi = MSI_DEFAULT;
  84. module_param(msi, int, 0644);
  85. MODULE_PARM_DESC(msi, "whether to use MSI-X or MSI");
  86. /*
  87. * Fundamental constants.
  88. * ======================
  89. */
  90. enum {
  91. MAX_TXQ_ENTRIES = 16384,
  92. MAX_RSPQ_ENTRIES = 16384,
  93. MAX_RX_BUFFERS = 16384,
  94. MIN_TXQ_ENTRIES = 32,
  95. MIN_RSPQ_ENTRIES = 128,
  96. MIN_FL_ENTRIES = 16,
  97. /*
  98. * For purposes of manipulating the Free List size we need to
  99. * recognize that Free Lists are actually Egress Queues (the host
  100. * produces free buffers which the hardware consumes), Egress Queues
  101. * indices are all in units of Egress Context Units bytes, and free
  102. * list entries are 64-bit PCI DMA addresses. And since the state of
  103. * the Producer Index == the Consumer Index implies an EMPTY list, we
  104. * always have at least one Egress Unit's worth of Free List entries
  105. * unused. See sge.c for more details ...
  106. */
  107. EQ_UNIT = SGE_EQ_IDXSIZE,
  108. FL_PER_EQ_UNIT = EQ_UNIT / sizeof(__be64),
  109. MIN_FL_RESID = FL_PER_EQ_UNIT,
  110. };
  111. /*
  112. * Global driver state.
  113. * ====================
  114. */
  115. static struct dentry *cxgb4vf_debugfs_root;
  116. /*
  117. * OS "Callback" functions.
  118. * ========================
  119. */
  120. /*
  121. * The link status has changed on the indicated "port" (Virtual Interface).
  122. */
  123. void t4vf_os_link_changed(struct adapter *adapter, int pidx, int link_ok)
  124. {
  125. struct net_device *dev = adapter->port[pidx];
  126. /*
  127. * If the port is disabled or the current recorded "link up"
  128. * status matches the new status, just return.
  129. */
  130. if (!netif_running(dev) || link_ok == netif_carrier_ok(dev))
  131. return;
  132. /*
  133. * Tell the OS that the link status has changed and print a short
  134. * informative message on the console about the event.
  135. */
  136. if (link_ok) {
  137. const char *s;
  138. const char *fc;
  139. const struct port_info *pi = netdev_priv(dev);
  140. netif_carrier_on(dev);
  141. switch (pi->link_cfg.speed) {
  142. case SPEED_10000:
  143. s = "10Gbps";
  144. break;
  145. case SPEED_1000:
  146. s = "1000Mbps";
  147. break;
  148. case SPEED_100:
  149. s = "100Mbps";
  150. break;
  151. default:
  152. s = "unknown";
  153. break;
  154. }
  155. switch (pi->link_cfg.fc) {
  156. case PAUSE_RX:
  157. fc = "RX";
  158. break;
  159. case PAUSE_TX:
  160. fc = "TX";
  161. break;
  162. case PAUSE_RX|PAUSE_TX:
  163. fc = "RX/TX";
  164. break;
  165. default:
  166. fc = "no";
  167. break;
  168. }
  169. printk(KERN_INFO "%s: link up, %s, full-duplex, %s PAUSE\n",
  170. dev->name, s, fc);
  171. } else {
  172. netif_carrier_off(dev);
  173. printk(KERN_INFO "%s: link down\n", dev->name);
  174. }
  175. }
  176. /*
  177. * Net device operations.
  178. * ======================
  179. */
  180. /*
  181. * Record our new VLAN Group and enable/disable hardware VLAN Tag extraction
  182. * based on whether the specified VLAN Group pointer is NULL or not.
  183. */
  184. static void cxgb4vf_vlan_rx_register(struct net_device *dev,
  185. struct vlan_group *grp)
  186. {
  187. struct port_info *pi = netdev_priv(dev);
  188. pi->vlan_grp = grp;
  189. t4vf_set_rxmode(pi->adapter, pi->viid, -1, -1, -1, -1, grp != NULL, 0);
  190. }
  191. /*
  192. * Perform the MAC and PHY actions needed to enable a "port" (Virtual
  193. * Interface).
  194. */
  195. static int link_start(struct net_device *dev)
  196. {
  197. int ret;
  198. struct port_info *pi = netdev_priv(dev);
  199. /*
  200. * We do not set address filters and promiscuity here, the stack does
  201. * that step explicitly.
  202. */
  203. ret = t4vf_set_rxmode(pi->adapter, pi->viid, dev->mtu, -1, -1, -1, -1,
  204. true);
  205. if (ret == 0) {
  206. ret = t4vf_change_mac(pi->adapter, pi->viid,
  207. pi->xact_addr_filt, dev->dev_addr, true);
  208. if (ret >= 0) {
  209. pi->xact_addr_filt = ret;
  210. ret = 0;
  211. }
  212. }
  213. /*
  214. * We don't need to actually "start the link" itself since the
  215. * firmware will do that for us when the first Virtual Interface
  216. * is enabled on a port.
  217. */
  218. if (ret == 0)
  219. ret = t4vf_enable_vi(pi->adapter, pi->viid, true, true);
  220. return ret;
  221. }
  222. /*
  223. * Name the MSI-X interrupts.
  224. */
  225. static void name_msix_vecs(struct adapter *adapter)
  226. {
  227. int namelen = sizeof(adapter->msix_info[0].desc) - 1;
  228. int pidx;
  229. /*
  230. * Firmware events.
  231. */
  232. snprintf(adapter->msix_info[MSIX_FW].desc, namelen,
  233. "%s-FWeventq", adapter->name);
  234. adapter->msix_info[MSIX_FW].desc[namelen] = 0;
  235. /*
  236. * Ethernet queues.
  237. */
  238. for_each_port(adapter, pidx) {
  239. struct net_device *dev = adapter->port[pidx];
  240. const struct port_info *pi = netdev_priv(dev);
  241. int qs, msi;
  242. for (qs = 0, msi = MSIX_IQFLINT; qs < pi->nqsets; qs++, msi++) {
  243. snprintf(adapter->msix_info[msi].desc, namelen,
  244. "%s-%d", dev->name, qs);
  245. adapter->msix_info[msi].desc[namelen] = 0;
  246. }
  247. }
  248. }
  249. /*
  250. * Request all of our MSI-X resources.
  251. */
  252. static int request_msix_queue_irqs(struct adapter *adapter)
  253. {
  254. struct sge *s = &adapter->sge;
  255. int rxq, msi, err;
  256. /*
  257. * Firmware events.
  258. */
  259. err = request_irq(adapter->msix_info[MSIX_FW].vec, t4vf_sge_intr_msix,
  260. 0, adapter->msix_info[MSIX_FW].desc, &s->fw_evtq);
  261. if (err)
  262. return err;
  263. /*
  264. * Ethernet queues.
  265. */
  266. msi = MSIX_IQFLINT;
  267. for_each_ethrxq(s, rxq) {
  268. err = request_irq(adapter->msix_info[msi].vec,
  269. t4vf_sge_intr_msix, 0,
  270. adapter->msix_info[msi].desc,
  271. &s->ethrxq[rxq].rspq);
  272. if (err)
  273. goto err_free_irqs;
  274. msi++;
  275. }
  276. return 0;
  277. err_free_irqs:
  278. while (--rxq >= 0)
  279. free_irq(adapter->msix_info[--msi].vec, &s->ethrxq[rxq].rspq);
  280. free_irq(adapter->msix_info[MSIX_FW].vec, &s->fw_evtq);
  281. return err;
  282. }
  283. /*
  284. * Free our MSI-X resources.
  285. */
  286. static void free_msix_queue_irqs(struct adapter *adapter)
  287. {
  288. struct sge *s = &adapter->sge;
  289. int rxq, msi;
  290. free_irq(adapter->msix_info[MSIX_FW].vec, &s->fw_evtq);
  291. msi = MSIX_IQFLINT;
  292. for_each_ethrxq(s, rxq)
  293. free_irq(adapter->msix_info[msi++].vec,
  294. &s->ethrxq[rxq].rspq);
  295. }
  296. /*
  297. * Turn on NAPI and start up interrupts on a response queue.
  298. */
  299. static void qenable(struct sge_rspq *rspq)
  300. {
  301. napi_enable(&rspq->napi);
  302. /*
  303. * 0-increment the Going To Sleep register to start the timer and
  304. * enable interrupts.
  305. */
  306. t4_write_reg(rspq->adapter, T4VF_SGE_BASE_ADDR + SGE_VF_GTS,
  307. CIDXINC(0) |
  308. SEINTARM(rspq->intr_params) |
  309. INGRESSQID(rspq->cntxt_id));
  310. }
  311. /*
  312. * Enable NAPI scheduling and interrupt generation for all Receive Queues.
  313. */
  314. static void enable_rx(struct adapter *adapter)
  315. {
  316. int rxq;
  317. struct sge *s = &adapter->sge;
  318. for_each_ethrxq(s, rxq)
  319. qenable(&s->ethrxq[rxq].rspq);
  320. qenable(&s->fw_evtq);
  321. /*
  322. * The interrupt queue doesn't use NAPI so we do the 0-increment of
  323. * its Going To Sleep register here to get it started.
  324. */
  325. if (adapter->flags & USING_MSI)
  326. t4_write_reg(adapter, T4VF_SGE_BASE_ADDR + SGE_VF_GTS,
  327. CIDXINC(0) |
  328. SEINTARM(s->intrq.intr_params) |
  329. INGRESSQID(s->intrq.cntxt_id));
  330. }
  331. /*
  332. * Wait until all NAPI handlers are descheduled.
  333. */
  334. static void quiesce_rx(struct adapter *adapter)
  335. {
  336. struct sge *s = &adapter->sge;
  337. int rxq;
  338. for_each_ethrxq(s, rxq)
  339. napi_disable(&s->ethrxq[rxq].rspq.napi);
  340. napi_disable(&s->fw_evtq.napi);
  341. }
  342. /*
  343. * Response queue handler for the firmware event queue.
  344. */
  345. static int fwevtq_handler(struct sge_rspq *rspq, const __be64 *rsp,
  346. const struct pkt_gl *gl)
  347. {
  348. /*
  349. * Extract response opcode and get pointer to CPL message body.
  350. */
  351. struct adapter *adapter = rspq->adapter;
  352. u8 opcode = ((const struct rss_header *)rsp)->opcode;
  353. void *cpl = (void *)(rsp + 1);
  354. switch (opcode) {
  355. case CPL_FW6_MSG: {
  356. /*
  357. * We've received an asynchronous message from the firmware.
  358. */
  359. const struct cpl_fw6_msg *fw_msg = cpl;
  360. if (fw_msg->type == FW6_TYPE_CMD_RPL)
  361. t4vf_handle_fw_rpl(adapter, fw_msg->data);
  362. break;
  363. }
  364. case CPL_SGE_EGR_UPDATE: {
  365. /*
  366. * We've received an Egress Queue Status Update message. We
  367. * get these, if the SGE is configured to send these when the
  368. * firmware passes certain points in processing our TX
  369. * Ethernet Queue or if we make an explicit request for one.
  370. * We use these updates to determine when we may need to
  371. * restart a TX Ethernet Queue which was stopped for lack of
  372. * free TX Queue Descriptors ...
  373. */
  374. const struct cpl_sge_egr_update *p = (void *)cpl;
  375. unsigned int qid = EGR_QID(be32_to_cpu(p->opcode_qid));
  376. struct sge *s = &adapter->sge;
  377. struct sge_txq *tq;
  378. struct sge_eth_txq *txq;
  379. unsigned int eq_idx;
  380. /*
  381. * Perform sanity checking on the Queue ID to make sure it
  382. * really refers to one of our TX Ethernet Egress Queues which
  383. * is active and matches the queue's ID. None of these error
  384. * conditions should ever happen so we may want to either make
  385. * them fatal and/or conditionalized under DEBUG.
  386. */
  387. eq_idx = EQ_IDX(s, qid);
  388. if (unlikely(eq_idx >= MAX_EGRQ)) {
  389. dev_err(adapter->pdev_dev,
  390. "Egress Update QID %d out of range\n", qid);
  391. break;
  392. }
  393. tq = s->egr_map[eq_idx];
  394. if (unlikely(tq == NULL)) {
  395. dev_err(adapter->pdev_dev,
  396. "Egress Update QID %d TXQ=NULL\n", qid);
  397. break;
  398. }
  399. txq = container_of(tq, struct sge_eth_txq, q);
  400. if (unlikely(tq->abs_id != qid)) {
  401. dev_err(adapter->pdev_dev,
  402. "Egress Update QID %d refers to TXQ %d\n",
  403. qid, tq->abs_id);
  404. break;
  405. }
  406. /*
  407. * Restart a stopped TX Queue which has less than half of its
  408. * TX ring in use ...
  409. */
  410. txq->q.restarts++;
  411. netif_tx_wake_queue(txq->txq);
  412. break;
  413. }
  414. default:
  415. dev_err(adapter->pdev_dev,
  416. "unexpected CPL %#x on FW event queue\n", opcode);
  417. }
  418. return 0;
  419. }
  420. /*
  421. * Allocate SGE TX/RX response queues. Determine how many sets of SGE queues
  422. * to use and initializes them. We support multiple "Queue Sets" per port if
  423. * we have MSI-X, otherwise just one queue set per port.
  424. */
  425. static int setup_sge_queues(struct adapter *adapter)
  426. {
  427. struct sge *s = &adapter->sge;
  428. int err, pidx, msix;
  429. /*
  430. * Clear "Queue Set" Free List Starving and TX Queue Mapping Error
  431. * state.
  432. */
  433. bitmap_zero(s->starving_fl, MAX_EGRQ);
  434. /*
  435. * If we're using MSI interrupt mode we need to set up a "forwarded
  436. * interrupt" queue which we'll set up with our MSI vector. The rest
  437. * of the ingress queues will be set up to forward their interrupts to
  438. * this queue ... This must be first since t4vf_sge_alloc_rxq() uses
  439. * the intrq's queue ID as the interrupt forwarding queue for the
  440. * subsequent calls ...
  441. */
  442. if (adapter->flags & USING_MSI) {
  443. err = t4vf_sge_alloc_rxq(adapter, &s->intrq, false,
  444. adapter->port[0], 0, NULL, NULL);
  445. if (err)
  446. goto err_free_queues;
  447. }
  448. /*
  449. * Allocate our ingress queue for asynchronous firmware messages.
  450. */
  451. err = t4vf_sge_alloc_rxq(adapter, &s->fw_evtq, true, adapter->port[0],
  452. MSIX_FW, NULL, fwevtq_handler);
  453. if (err)
  454. goto err_free_queues;
  455. /*
  456. * Allocate each "port"'s initial Queue Sets. These can be changed
  457. * later on ... up to the point where any interface on the adapter is
  458. * brought up at which point lots of things get nailed down
  459. * permanently ...
  460. */
  461. msix = MSIX_IQFLINT;
  462. for_each_port(adapter, pidx) {
  463. struct net_device *dev = adapter->port[pidx];
  464. struct port_info *pi = netdev_priv(dev);
  465. struct sge_eth_rxq *rxq = &s->ethrxq[pi->first_qset];
  466. struct sge_eth_txq *txq = &s->ethtxq[pi->first_qset];
  467. int qs;
  468. for (qs = 0; qs < pi->nqsets; qs++, rxq++, txq++) {
  469. err = t4vf_sge_alloc_rxq(adapter, &rxq->rspq, false,
  470. dev, msix++,
  471. &rxq->fl, t4vf_ethrx_handler);
  472. if (err)
  473. goto err_free_queues;
  474. err = t4vf_sge_alloc_eth_txq(adapter, txq, dev,
  475. netdev_get_tx_queue(dev, qs),
  476. s->fw_evtq.cntxt_id);
  477. if (err)
  478. goto err_free_queues;
  479. rxq->rspq.idx = qs;
  480. memset(&rxq->stats, 0, sizeof(rxq->stats));
  481. }
  482. }
  483. /*
  484. * Create the reverse mappings for the queues.
  485. */
  486. s->egr_base = s->ethtxq[0].q.abs_id - s->ethtxq[0].q.cntxt_id;
  487. s->ingr_base = s->ethrxq[0].rspq.abs_id - s->ethrxq[0].rspq.cntxt_id;
  488. IQ_MAP(s, s->fw_evtq.abs_id) = &s->fw_evtq;
  489. for_each_port(adapter, pidx) {
  490. struct net_device *dev = adapter->port[pidx];
  491. struct port_info *pi = netdev_priv(dev);
  492. struct sge_eth_rxq *rxq = &s->ethrxq[pi->first_qset];
  493. struct sge_eth_txq *txq = &s->ethtxq[pi->first_qset];
  494. int qs;
  495. for (qs = 0; qs < pi->nqsets; qs++, rxq++, txq++) {
  496. IQ_MAP(s, rxq->rspq.abs_id) = &rxq->rspq;
  497. EQ_MAP(s, txq->q.abs_id) = &txq->q;
  498. /*
  499. * The FW_IQ_CMD doesn't return the Absolute Queue IDs
  500. * for Free Lists but since all of the Egress Queues
  501. * (including Free Lists) have Relative Queue IDs
  502. * which are computed as Absolute - Base Queue ID, we
  503. * can synthesize the Absolute Queue IDs for the Free
  504. * Lists. This is useful for debugging purposes when
  505. * we want to dump Queue Contexts via the PF Driver.
  506. */
  507. rxq->fl.abs_id = rxq->fl.cntxt_id + s->egr_base;
  508. EQ_MAP(s, rxq->fl.abs_id) = &rxq->fl;
  509. }
  510. }
  511. return 0;
  512. err_free_queues:
  513. t4vf_free_sge_resources(adapter);
  514. return err;
  515. }
  516. /*
  517. * Set up Receive Side Scaling (RSS) to distribute packets to multiple receive
  518. * queues. We configure the RSS CPU lookup table to distribute to the number
  519. * of HW receive queues, and the response queue lookup table to narrow that
  520. * down to the response queues actually configured for each "port" (Virtual
  521. * Interface). We always configure the RSS mapping for all ports since the
  522. * mapping table has plenty of entries.
  523. */
  524. static int setup_rss(struct adapter *adapter)
  525. {
  526. int pidx;
  527. for_each_port(adapter, pidx) {
  528. struct port_info *pi = adap2pinfo(adapter, pidx);
  529. struct sge_eth_rxq *rxq = &adapter->sge.ethrxq[pi->first_qset];
  530. u16 rss[MAX_PORT_QSETS];
  531. int qs, err;
  532. for (qs = 0; qs < pi->nqsets; qs++)
  533. rss[qs] = rxq[qs].rspq.abs_id;
  534. err = t4vf_config_rss_range(adapter, pi->viid,
  535. 0, pi->rss_size, rss, pi->nqsets);
  536. if (err)
  537. return err;
  538. /*
  539. * Perform Global RSS Mode-specific initialization.
  540. */
  541. switch (adapter->params.rss.mode) {
  542. case FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL:
  543. /*
  544. * If Tunnel All Lookup isn't specified in the global
  545. * RSS Configuration, then we need to specify a
  546. * default Ingress Queue for any ingress packets which
  547. * aren't hashed. We'll use our first ingress queue
  548. * ...
  549. */
  550. if (!adapter->params.rss.u.basicvirtual.tnlalllookup) {
  551. union rss_vi_config config;
  552. err = t4vf_read_rss_vi_config(adapter,
  553. pi->viid,
  554. &config);
  555. if (err)
  556. return err;
  557. config.basicvirtual.defaultq =
  558. rxq[0].rspq.abs_id;
  559. err = t4vf_write_rss_vi_config(adapter,
  560. pi->viid,
  561. &config);
  562. if (err)
  563. return err;
  564. }
  565. break;
  566. }
  567. }
  568. return 0;
  569. }
  570. /*
  571. * Bring the adapter up. Called whenever we go from no "ports" open to having
  572. * one open. This function performs the actions necessary to make an adapter
  573. * operational, such as completing the initialization of HW modules, and
  574. * enabling interrupts. Must be called with the rtnl lock held. (Note that
  575. * this is called "cxgb_up" in the PF Driver.)
  576. */
  577. static int adapter_up(struct adapter *adapter)
  578. {
  579. int err;
  580. /*
  581. * If this is the first time we've been called, perform basic
  582. * adapter setup. Once we've done this, many of our adapter
  583. * parameters can no longer be changed ...
  584. */
  585. if ((adapter->flags & FULL_INIT_DONE) == 0) {
  586. err = setup_sge_queues(adapter);
  587. if (err)
  588. return err;
  589. err = setup_rss(adapter);
  590. if (err) {
  591. t4vf_free_sge_resources(adapter);
  592. return err;
  593. }
  594. if (adapter->flags & USING_MSIX)
  595. name_msix_vecs(adapter);
  596. adapter->flags |= FULL_INIT_DONE;
  597. }
  598. /*
  599. * Acquire our interrupt resources. We only support MSI-X and MSI.
  600. */
  601. BUG_ON((adapter->flags & (USING_MSIX|USING_MSI)) == 0);
  602. if (adapter->flags & USING_MSIX)
  603. err = request_msix_queue_irqs(adapter);
  604. else
  605. err = request_irq(adapter->pdev->irq,
  606. t4vf_intr_handler(adapter), 0,
  607. adapter->name, adapter);
  608. if (err) {
  609. dev_err(adapter->pdev_dev, "request_irq failed, err %d\n",
  610. err);
  611. return err;
  612. }
  613. /*
  614. * Enable NAPI ingress processing and return success.
  615. */
  616. enable_rx(adapter);
  617. t4vf_sge_start(adapter);
  618. return 0;
  619. }
  620. /*
  621. * Bring the adapter down. Called whenever the last "port" (Virtual
  622. * Interface) closed. (Note that this routine is called "cxgb_down" in the PF
  623. * Driver.)
  624. */
  625. static void adapter_down(struct adapter *adapter)
  626. {
  627. /*
  628. * Free interrupt resources.
  629. */
  630. if (adapter->flags & USING_MSIX)
  631. free_msix_queue_irqs(adapter);
  632. else
  633. free_irq(adapter->pdev->irq, adapter);
  634. /*
  635. * Wait for NAPI handlers to finish.
  636. */
  637. quiesce_rx(adapter);
  638. }
  639. /*
  640. * Start up a net device.
  641. */
  642. static int cxgb4vf_open(struct net_device *dev)
  643. {
  644. int err;
  645. struct port_info *pi = netdev_priv(dev);
  646. struct adapter *adapter = pi->adapter;
  647. /*
  648. * If this is the first interface that we're opening on the "adapter",
  649. * bring the "adapter" up now.
  650. */
  651. if (adapter->open_device_map == 0) {
  652. err = adapter_up(adapter);
  653. if (err)
  654. return err;
  655. }
  656. /*
  657. * Note that this interface is up and start everything up ...
  658. */
  659. netif_set_real_num_tx_queues(dev, pi->nqsets);
  660. err = netif_set_real_num_rx_queues(dev, pi->nqsets);
  661. if (err)
  662. goto err_unwind;
  663. err = link_start(dev);
  664. if (err)
  665. goto err_unwind;
  666. netif_tx_start_all_queues(dev);
  667. set_bit(pi->port_id, &adapter->open_device_map);
  668. return 0;
  669. err_unwind:
  670. if (adapter->open_device_map == 0)
  671. adapter_down(adapter);
  672. return err;
  673. }
  674. /*
  675. * Shut down a net device. This routine is called "cxgb_close" in the PF
  676. * Driver ...
  677. */
  678. static int cxgb4vf_stop(struct net_device *dev)
  679. {
  680. struct port_info *pi = netdev_priv(dev);
  681. struct adapter *adapter = pi->adapter;
  682. netif_tx_stop_all_queues(dev);
  683. netif_carrier_off(dev);
  684. t4vf_enable_vi(adapter, pi->viid, false, false);
  685. pi->link_cfg.link_ok = 0;
  686. clear_bit(pi->port_id, &adapter->open_device_map);
  687. if (adapter->open_device_map == 0)
  688. adapter_down(adapter);
  689. return 0;
  690. }
  691. /*
  692. * Translate our basic statistics into the standard "ifconfig" statistics.
  693. */
  694. static struct net_device_stats *cxgb4vf_get_stats(struct net_device *dev)
  695. {
  696. struct t4vf_port_stats stats;
  697. struct port_info *pi = netdev2pinfo(dev);
  698. struct adapter *adapter = pi->adapter;
  699. struct net_device_stats *ns = &dev->stats;
  700. int err;
  701. spin_lock(&adapter->stats_lock);
  702. err = t4vf_get_port_stats(adapter, pi->pidx, &stats);
  703. spin_unlock(&adapter->stats_lock);
  704. memset(ns, 0, sizeof(*ns));
  705. if (err)
  706. return ns;
  707. ns->tx_bytes = (stats.tx_bcast_bytes + stats.tx_mcast_bytes +
  708. stats.tx_ucast_bytes + stats.tx_offload_bytes);
  709. ns->tx_packets = (stats.tx_bcast_frames + stats.tx_mcast_frames +
  710. stats.tx_ucast_frames + stats.tx_offload_frames);
  711. ns->rx_bytes = (stats.rx_bcast_bytes + stats.rx_mcast_bytes +
  712. stats.rx_ucast_bytes);
  713. ns->rx_packets = (stats.rx_bcast_frames + stats.rx_mcast_frames +
  714. stats.rx_ucast_frames);
  715. ns->multicast = stats.rx_mcast_frames;
  716. ns->tx_errors = stats.tx_drop_frames;
  717. ns->rx_errors = stats.rx_err_frames;
  718. return ns;
  719. }
  720. /*
  721. * Collect up to maxaddrs worth of a netdevice's unicast addresses, starting
  722. * at a specified offset within the list, into an array of addrss pointers and
  723. * return the number collected.
  724. */
  725. static inline unsigned int collect_netdev_uc_list_addrs(const struct net_device *dev,
  726. const u8 **addr,
  727. unsigned int offset,
  728. unsigned int maxaddrs)
  729. {
  730. unsigned int index = 0;
  731. unsigned int naddr = 0;
  732. const struct netdev_hw_addr *ha;
  733. for_each_dev_addr(dev, ha)
  734. if (index++ >= offset) {
  735. addr[naddr++] = ha->addr;
  736. if (naddr >= maxaddrs)
  737. break;
  738. }
  739. return naddr;
  740. }
  741. /*
  742. * Collect up to maxaddrs worth of a netdevice's multicast addresses, starting
  743. * at a specified offset within the list, into an array of addrss pointers and
  744. * return the number collected.
  745. */
  746. static inline unsigned int collect_netdev_mc_list_addrs(const struct net_device *dev,
  747. const u8 **addr,
  748. unsigned int offset,
  749. unsigned int maxaddrs)
  750. {
  751. unsigned int index = 0;
  752. unsigned int naddr = 0;
  753. const struct netdev_hw_addr *ha;
  754. netdev_for_each_mc_addr(ha, dev)
  755. if (index++ >= offset) {
  756. addr[naddr++] = ha->addr;
  757. if (naddr >= maxaddrs)
  758. break;
  759. }
  760. return naddr;
  761. }
  762. /*
  763. * Configure the exact and hash address filters to handle a port's multicast
  764. * and secondary unicast MAC addresses.
  765. */
  766. static int set_addr_filters(const struct net_device *dev, bool sleep)
  767. {
  768. u64 mhash = 0;
  769. u64 uhash = 0;
  770. bool free = true;
  771. unsigned int offset, naddr;
  772. const u8 *addr[7];
  773. int ret;
  774. const struct port_info *pi = netdev_priv(dev);
  775. /* first do the secondary unicast addresses */
  776. for (offset = 0; ; offset += naddr) {
  777. naddr = collect_netdev_uc_list_addrs(dev, addr, offset,
  778. ARRAY_SIZE(addr));
  779. if (naddr == 0)
  780. break;
  781. ret = t4vf_alloc_mac_filt(pi->adapter, pi->viid, free,
  782. naddr, addr, NULL, &uhash, sleep);
  783. if (ret < 0)
  784. return ret;
  785. free = false;
  786. }
  787. /* next set up the multicast addresses */
  788. for (offset = 0; ; offset += naddr) {
  789. naddr = collect_netdev_mc_list_addrs(dev, addr, offset,
  790. ARRAY_SIZE(addr));
  791. if (naddr == 0)
  792. break;
  793. ret = t4vf_alloc_mac_filt(pi->adapter, pi->viid, free,
  794. naddr, addr, NULL, &mhash, sleep);
  795. if (ret < 0)
  796. return ret;
  797. free = false;
  798. }
  799. return t4vf_set_addr_hash(pi->adapter, pi->viid, uhash != 0,
  800. uhash | mhash, sleep);
  801. }
  802. /*
  803. * Set RX properties of a port, such as promiscruity, address filters, and MTU.
  804. * If @mtu is -1 it is left unchanged.
  805. */
  806. static int set_rxmode(struct net_device *dev, int mtu, bool sleep_ok)
  807. {
  808. int ret;
  809. struct port_info *pi = netdev_priv(dev);
  810. ret = set_addr_filters(dev, sleep_ok);
  811. if (ret == 0)
  812. ret = t4vf_set_rxmode(pi->adapter, pi->viid, -1,
  813. (dev->flags & IFF_PROMISC) != 0,
  814. (dev->flags & IFF_ALLMULTI) != 0,
  815. 1, -1, sleep_ok);
  816. return ret;
  817. }
  818. /*
  819. * Set the current receive modes on the device.
  820. */
  821. static void cxgb4vf_set_rxmode(struct net_device *dev)
  822. {
  823. /* unfortunately we can't return errors to the stack */
  824. set_rxmode(dev, -1, false);
  825. }
  826. /*
  827. * Find the entry in the interrupt holdoff timer value array which comes
  828. * closest to the specified interrupt holdoff value.
  829. */
  830. static int closest_timer(const struct sge *s, int us)
  831. {
  832. int i, timer_idx = 0, min_delta = INT_MAX;
  833. for (i = 0; i < ARRAY_SIZE(s->timer_val); i++) {
  834. int delta = us - s->timer_val[i];
  835. if (delta < 0)
  836. delta = -delta;
  837. if (delta < min_delta) {
  838. min_delta = delta;
  839. timer_idx = i;
  840. }
  841. }
  842. return timer_idx;
  843. }
  844. static int closest_thres(const struct sge *s, int thres)
  845. {
  846. int i, delta, pktcnt_idx = 0, min_delta = INT_MAX;
  847. for (i = 0; i < ARRAY_SIZE(s->counter_val); i++) {
  848. delta = thres - s->counter_val[i];
  849. if (delta < 0)
  850. delta = -delta;
  851. if (delta < min_delta) {
  852. min_delta = delta;
  853. pktcnt_idx = i;
  854. }
  855. }
  856. return pktcnt_idx;
  857. }
  858. /*
  859. * Return a queue's interrupt hold-off time in us. 0 means no timer.
  860. */
  861. static unsigned int qtimer_val(const struct adapter *adapter,
  862. const struct sge_rspq *rspq)
  863. {
  864. unsigned int timer_idx = QINTR_TIMER_IDX_GET(rspq->intr_params);
  865. return timer_idx < SGE_NTIMERS
  866. ? adapter->sge.timer_val[timer_idx]
  867. : 0;
  868. }
  869. /**
  870. * set_rxq_intr_params - set a queue's interrupt holdoff parameters
  871. * @adapter: the adapter
  872. * @rspq: the RX response queue
  873. * @us: the hold-off time in us, or 0 to disable timer
  874. * @cnt: the hold-off packet count, or 0 to disable counter
  875. *
  876. * Sets an RX response queue's interrupt hold-off time and packet count.
  877. * At least one of the two needs to be enabled for the queue to generate
  878. * interrupts.
  879. */
  880. static int set_rxq_intr_params(struct adapter *adapter, struct sge_rspq *rspq,
  881. unsigned int us, unsigned int cnt)
  882. {
  883. unsigned int timer_idx;
  884. /*
  885. * If both the interrupt holdoff timer and count are specified as
  886. * zero, default to a holdoff count of 1 ...
  887. */
  888. if ((us | cnt) == 0)
  889. cnt = 1;
  890. /*
  891. * If an interrupt holdoff count has been specified, then find the
  892. * closest configured holdoff count and use that. If the response
  893. * queue has already been created, then update its queue context
  894. * parameters ...
  895. */
  896. if (cnt) {
  897. int err;
  898. u32 v, pktcnt_idx;
  899. pktcnt_idx = closest_thres(&adapter->sge, cnt);
  900. if (rspq->desc && rspq->pktcnt_idx != pktcnt_idx) {
  901. v = FW_PARAMS_MNEM(FW_PARAMS_MNEM_DMAQ) |
  902. FW_PARAMS_PARAM_X(
  903. FW_PARAMS_PARAM_DMAQ_IQ_INTCNTTHRESH) |
  904. FW_PARAMS_PARAM_YZ(rspq->cntxt_id);
  905. err = t4vf_set_params(adapter, 1, &v, &pktcnt_idx);
  906. if (err)
  907. return err;
  908. }
  909. rspq->pktcnt_idx = pktcnt_idx;
  910. }
  911. /*
  912. * Compute the closest holdoff timer index from the supplied holdoff
  913. * timer value.
  914. */
  915. timer_idx = (us == 0
  916. ? SGE_TIMER_RSTRT_CNTR
  917. : closest_timer(&adapter->sge, us));
  918. /*
  919. * Update the response queue's interrupt coalescing parameters and
  920. * return success.
  921. */
  922. rspq->intr_params = (QINTR_TIMER_IDX(timer_idx) |
  923. (cnt > 0 ? QINTR_CNT_EN : 0));
  924. return 0;
  925. }
  926. /*
  927. * Return a version number to identify the type of adapter. The scheme is:
  928. * - bits 0..9: chip version
  929. * - bits 10..15: chip revision
  930. */
  931. static inline unsigned int mk_adap_vers(const struct adapter *adapter)
  932. {
  933. /*
  934. * Chip version 4, revision 0x3f (cxgb4vf).
  935. */
  936. return 4 | (0x3f << 10);
  937. }
  938. /*
  939. * Execute the specified ioctl command.
  940. */
  941. static int cxgb4vf_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  942. {
  943. int ret = 0;
  944. switch (cmd) {
  945. /*
  946. * The VF Driver doesn't have access to any of the other
  947. * common Ethernet device ioctl()'s (like reading/writing
  948. * PHY registers, etc.
  949. */
  950. default:
  951. ret = -EOPNOTSUPP;
  952. break;
  953. }
  954. return ret;
  955. }
  956. /*
  957. * Change the device's MTU.
  958. */
  959. static int cxgb4vf_change_mtu(struct net_device *dev, int new_mtu)
  960. {
  961. int ret;
  962. struct port_info *pi = netdev_priv(dev);
  963. /* accommodate SACK */
  964. if (new_mtu < 81)
  965. return -EINVAL;
  966. ret = t4vf_set_rxmode(pi->adapter, pi->viid, new_mtu,
  967. -1, -1, -1, -1, true);
  968. if (!ret)
  969. dev->mtu = new_mtu;
  970. return ret;
  971. }
  972. /*
  973. * Change the devices MAC address.
  974. */
  975. static int cxgb4vf_set_mac_addr(struct net_device *dev, void *_addr)
  976. {
  977. int ret;
  978. struct sockaddr *addr = _addr;
  979. struct port_info *pi = netdev_priv(dev);
  980. if (!is_valid_ether_addr(addr->sa_data))
  981. return -EINVAL;
  982. ret = t4vf_change_mac(pi->adapter, pi->viid, pi->xact_addr_filt,
  983. addr->sa_data, true);
  984. if (ret < 0)
  985. return ret;
  986. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  987. pi->xact_addr_filt = ret;
  988. return 0;
  989. }
  990. #ifdef CONFIG_NET_POLL_CONTROLLER
  991. /*
  992. * Poll all of our receive queues. This is called outside of normal interrupt
  993. * context.
  994. */
  995. static void cxgb4vf_poll_controller(struct net_device *dev)
  996. {
  997. struct port_info *pi = netdev_priv(dev);
  998. struct adapter *adapter = pi->adapter;
  999. if (adapter->flags & USING_MSIX) {
  1000. struct sge_eth_rxq *rxq;
  1001. int nqsets;
  1002. rxq = &adapter->sge.ethrxq[pi->first_qset];
  1003. for (nqsets = pi->nqsets; nqsets; nqsets--) {
  1004. t4vf_sge_intr_msix(0, &rxq->rspq);
  1005. rxq++;
  1006. }
  1007. } else
  1008. t4vf_intr_handler(adapter)(0, adapter);
  1009. }
  1010. #endif
  1011. /*
  1012. * Ethtool operations.
  1013. * ===================
  1014. *
  1015. * Note that we don't support any ethtool operations which change the physical
  1016. * state of the port to which we're linked.
  1017. */
  1018. /*
  1019. * Return current port link settings.
  1020. */
  1021. static int cxgb4vf_get_settings(struct net_device *dev,
  1022. struct ethtool_cmd *cmd)
  1023. {
  1024. const struct port_info *pi = netdev_priv(dev);
  1025. cmd->supported = pi->link_cfg.supported;
  1026. cmd->advertising = pi->link_cfg.advertising;
  1027. cmd->speed = netif_carrier_ok(dev) ? pi->link_cfg.speed : -1;
  1028. cmd->duplex = DUPLEX_FULL;
  1029. cmd->port = (cmd->supported & SUPPORTED_TP) ? PORT_TP : PORT_FIBRE;
  1030. cmd->phy_address = pi->port_id;
  1031. cmd->transceiver = XCVR_EXTERNAL;
  1032. cmd->autoneg = pi->link_cfg.autoneg;
  1033. cmd->maxtxpkt = 0;
  1034. cmd->maxrxpkt = 0;
  1035. return 0;
  1036. }
  1037. /*
  1038. * Return our driver information.
  1039. */
  1040. static void cxgb4vf_get_drvinfo(struct net_device *dev,
  1041. struct ethtool_drvinfo *drvinfo)
  1042. {
  1043. struct adapter *adapter = netdev2adap(dev);
  1044. strcpy(drvinfo->driver, KBUILD_MODNAME);
  1045. strcpy(drvinfo->version, DRV_VERSION);
  1046. strcpy(drvinfo->bus_info, pci_name(to_pci_dev(dev->dev.parent)));
  1047. snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
  1048. "%u.%u.%u.%u, TP %u.%u.%u.%u",
  1049. FW_HDR_FW_VER_MAJOR_GET(adapter->params.dev.fwrev),
  1050. FW_HDR_FW_VER_MINOR_GET(adapter->params.dev.fwrev),
  1051. FW_HDR_FW_VER_MICRO_GET(adapter->params.dev.fwrev),
  1052. FW_HDR_FW_VER_BUILD_GET(adapter->params.dev.fwrev),
  1053. FW_HDR_FW_VER_MAJOR_GET(adapter->params.dev.tprev),
  1054. FW_HDR_FW_VER_MINOR_GET(adapter->params.dev.tprev),
  1055. FW_HDR_FW_VER_MICRO_GET(adapter->params.dev.tprev),
  1056. FW_HDR_FW_VER_BUILD_GET(adapter->params.dev.tprev));
  1057. }
  1058. /*
  1059. * Return current adapter message level.
  1060. */
  1061. static u32 cxgb4vf_get_msglevel(struct net_device *dev)
  1062. {
  1063. return netdev2adap(dev)->msg_enable;
  1064. }
  1065. /*
  1066. * Set current adapter message level.
  1067. */
  1068. static void cxgb4vf_set_msglevel(struct net_device *dev, u32 msglevel)
  1069. {
  1070. netdev2adap(dev)->msg_enable = msglevel;
  1071. }
  1072. /*
  1073. * Return the device's current Queue Set ring size parameters along with the
  1074. * allowed maximum values. Since ethtool doesn't understand the concept of
  1075. * multi-queue devices, we just return the current values associated with the
  1076. * first Queue Set.
  1077. */
  1078. static void cxgb4vf_get_ringparam(struct net_device *dev,
  1079. struct ethtool_ringparam *rp)
  1080. {
  1081. const struct port_info *pi = netdev_priv(dev);
  1082. const struct sge *s = &pi->adapter->sge;
  1083. rp->rx_max_pending = MAX_RX_BUFFERS;
  1084. rp->rx_mini_max_pending = MAX_RSPQ_ENTRIES;
  1085. rp->rx_jumbo_max_pending = 0;
  1086. rp->tx_max_pending = MAX_TXQ_ENTRIES;
  1087. rp->rx_pending = s->ethrxq[pi->first_qset].fl.size - MIN_FL_RESID;
  1088. rp->rx_mini_pending = s->ethrxq[pi->first_qset].rspq.size;
  1089. rp->rx_jumbo_pending = 0;
  1090. rp->tx_pending = s->ethtxq[pi->first_qset].q.size;
  1091. }
  1092. /*
  1093. * Set the Queue Set ring size parameters for the device. Again, since
  1094. * ethtool doesn't allow for the concept of multiple queues per device, we'll
  1095. * apply these new values across all of the Queue Sets associated with the
  1096. * device -- after vetting them of course!
  1097. */
  1098. static int cxgb4vf_set_ringparam(struct net_device *dev,
  1099. struct ethtool_ringparam *rp)
  1100. {
  1101. const struct port_info *pi = netdev_priv(dev);
  1102. struct adapter *adapter = pi->adapter;
  1103. struct sge *s = &adapter->sge;
  1104. int qs;
  1105. if (rp->rx_pending > MAX_RX_BUFFERS ||
  1106. rp->rx_jumbo_pending ||
  1107. rp->tx_pending > MAX_TXQ_ENTRIES ||
  1108. rp->rx_mini_pending > MAX_RSPQ_ENTRIES ||
  1109. rp->rx_mini_pending < MIN_RSPQ_ENTRIES ||
  1110. rp->rx_pending < MIN_FL_ENTRIES ||
  1111. rp->tx_pending < MIN_TXQ_ENTRIES)
  1112. return -EINVAL;
  1113. if (adapter->flags & FULL_INIT_DONE)
  1114. return -EBUSY;
  1115. for (qs = pi->first_qset; qs < pi->first_qset + pi->nqsets; qs++) {
  1116. s->ethrxq[qs].fl.size = rp->rx_pending + MIN_FL_RESID;
  1117. s->ethrxq[qs].rspq.size = rp->rx_mini_pending;
  1118. s->ethtxq[qs].q.size = rp->tx_pending;
  1119. }
  1120. return 0;
  1121. }
  1122. /*
  1123. * Return the interrupt holdoff timer and count for the first Queue Set on the
  1124. * device. Our extension ioctl() (the cxgbtool interface) allows the
  1125. * interrupt holdoff timer to be read on all of the device's Queue Sets.
  1126. */
  1127. static int cxgb4vf_get_coalesce(struct net_device *dev,
  1128. struct ethtool_coalesce *coalesce)
  1129. {
  1130. const struct port_info *pi = netdev_priv(dev);
  1131. const struct adapter *adapter = pi->adapter;
  1132. const struct sge_rspq *rspq = &adapter->sge.ethrxq[pi->first_qset].rspq;
  1133. coalesce->rx_coalesce_usecs = qtimer_val(adapter, rspq);
  1134. coalesce->rx_max_coalesced_frames =
  1135. ((rspq->intr_params & QINTR_CNT_EN)
  1136. ? adapter->sge.counter_val[rspq->pktcnt_idx]
  1137. : 0);
  1138. return 0;
  1139. }
  1140. /*
  1141. * Set the RX interrupt holdoff timer and count for the first Queue Set on the
  1142. * interface. Our extension ioctl() (the cxgbtool interface) allows us to set
  1143. * the interrupt holdoff timer on any of the device's Queue Sets.
  1144. */
  1145. static int cxgb4vf_set_coalesce(struct net_device *dev,
  1146. struct ethtool_coalesce *coalesce)
  1147. {
  1148. const struct port_info *pi = netdev_priv(dev);
  1149. struct adapter *adapter = pi->adapter;
  1150. return set_rxq_intr_params(adapter,
  1151. &adapter->sge.ethrxq[pi->first_qset].rspq,
  1152. coalesce->rx_coalesce_usecs,
  1153. coalesce->rx_max_coalesced_frames);
  1154. }
  1155. /*
  1156. * Report current port link pause parameter settings.
  1157. */
  1158. static void cxgb4vf_get_pauseparam(struct net_device *dev,
  1159. struct ethtool_pauseparam *pauseparam)
  1160. {
  1161. struct port_info *pi = netdev_priv(dev);
  1162. pauseparam->autoneg = (pi->link_cfg.requested_fc & PAUSE_AUTONEG) != 0;
  1163. pauseparam->rx_pause = (pi->link_cfg.fc & PAUSE_RX) != 0;
  1164. pauseparam->tx_pause = (pi->link_cfg.fc & PAUSE_TX) != 0;
  1165. }
  1166. /*
  1167. * Return whether RX Checksum Offloading is currently enabled for the device.
  1168. */
  1169. static u32 cxgb4vf_get_rx_csum(struct net_device *dev)
  1170. {
  1171. struct port_info *pi = netdev_priv(dev);
  1172. return (pi->rx_offload & RX_CSO) != 0;
  1173. }
  1174. /*
  1175. * Turn RX Checksum Offloading on or off for the device.
  1176. */
  1177. static int cxgb4vf_set_rx_csum(struct net_device *dev, u32 csum)
  1178. {
  1179. struct port_info *pi = netdev_priv(dev);
  1180. if (csum)
  1181. pi->rx_offload |= RX_CSO;
  1182. else
  1183. pi->rx_offload &= ~RX_CSO;
  1184. return 0;
  1185. }
  1186. /*
  1187. * Identify the port by blinking the port's LED.
  1188. */
  1189. static int cxgb4vf_phys_id(struct net_device *dev, u32 id)
  1190. {
  1191. struct port_info *pi = netdev_priv(dev);
  1192. return t4vf_identify_port(pi->adapter, pi->viid, 5);
  1193. }
  1194. /*
  1195. * Port stats maintained per queue of the port.
  1196. */
  1197. struct queue_port_stats {
  1198. u64 tso;
  1199. u64 tx_csum;
  1200. u64 rx_csum;
  1201. u64 vlan_ex;
  1202. u64 vlan_ins;
  1203. u64 lro_pkts;
  1204. u64 lro_merged;
  1205. };
  1206. /*
  1207. * Strings for the ETH_SS_STATS statistics set ("ethtool -S"). Note that
  1208. * these need to match the order of statistics returned by
  1209. * t4vf_get_port_stats().
  1210. */
  1211. static const char stats_strings[][ETH_GSTRING_LEN] = {
  1212. /*
  1213. * These must match the layout of the t4vf_port_stats structure.
  1214. */
  1215. "TxBroadcastBytes ",
  1216. "TxBroadcastFrames ",
  1217. "TxMulticastBytes ",
  1218. "TxMulticastFrames ",
  1219. "TxUnicastBytes ",
  1220. "TxUnicastFrames ",
  1221. "TxDroppedFrames ",
  1222. "TxOffloadBytes ",
  1223. "TxOffloadFrames ",
  1224. "RxBroadcastBytes ",
  1225. "RxBroadcastFrames ",
  1226. "RxMulticastBytes ",
  1227. "RxMulticastFrames ",
  1228. "RxUnicastBytes ",
  1229. "RxUnicastFrames ",
  1230. "RxErrorFrames ",
  1231. /*
  1232. * These are accumulated per-queue statistics and must match the
  1233. * order of the fields in the queue_port_stats structure.
  1234. */
  1235. "TSO ",
  1236. "TxCsumOffload ",
  1237. "RxCsumGood ",
  1238. "VLANextractions ",
  1239. "VLANinsertions ",
  1240. "GROPackets ",
  1241. "GROMerged ",
  1242. };
  1243. /*
  1244. * Return the number of statistics in the specified statistics set.
  1245. */
  1246. static int cxgb4vf_get_sset_count(struct net_device *dev, int sset)
  1247. {
  1248. switch (sset) {
  1249. case ETH_SS_STATS:
  1250. return ARRAY_SIZE(stats_strings);
  1251. default:
  1252. return -EOPNOTSUPP;
  1253. }
  1254. /*NOTREACHED*/
  1255. }
  1256. /*
  1257. * Return the strings for the specified statistics set.
  1258. */
  1259. static void cxgb4vf_get_strings(struct net_device *dev,
  1260. u32 sset,
  1261. u8 *data)
  1262. {
  1263. switch (sset) {
  1264. case ETH_SS_STATS:
  1265. memcpy(data, stats_strings, sizeof(stats_strings));
  1266. break;
  1267. }
  1268. }
  1269. /*
  1270. * Small utility routine to accumulate queue statistics across the queues of
  1271. * a "port".
  1272. */
  1273. static void collect_sge_port_stats(const struct adapter *adapter,
  1274. const struct port_info *pi,
  1275. struct queue_port_stats *stats)
  1276. {
  1277. const struct sge_eth_txq *txq = &adapter->sge.ethtxq[pi->first_qset];
  1278. const struct sge_eth_rxq *rxq = &adapter->sge.ethrxq[pi->first_qset];
  1279. int qs;
  1280. memset(stats, 0, sizeof(*stats));
  1281. for (qs = 0; qs < pi->nqsets; qs++, rxq++, txq++) {
  1282. stats->tso += txq->tso;
  1283. stats->tx_csum += txq->tx_cso;
  1284. stats->rx_csum += rxq->stats.rx_cso;
  1285. stats->vlan_ex += rxq->stats.vlan_ex;
  1286. stats->vlan_ins += txq->vlan_ins;
  1287. stats->lro_pkts += rxq->stats.lro_pkts;
  1288. stats->lro_merged += rxq->stats.lro_merged;
  1289. }
  1290. }
  1291. /*
  1292. * Return the ETH_SS_STATS statistics set.
  1293. */
  1294. static void cxgb4vf_get_ethtool_stats(struct net_device *dev,
  1295. struct ethtool_stats *stats,
  1296. u64 *data)
  1297. {
  1298. struct port_info *pi = netdev2pinfo(dev);
  1299. struct adapter *adapter = pi->adapter;
  1300. int err = t4vf_get_port_stats(adapter, pi->pidx,
  1301. (struct t4vf_port_stats *)data);
  1302. if (err)
  1303. memset(data, 0, sizeof(struct t4vf_port_stats));
  1304. data += sizeof(struct t4vf_port_stats) / sizeof(u64);
  1305. collect_sge_port_stats(adapter, pi, (struct queue_port_stats *)data);
  1306. }
  1307. /*
  1308. * Return the size of our register map.
  1309. */
  1310. static int cxgb4vf_get_regs_len(struct net_device *dev)
  1311. {
  1312. return T4VF_REGMAP_SIZE;
  1313. }
  1314. /*
  1315. * Dump a block of registers, start to end inclusive, into a buffer.
  1316. */
  1317. static void reg_block_dump(struct adapter *adapter, void *regbuf,
  1318. unsigned int start, unsigned int end)
  1319. {
  1320. u32 *bp = regbuf + start - T4VF_REGMAP_START;
  1321. for ( ; start <= end; start += sizeof(u32)) {
  1322. /*
  1323. * Avoid reading the Mailbox Control register since that
  1324. * can trigger a Mailbox Ownership Arbitration cycle and
  1325. * interfere with communication with the firmware.
  1326. */
  1327. if (start == T4VF_CIM_BASE_ADDR + CIM_VF_EXT_MAILBOX_CTRL)
  1328. *bp++ = 0xffff;
  1329. else
  1330. *bp++ = t4_read_reg(adapter, start);
  1331. }
  1332. }
  1333. /*
  1334. * Copy our entire register map into the provided buffer.
  1335. */
  1336. static void cxgb4vf_get_regs(struct net_device *dev,
  1337. struct ethtool_regs *regs,
  1338. void *regbuf)
  1339. {
  1340. struct adapter *adapter = netdev2adap(dev);
  1341. regs->version = mk_adap_vers(adapter);
  1342. /*
  1343. * Fill in register buffer with our register map.
  1344. */
  1345. memset(regbuf, 0, T4VF_REGMAP_SIZE);
  1346. reg_block_dump(adapter, regbuf,
  1347. T4VF_SGE_BASE_ADDR + T4VF_MOD_MAP_SGE_FIRST,
  1348. T4VF_SGE_BASE_ADDR + T4VF_MOD_MAP_SGE_LAST);
  1349. reg_block_dump(adapter, regbuf,
  1350. T4VF_MPS_BASE_ADDR + T4VF_MOD_MAP_MPS_FIRST,
  1351. T4VF_MPS_BASE_ADDR + T4VF_MOD_MAP_MPS_LAST);
  1352. reg_block_dump(adapter, regbuf,
  1353. T4VF_PL_BASE_ADDR + T4VF_MOD_MAP_PL_FIRST,
  1354. T4VF_PL_BASE_ADDR + T4VF_MOD_MAP_PL_LAST);
  1355. reg_block_dump(adapter, regbuf,
  1356. T4VF_CIM_BASE_ADDR + T4VF_MOD_MAP_CIM_FIRST,
  1357. T4VF_CIM_BASE_ADDR + T4VF_MOD_MAP_CIM_LAST);
  1358. reg_block_dump(adapter, regbuf,
  1359. T4VF_MBDATA_BASE_ADDR + T4VF_MBDATA_FIRST,
  1360. T4VF_MBDATA_BASE_ADDR + T4VF_MBDATA_LAST);
  1361. }
  1362. /*
  1363. * Report current Wake On LAN settings.
  1364. */
  1365. static void cxgb4vf_get_wol(struct net_device *dev,
  1366. struct ethtool_wolinfo *wol)
  1367. {
  1368. wol->supported = 0;
  1369. wol->wolopts = 0;
  1370. memset(&wol->sopass, 0, sizeof(wol->sopass));
  1371. }
  1372. /*
  1373. * TCP Segmentation Offload flags which we support.
  1374. */
  1375. #define TSO_FLAGS (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN)
  1376. /*
  1377. * Set TCP Segmentation Offloading feature capabilities.
  1378. */
  1379. static int cxgb4vf_set_tso(struct net_device *dev, u32 tso)
  1380. {
  1381. if (tso)
  1382. dev->features |= TSO_FLAGS;
  1383. else
  1384. dev->features &= ~TSO_FLAGS;
  1385. return 0;
  1386. }
  1387. static struct ethtool_ops cxgb4vf_ethtool_ops = {
  1388. .get_settings = cxgb4vf_get_settings,
  1389. .get_drvinfo = cxgb4vf_get_drvinfo,
  1390. .get_msglevel = cxgb4vf_get_msglevel,
  1391. .set_msglevel = cxgb4vf_set_msglevel,
  1392. .get_ringparam = cxgb4vf_get_ringparam,
  1393. .set_ringparam = cxgb4vf_set_ringparam,
  1394. .get_coalesce = cxgb4vf_get_coalesce,
  1395. .set_coalesce = cxgb4vf_set_coalesce,
  1396. .get_pauseparam = cxgb4vf_get_pauseparam,
  1397. .get_rx_csum = cxgb4vf_get_rx_csum,
  1398. .set_rx_csum = cxgb4vf_set_rx_csum,
  1399. .set_tx_csum = ethtool_op_set_tx_ipv6_csum,
  1400. .set_sg = ethtool_op_set_sg,
  1401. .get_link = ethtool_op_get_link,
  1402. .get_strings = cxgb4vf_get_strings,
  1403. .phys_id = cxgb4vf_phys_id,
  1404. .get_sset_count = cxgb4vf_get_sset_count,
  1405. .get_ethtool_stats = cxgb4vf_get_ethtool_stats,
  1406. .get_regs_len = cxgb4vf_get_regs_len,
  1407. .get_regs = cxgb4vf_get_regs,
  1408. .get_wol = cxgb4vf_get_wol,
  1409. .set_tso = cxgb4vf_set_tso,
  1410. };
  1411. /*
  1412. * /sys/kernel/debug/cxgb4vf support code and data.
  1413. * ================================================
  1414. */
  1415. /*
  1416. * Show SGE Queue Set information. We display QPL Queues Sets per line.
  1417. */
  1418. #define QPL 4
  1419. static int sge_qinfo_show(struct seq_file *seq, void *v)
  1420. {
  1421. struct adapter *adapter = seq->private;
  1422. int eth_entries = DIV_ROUND_UP(adapter->sge.ethqsets, QPL);
  1423. int qs, r = (uintptr_t)v - 1;
  1424. if (r)
  1425. seq_putc(seq, '\n');
  1426. #define S3(fmt_spec, s, v) \
  1427. do {\
  1428. seq_printf(seq, "%-12s", s); \
  1429. for (qs = 0; qs < n; ++qs) \
  1430. seq_printf(seq, " %16" fmt_spec, v); \
  1431. seq_putc(seq, '\n'); \
  1432. } while (0)
  1433. #define S(s, v) S3("s", s, v)
  1434. #define T(s, v) S3("u", s, txq[qs].v)
  1435. #define R(s, v) S3("u", s, rxq[qs].v)
  1436. if (r < eth_entries) {
  1437. const struct sge_eth_rxq *rxq = &adapter->sge.ethrxq[r * QPL];
  1438. const struct sge_eth_txq *txq = &adapter->sge.ethtxq[r * QPL];
  1439. int n = min(QPL, adapter->sge.ethqsets - QPL * r);
  1440. S("QType:", "Ethernet");
  1441. S("Interface:",
  1442. (rxq[qs].rspq.netdev
  1443. ? rxq[qs].rspq.netdev->name
  1444. : "N/A"));
  1445. S3("d", "Port:",
  1446. (rxq[qs].rspq.netdev
  1447. ? ((struct port_info *)
  1448. netdev_priv(rxq[qs].rspq.netdev))->port_id
  1449. : -1));
  1450. T("TxQ ID:", q.abs_id);
  1451. T("TxQ size:", q.size);
  1452. T("TxQ inuse:", q.in_use);
  1453. T("TxQ PIdx:", q.pidx);
  1454. T("TxQ CIdx:", q.cidx);
  1455. R("RspQ ID:", rspq.abs_id);
  1456. R("RspQ size:", rspq.size);
  1457. R("RspQE size:", rspq.iqe_len);
  1458. S3("u", "Intr delay:", qtimer_val(adapter, &rxq[qs].rspq));
  1459. S3("u", "Intr pktcnt:",
  1460. adapter->sge.counter_val[rxq[qs].rspq.pktcnt_idx]);
  1461. R("RspQ CIdx:", rspq.cidx);
  1462. R("RspQ Gen:", rspq.gen);
  1463. R("FL ID:", fl.abs_id);
  1464. R("FL size:", fl.size - MIN_FL_RESID);
  1465. R("FL avail:", fl.avail);
  1466. R("FL PIdx:", fl.pidx);
  1467. R("FL CIdx:", fl.cidx);
  1468. return 0;
  1469. }
  1470. r -= eth_entries;
  1471. if (r == 0) {
  1472. const struct sge_rspq *evtq = &adapter->sge.fw_evtq;
  1473. seq_printf(seq, "%-12s %16s\n", "QType:", "FW event queue");
  1474. seq_printf(seq, "%-12s %16u\n", "RspQ ID:", evtq->abs_id);
  1475. seq_printf(seq, "%-12s %16u\n", "Intr delay:",
  1476. qtimer_val(adapter, evtq));
  1477. seq_printf(seq, "%-12s %16u\n", "Intr pktcnt:",
  1478. adapter->sge.counter_val[evtq->pktcnt_idx]);
  1479. seq_printf(seq, "%-12s %16u\n", "RspQ Cidx:", evtq->cidx);
  1480. seq_printf(seq, "%-12s %16u\n", "RspQ Gen:", evtq->gen);
  1481. } else if (r == 1) {
  1482. const struct sge_rspq *intrq = &adapter->sge.intrq;
  1483. seq_printf(seq, "%-12s %16s\n", "QType:", "Interrupt Queue");
  1484. seq_printf(seq, "%-12s %16u\n", "RspQ ID:", intrq->abs_id);
  1485. seq_printf(seq, "%-12s %16u\n", "Intr delay:",
  1486. qtimer_val(adapter, intrq));
  1487. seq_printf(seq, "%-12s %16u\n", "Intr pktcnt:",
  1488. adapter->sge.counter_val[intrq->pktcnt_idx]);
  1489. seq_printf(seq, "%-12s %16u\n", "RspQ Cidx:", intrq->cidx);
  1490. seq_printf(seq, "%-12s %16u\n", "RspQ Gen:", intrq->gen);
  1491. }
  1492. #undef R
  1493. #undef T
  1494. #undef S
  1495. #undef S3
  1496. return 0;
  1497. }
  1498. /*
  1499. * Return the number of "entries" in our "file". We group the multi-Queue
  1500. * sections with QPL Queue Sets per "entry". The sections of the output are:
  1501. *
  1502. * Ethernet RX/TX Queue Sets
  1503. * Firmware Event Queue
  1504. * Forwarded Interrupt Queue (if in MSI mode)
  1505. */
  1506. static int sge_queue_entries(const struct adapter *adapter)
  1507. {
  1508. return DIV_ROUND_UP(adapter->sge.ethqsets, QPL) + 1 +
  1509. ((adapter->flags & USING_MSI) != 0);
  1510. }
  1511. static void *sge_queue_start(struct seq_file *seq, loff_t *pos)
  1512. {
  1513. int entries = sge_queue_entries(seq->private);
  1514. return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
  1515. }
  1516. static void sge_queue_stop(struct seq_file *seq, void *v)
  1517. {
  1518. }
  1519. static void *sge_queue_next(struct seq_file *seq, void *v, loff_t *pos)
  1520. {
  1521. int entries = sge_queue_entries(seq->private);
  1522. ++*pos;
  1523. return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
  1524. }
  1525. static const struct seq_operations sge_qinfo_seq_ops = {
  1526. .start = sge_queue_start,
  1527. .next = sge_queue_next,
  1528. .stop = sge_queue_stop,
  1529. .show = sge_qinfo_show
  1530. };
  1531. static int sge_qinfo_open(struct inode *inode, struct file *file)
  1532. {
  1533. int res = seq_open(file, &sge_qinfo_seq_ops);
  1534. if (!res) {
  1535. struct seq_file *seq = file->private_data;
  1536. seq->private = inode->i_private;
  1537. }
  1538. return res;
  1539. }
  1540. static const struct file_operations sge_qinfo_debugfs_fops = {
  1541. .owner = THIS_MODULE,
  1542. .open = sge_qinfo_open,
  1543. .read = seq_read,
  1544. .llseek = seq_lseek,
  1545. .release = seq_release,
  1546. };
  1547. /*
  1548. * Show SGE Queue Set statistics. We display QPL Queues Sets per line.
  1549. */
  1550. #define QPL 4
  1551. static int sge_qstats_show(struct seq_file *seq, void *v)
  1552. {
  1553. struct adapter *adapter = seq->private;
  1554. int eth_entries = DIV_ROUND_UP(adapter->sge.ethqsets, QPL);
  1555. int qs, r = (uintptr_t)v - 1;
  1556. if (r)
  1557. seq_putc(seq, '\n');
  1558. #define S3(fmt, s, v) \
  1559. do { \
  1560. seq_printf(seq, "%-16s", s); \
  1561. for (qs = 0; qs < n; ++qs) \
  1562. seq_printf(seq, " %8" fmt, v); \
  1563. seq_putc(seq, '\n'); \
  1564. } while (0)
  1565. #define S(s, v) S3("s", s, v)
  1566. #define T3(fmt, s, v) S3(fmt, s, txq[qs].v)
  1567. #define T(s, v) T3("lu", s, v)
  1568. #define R3(fmt, s, v) S3(fmt, s, rxq[qs].v)
  1569. #define R(s, v) R3("lu", s, v)
  1570. if (r < eth_entries) {
  1571. const struct sge_eth_rxq *rxq = &adapter->sge.ethrxq[r * QPL];
  1572. const struct sge_eth_txq *txq = &adapter->sge.ethtxq[r * QPL];
  1573. int n = min(QPL, adapter->sge.ethqsets - QPL * r);
  1574. S("QType:", "Ethernet");
  1575. S("Interface:",
  1576. (rxq[qs].rspq.netdev
  1577. ? rxq[qs].rspq.netdev->name
  1578. : "N/A"));
  1579. R3("u", "RspQNullInts:", rspq.unhandled_irqs);
  1580. R("RxPackets:", stats.pkts);
  1581. R("RxCSO:", stats.rx_cso);
  1582. R("VLANxtract:", stats.vlan_ex);
  1583. R("LROmerged:", stats.lro_merged);
  1584. R("LROpackets:", stats.lro_pkts);
  1585. R("RxDrops:", stats.rx_drops);
  1586. T("TSO:", tso);
  1587. T("TxCSO:", tx_cso);
  1588. T("VLANins:", vlan_ins);
  1589. T("TxQFull:", q.stops);
  1590. T("TxQRestarts:", q.restarts);
  1591. T("TxMapErr:", mapping_err);
  1592. R("FLAllocErr:", fl.alloc_failed);
  1593. R("FLLrgAlcErr:", fl.large_alloc_failed);
  1594. R("FLStarving:", fl.starving);
  1595. return 0;
  1596. }
  1597. r -= eth_entries;
  1598. if (r == 0) {
  1599. const struct sge_rspq *evtq = &adapter->sge.fw_evtq;
  1600. seq_printf(seq, "%-8s %16s\n", "QType:", "FW event queue");
  1601. seq_printf(seq, "%-16s %8u\n", "RspQNullInts:",
  1602. evtq->unhandled_irqs);
  1603. seq_printf(seq, "%-16s %8u\n", "RspQ CIdx:", evtq->cidx);
  1604. seq_printf(seq, "%-16s %8u\n", "RspQ Gen:", evtq->gen);
  1605. } else if (r == 1) {
  1606. const struct sge_rspq *intrq = &adapter->sge.intrq;
  1607. seq_printf(seq, "%-8s %16s\n", "QType:", "Interrupt Queue");
  1608. seq_printf(seq, "%-16s %8u\n", "RspQNullInts:",
  1609. intrq->unhandled_irqs);
  1610. seq_printf(seq, "%-16s %8u\n", "RspQ CIdx:", intrq->cidx);
  1611. seq_printf(seq, "%-16s %8u\n", "RspQ Gen:", intrq->gen);
  1612. }
  1613. #undef R
  1614. #undef T
  1615. #undef S
  1616. #undef R3
  1617. #undef T3
  1618. #undef S3
  1619. return 0;
  1620. }
  1621. /*
  1622. * Return the number of "entries" in our "file". We group the multi-Queue
  1623. * sections with QPL Queue Sets per "entry". The sections of the output are:
  1624. *
  1625. * Ethernet RX/TX Queue Sets
  1626. * Firmware Event Queue
  1627. * Forwarded Interrupt Queue (if in MSI mode)
  1628. */
  1629. static int sge_qstats_entries(const struct adapter *adapter)
  1630. {
  1631. return DIV_ROUND_UP(adapter->sge.ethqsets, QPL) + 1 +
  1632. ((adapter->flags & USING_MSI) != 0);
  1633. }
  1634. static void *sge_qstats_start(struct seq_file *seq, loff_t *pos)
  1635. {
  1636. int entries = sge_qstats_entries(seq->private);
  1637. return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
  1638. }
  1639. static void sge_qstats_stop(struct seq_file *seq, void *v)
  1640. {
  1641. }
  1642. static void *sge_qstats_next(struct seq_file *seq, void *v, loff_t *pos)
  1643. {
  1644. int entries = sge_qstats_entries(seq->private);
  1645. (*pos)++;
  1646. return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
  1647. }
  1648. static const struct seq_operations sge_qstats_seq_ops = {
  1649. .start = sge_qstats_start,
  1650. .next = sge_qstats_next,
  1651. .stop = sge_qstats_stop,
  1652. .show = sge_qstats_show
  1653. };
  1654. static int sge_qstats_open(struct inode *inode, struct file *file)
  1655. {
  1656. int res = seq_open(file, &sge_qstats_seq_ops);
  1657. if (res == 0) {
  1658. struct seq_file *seq = file->private_data;
  1659. seq->private = inode->i_private;
  1660. }
  1661. return res;
  1662. }
  1663. static const struct file_operations sge_qstats_proc_fops = {
  1664. .owner = THIS_MODULE,
  1665. .open = sge_qstats_open,
  1666. .read = seq_read,
  1667. .llseek = seq_lseek,
  1668. .release = seq_release,
  1669. };
  1670. /*
  1671. * Show PCI-E SR-IOV Virtual Function Resource Limits.
  1672. */
  1673. static int resources_show(struct seq_file *seq, void *v)
  1674. {
  1675. struct adapter *adapter = seq->private;
  1676. struct vf_resources *vfres = &adapter->params.vfres;
  1677. #define S(desc, fmt, var) \
  1678. seq_printf(seq, "%-60s " fmt "\n", \
  1679. desc " (" #var "):", vfres->var)
  1680. S("Virtual Interfaces", "%d", nvi);
  1681. S("Egress Queues", "%d", neq);
  1682. S("Ethernet Control", "%d", nethctrl);
  1683. S("Ingress Queues/w Free Lists/Interrupts", "%d", niqflint);
  1684. S("Ingress Queues", "%d", niq);
  1685. S("Traffic Class", "%d", tc);
  1686. S("Port Access Rights Mask", "%#x", pmask);
  1687. S("MAC Address Filters", "%d", nexactf);
  1688. S("Firmware Command Read Capabilities", "%#x", r_caps);
  1689. S("Firmware Command Write/Execute Capabilities", "%#x", wx_caps);
  1690. #undef S
  1691. return 0;
  1692. }
  1693. static int resources_open(struct inode *inode, struct file *file)
  1694. {
  1695. return single_open(file, resources_show, inode->i_private);
  1696. }
  1697. static const struct file_operations resources_proc_fops = {
  1698. .owner = THIS_MODULE,
  1699. .open = resources_open,
  1700. .read = seq_read,
  1701. .llseek = seq_lseek,
  1702. .release = single_release,
  1703. };
  1704. /*
  1705. * Show Virtual Interfaces.
  1706. */
  1707. static int interfaces_show(struct seq_file *seq, void *v)
  1708. {
  1709. if (v == SEQ_START_TOKEN) {
  1710. seq_puts(seq, "Interface Port VIID\n");
  1711. } else {
  1712. struct adapter *adapter = seq->private;
  1713. int pidx = (uintptr_t)v - 2;
  1714. struct net_device *dev = adapter->port[pidx];
  1715. struct port_info *pi = netdev_priv(dev);
  1716. seq_printf(seq, "%9s %4d %#5x\n",
  1717. dev->name, pi->port_id, pi->viid);
  1718. }
  1719. return 0;
  1720. }
  1721. static inline void *interfaces_get_idx(struct adapter *adapter, loff_t pos)
  1722. {
  1723. return pos <= adapter->params.nports
  1724. ? (void *)(uintptr_t)(pos + 1)
  1725. : NULL;
  1726. }
  1727. static void *interfaces_start(struct seq_file *seq, loff_t *pos)
  1728. {
  1729. return *pos
  1730. ? interfaces_get_idx(seq->private, *pos)
  1731. : SEQ_START_TOKEN;
  1732. }
  1733. static void *interfaces_next(struct seq_file *seq, void *v, loff_t *pos)
  1734. {
  1735. (*pos)++;
  1736. return interfaces_get_idx(seq->private, *pos);
  1737. }
  1738. static void interfaces_stop(struct seq_file *seq, void *v)
  1739. {
  1740. }
  1741. static const struct seq_operations interfaces_seq_ops = {
  1742. .start = interfaces_start,
  1743. .next = interfaces_next,
  1744. .stop = interfaces_stop,
  1745. .show = interfaces_show
  1746. };
  1747. static int interfaces_open(struct inode *inode, struct file *file)
  1748. {
  1749. int res = seq_open(file, &interfaces_seq_ops);
  1750. if (res == 0) {
  1751. struct seq_file *seq = file->private_data;
  1752. seq->private = inode->i_private;
  1753. }
  1754. return res;
  1755. }
  1756. static const struct file_operations interfaces_proc_fops = {
  1757. .owner = THIS_MODULE,
  1758. .open = interfaces_open,
  1759. .read = seq_read,
  1760. .llseek = seq_lseek,
  1761. .release = seq_release,
  1762. };
  1763. /*
  1764. * /sys/kernel/debugfs/cxgb4vf/ files list.
  1765. */
  1766. struct cxgb4vf_debugfs_entry {
  1767. const char *name; /* name of debugfs node */
  1768. mode_t mode; /* file system mode */
  1769. const struct file_operations *fops;
  1770. };
  1771. static struct cxgb4vf_debugfs_entry debugfs_files[] = {
  1772. { "sge_qinfo", S_IRUGO, &sge_qinfo_debugfs_fops },
  1773. { "sge_qstats", S_IRUGO, &sge_qstats_proc_fops },
  1774. { "resources", S_IRUGO, &resources_proc_fops },
  1775. { "interfaces", S_IRUGO, &interfaces_proc_fops },
  1776. };
  1777. /*
  1778. * Module and device initialization and cleanup code.
  1779. * ==================================================
  1780. */
  1781. /*
  1782. * Set up out /sys/kernel/debug/cxgb4vf sub-nodes. We assume that the
  1783. * directory (debugfs_root) has already been set up.
  1784. */
  1785. static int __devinit setup_debugfs(struct adapter *adapter)
  1786. {
  1787. int i;
  1788. BUG_ON(IS_ERR_OR_NULL(adapter->debugfs_root));
  1789. /*
  1790. * Debugfs support is best effort.
  1791. */
  1792. for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
  1793. (void)debugfs_create_file(debugfs_files[i].name,
  1794. debugfs_files[i].mode,
  1795. adapter->debugfs_root,
  1796. (void *)adapter,
  1797. debugfs_files[i].fops);
  1798. return 0;
  1799. }
  1800. /*
  1801. * Tear down the /sys/kernel/debug/cxgb4vf sub-nodes created above. We leave
  1802. * it to our caller to tear down the directory (debugfs_root).
  1803. */
  1804. static void cleanup_debugfs(struct adapter *adapter)
  1805. {
  1806. BUG_ON(IS_ERR_OR_NULL(adapter->debugfs_root));
  1807. /*
  1808. * Unlike our sister routine cleanup_proc(), we don't need to remove
  1809. * individual entries because a call will be made to
  1810. * debugfs_remove_recursive(). We just need to clean up any ancillary
  1811. * persistent state.
  1812. */
  1813. /* nothing to do */
  1814. }
  1815. /*
  1816. * Perform early "adapter" initialization. This is where we discover what
  1817. * adapter parameters we're going to be using and initialize basic adapter
  1818. * hardware support.
  1819. */
  1820. static int __devinit adap_init0(struct adapter *adapter)
  1821. {
  1822. struct vf_resources *vfres = &adapter->params.vfres;
  1823. struct sge_params *sge_params = &adapter->params.sge;
  1824. struct sge *s = &adapter->sge;
  1825. unsigned int ethqsets;
  1826. int err;
  1827. /*
  1828. * Wait for the device to become ready before proceeding ...
  1829. */
  1830. err = t4vf_wait_dev_ready(adapter);
  1831. if (err) {
  1832. dev_err(adapter->pdev_dev, "device didn't become ready:"
  1833. " err=%d\n", err);
  1834. return err;
  1835. }
  1836. /*
  1837. * Some environments do not properly handle PCIE FLRs -- e.g. in Linux
  1838. * 2.6.31 and later we can't call pci_reset_function() in order to
  1839. * issue an FLR because of a self- deadlock on the device semaphore.
  1840. * Meanwhile, the OS infrastructure doesn't issue FLRs in all the
  1841. * cases where they're needed -- for instance, some versions of KVM
  1842. * fail to reset "Assigned Devices" when the VM reboots. Therefore we
  1843. * use the firmware based reset in order to reset any per function
  1844. * state.
  1845. */
  1846. err = t4vf_fw_reset(adapter);
  1847. if (err < 0) {
  1848. dev_err(adapter->pdev_dev, "FW reset failed: err=%d\n", err);
  1849. return err;
  1850. }
  1851. /*
  1852. * Grab basic operational parameters. These will predominantly have
  1853. * been set up by the Physical Function Driver or will be hard coded
  1854. * into the adapter. We just have to live with them ... Note that
  1855. * we _must_ get our VPD parameters before our SGE parameters because
  1856. * we need to know the adapter's core clock from the VPD in order to
  1857. * properly decode the SGE Timer Values.
  1858. */
  1859. err = t4vf_get_dev_params(adapter);
  1860. if (err) {
  1861. dev_err(adapter->pdev_dev, "unable to retrieve adapter"
  1862. " device parameters: err=%d\n", err);
  1863. return err;
  1864. }
  1865. err = t4vf_get_vpd_params(adapter);
  1866. if (err) {
  1867. dev_err(adapter->pdev_dev, "unable to retrieve adapter"
  1868. " VPD parameters: err=%d\n", err);
  1869. return err;
  1870. }
  1871. err = t4vf_get_sge_params(adapter);
  1872. if (err) {
  1873. dev_err(adapter->pdev_dev, "unable to retrieve adapter"
  1874. " SGE parameters: err=%d\n", err);
  1875. return err;
  1876. }
  1877. err = t4vf_get_rss_glb_config(adapter);
  1878. if (err) {
  1879. dev_err(adapter->pdev_dev, "unable to retrieve adapter"
  1880. " RSS parameters: err=%d\n", err);
  1881. return err;
  1882. }
  1883. if (adapter->params.rss.mode !=
  1884. FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL) {
  1885. dev_err(adapter->pdev_dev, "unable to operate with global RSS"
  1886. " mode %d\n", adapter->params.rss.mode);
  1887. return -EINVAL;
  1888. }
  1889. err = t4vf_sge_init(adapter);
  1890. if (err) {
  1891. dev_err(adapter->pdev_dev, "unable to use adapter parameters:"
  1892. " err=%d\n", err);
  1893. return err;
  1894. }
  1895. /*
  1896. * Retrieve our RX interrupt holdoff timer values and counter
  1897. * threshold values from the SGE parameters.
  1898. */
  1899. s->timer_val[0] = core_ticks_to_us(adapter,
  1900. TIMERVALUE0_GET(sge_params->sge_timer_value_0_and_1));
  1901. s->timer_val[1] = core_ticks_to_us(adapter,
  1902. TIMERVALUE1_GET(sge_params->sge_timer_value_0_and_1));
  1903. s->timer_val[2] = core_ticks_to_us(adapter,
  1904. TIMERVALUE0_GET(sge_params->sge_timer_value_2_and_3));
  1905. s->timer_val[3] = core_ticks_to_us(adapter,
  1906. TIMERVALUE1_GET(sge_params->sge_timer_value_2_and_3));
  1907. s->timer_val[4] = core_ticks_to_us(adapter,
  1908. TIMERVALUE0_GET(sge_params->sge_timer_value_4_and_5));
  1909. s->timer_val[5] = core_ticks_to_us(adapter,
  1910. TIMERVALUE1_GET(sge_params->sge_timer_value_4_and_5));
  1911. s->counter_val[0] =
  1912. THRESHOLD_0_GET(sge_params->sge_ingress_rx_threshold);
  1913. s->counter_val[1] =
  1914. THRESHOLD_1_GET(sge_params->sge_ingress_rx_threshold);
  1915. s->counter_val[2] =
  1916. THRESHOLD_2_GET(sge_params->sge_ingress_rx_threshold);
  1917. s->counter_val[3] =
  1918. THRESHOLD_3_GET(sge_params->sge_ingress_rx_threshold);
  1919. /*
  1920. * Grab our Virtual Interface resource allocation, extract the
  1921. * features that we're interested in and do a bit of sanity testing on
  1922. * what we discover.
  1923. */
  1924. err = t4vf_get_vfres(adapter);
  1925. if (err) {
  1926. dev_err(adapter->pdev_dev, "unable to get virtual interface"
  1927. " resources: err=%d\n", err);
  1928. return err;
  1929. }
  1930. /*
  1931. * The number of "ports" which we support is equal to the number of
  1932. * Virtual Interfaces with which we've been provisioned.
  1933. */
  1934. adapter->params.nports = vfres->nvi;
  1935. if (adapter->params.nports > MAX_NPORTS) {
  1936. dev_warn(adapter->pdev_dev, "only using %d of %d allowed"
  1937. " virtual interfaces\n", MAX_NPORTS,
  1938. adapter->params.nports);
  1939. adapter->params.nports = MAX_NPORTS;
  1940. }
  1941. /*
  1942. * We need to reserve a number of the ingress queues with Free List
  1943. * and Interrupt capabilities for special interrupt purposes (like
  1944. * asynchronous firmware messages, or forwarded interrupts if we're
  1945. * using MSI). The rest of the FL/Intr-capable ingress queues will be
  1946. * matched up one-for-one with Ethernet/Control egress queues in order
  1947. * to form "Queue Sets" which will be aportioned between the "ports".
  1948. * For each Queue Set, we'll need the ability to allocate two Egress
  1949. * Contexts -- one for the Ingress Queue Free List and one for the TX
  1950. * Ethernet Queue.
  1951. */
  1952. ethqsets = vfres->niqflint - INGQ_EXTRAS;
  1953. if (vfres->nethctrl != ethqsets) {
  1954. dev_warn(adapter->pdev_dev, "unequal number of [available]"
  1955. " ingress/egress queues (%d/%d); using minimum for"
  1956. " number of Queue Sets\n", ethqsets, vfres->nethctrl);
  1957. ethqsets = min(vfres->nethctrl, ethqsets);
  1958. }
  1959. if (vfres->neq < ethqsets*2) {
  1960. dev_warn(adapter->pdev_dev, "Not enough Egress Contexts (%d)"
  1961. " to support Queue Sets (%d); reducing allowed Queue"
  1962. " Sets\n", vfres->neq, ethqsets);
  1963. ethqsets = vfres->neq/2;
  1964. }
  1965. if (ethqsets > MAX_ETH_QSETS) {
  1966. dev_warn(adapter->pdev_dev, "only using %d of %d allowed Queue"
  1967. " Sets\n", MAX_ETH_QSETS, adapter->sge.max_ethqsets);
  1968. ethqsets = MAX_ETH_QSETS;
  1969. }
  1970. if (vfres->niq != 0 || vfres->neq > ethqsets*2) {
  1971. dev_warn(adapter->pdev_dev, "unused resources niq/neq (%d/%d)"
  1972. " ignored\n", vfres->niq, vfres->neq - ethqsets*2);
  1973. }
  1974. adapter->sge.max_ethqsets = ethqsets;
  1975. /*
  1976. * Check for various parameter sanity issues. Most checks simply
  1977. * result in us using fewer resources than our provissioning but we
  1978. * do need at least one "port" with which to work ...
  1979. */
  1980. if (adapter->sge.max_ethqsets < adapter->params.nports) {
  1981. dev_warn(adapter->pdev_dev, "only using %d of %d available"
  1982. " virtual interfaces (too few Queue Sets)\n",
  1983. adapter->sge.max_ethqsets, adapter->params.nports);
  1984. adapter->params.nports = adapter->sge.max_ethqsets;
  1985. }
  1986. if (adapter->params.nports == 0) {
  1987. dev_err(adapter->pdev_dev, "no virtual interfaces configured/"
  1988. "usable!\n");
  1989. return -EINVAL;
  1990. }
  1991. return 0;
  1992. }
  1993. static inline void init_rspq(struct sge_rspq *rspq, u8 timer_idx,
  1994. u8 pkt_cnt_idx, unsigned int size,
  1995. unsigned int iqe_size)
  1996. {
  1997. rspq->intr_params = (QINTR_TIMER_IDX(timer_idx) |
  1998. (pkt_cnt_idx < SGE_NCOUNTERS ? QINTR_CNT_EN : 0));
  1999. rspq->pktcnt_idx = (pkt_cnt_idx < SGE_NCOUNTERS
  2000. ? pkt_cnt_idx
  2001. : 0);
  2002. rspq->iqe_len = iqe_size;
  2003. rspq->size = size;
  2004. }
  2005. /*
  2006. * Perform default configuration of DMA queues depending on the number and
  2007. * type of ports we found and the number of available CPUs. Most settings can
  2008. * be modified by the admin via ethtool and cxgbtool prior to the adapter
  2009. * being brought up for the first time.
  2010. */
  2011. static void __devinit cfg_queues(struct adapter *adapter)
  2012. {
  2013. struct sge *s = &adapter->sge;
  2014. int q10g, n10g, qidx, pidx, qs;
  2015. size_t iqe_size;
  2016. /*
  2017. * We should not be called till we know how many Queue Sets we can
  2018. * support. In particular, this means that we need to know what kind
  2019. * of interrupts we'll be using ...
  2020. */
  2021. BUG_ON((adapter->flags & (USING_MSIX|USING_MSI)) == 0);
  2022. /*
  2023. * Count the number of 10GbE Virtual Interfaces that we have.
  2024. */
  2025. n10g = 0;
  2026. for_each_port(adapter, pidx)
  2027. n10g += is_10g_port(&adap2pinfo(adapter, pidx)->link_cfg);
  2028. /*
  2029. * We default to 1 queue per non-10G port and up to # of cores queues
  2030. * per 10G port.
  2031. */
  2032. if (n10g == 0)
  2033. q10g = 0;
  2034. else {
  2035. int n1g = (adapter->params.nports - n10g);
  2036. q10g = (adapter->sge.max_ethqsets - n1g) / n10g;
  2037. if (q10g > num_online_cpus())
  2038. q10g = num_online_cpus();
  2039. }
  2040. /*
  2041. * Allocate the "Queue Sets" to the various Virtual Interfaces.
  2042. * The layout will be established in setup_sge_queues() when the
  2043. * adapter is brough up for the first time.
  2044. */
  2045. qidx = 0;
  2046. for_each_port(adapter, pidx) {
  2047. struct port_info *pi = adap2pinfo(adapter, pidx);
  2048. pi->first_qset = qidx;
  2049. pi->nqsets = is_10g_port(&pi->link_cfg) ? q10g : 1;
  2050. qidx += pi->nqsets;
  2051. }
  2052. s->ethqsets = qidx;
  2053. /*
  2054. * The Ingress Queue Entry Size for our various Response Queues needs
  2055. * to be big enough to accommodate the largest message we can receive
  2056. * from the chip/firmware; which is 64 bytes ...
  2057. */
  2058. iqe_size = 64;
  2059. /*
  2060. * Set up default Queue Set parameters ... Start off with the
  2061. * shortest interrupt holdoff timer.
  2062. */
  2063. for (qs = 0; qs < s->max_ethqsets; qs++) {
  2064. struct sge_eth_rxq *rxq = &s->ethrxq[qs];
  2065. struct sge_eth_txq *txq = &s->ethtxq[qs];
  2066. init_rspq(&rxq->rspq, 0, 0, 1024, iqe_size);
  2067. rxq->fl.size = 72;
  2068. txq->q.size = 1024;
  2069. }
  2070. /*
  2071. * The firmware event queue is used for link state changes and
  2072. * notifications of TX DMA completions.
  2073. */
  2074. init_rspq(&s->fw_evtq, SGE_TIMER_RSTRT_CNTR, 0, 512, iqe_size);
  2075. /*
  2076. * The forwarded interrupt queue is used when we're in MSI interrupt
  2077. * mode. In this mode all interrupts associated with RX queues will
  2078. * be forwarded to a single queue which we'll associate with our MSI
  2079. * interrupt vector. The messages dropped in the forwarded interrupt
  2080. * queue will indicate which ingress queue needs servicing ... This
  2081. * queue needs to be large enough to accommodate all of the ingress
  2082. * queues which are forwarding their interrupt (+1 to prevent the PIDX
  2083. * from equalling the CIDX if every ingress queue has an outstanding
  2084. * interrupt). The queue doesn't need to be any larger because no
  2085. * ingress queue will ever have more than one outstanding interrupt at
  2086. * any time ...
  2087. */
  2088. init_rspq(&s->intrq, SGE_TIMER_RSTRT_CNTR, 0, MSIX_ENTRIES + 1,
  2089. iqe_size);
  2090. }
  2091. /*
  2092. * Reduce the number of Ethernet queues across all ports to at most n.
  2093. * n provides at least one queue per port.
  2094. */
  2095. static void __devinit reduce_ethqs(struct adapter *adapter, int n)
  2096. {
  2097. int i;
  2098. struct port_info *pi;
  2099. /*
  2100. * While we have too many active Ether Queue Sets, interate across the
  2101. * "ports" and reduce their individual Queue Set allocations.
  2102. */
  2103. BUG_ON(n < adapter->params.nports);
  2104. while (n < adapter->sge.ethqsets)
  2105. for_each_port(adapter, i) {
  2106. pi = adap2pinfo(adapter, i);
  2107. if (pi->nqsets > 1) {
  2108. pi->nqsets--;
  2109. adapter->sge.ethqsets--;
  2110. if (adapter->sge.ethqsets <= n)
  2111. break;
  2112. }
  2113. }
  2114. /*
  2115. * Reassign the starting Queue Sets for each of the "ports" ...
  2116. */
  2117. n = 0;
  2118. for_each_port(adapter, i) {
  2119. pi = adap2pinfo(adapter, i);
  2120. pi->first_qset = n;
  2121. n += pi->nqsets;
  2122. }
  2123. }
  2124. /*
  2125. * We need to grab enough MSI-X vectors to cover our interrupt needs. Ideally
  2126. * we get a separate MSI-X vector for every "Queue Set" plus any extras we
  2127. * need. Minimally we need one for every Virtual Interface plus those needed
  2128. * for our "extras". Note that this process may lower the maximum number of
  2129. * allowed Queue Sets ...
  2130. */
  2131. static int __devinit enable_msix(struct adapter *adapter)
  2132. {
  2133. int i, err, want, need;
  2134. struct msix_entry entries[MSIX_ENTRIES];
  2135. struct sge *s = &adapter->sge;
  2136. for (i = 0; i < MSIX_ENTRIES; ++i)
  2137. entries[i].entry = i;
  2138. /*
  2139. * We _want_ enough MSI-X interrupts to cover all of our "Queue Sets"
  2140. * plus those needed for our "extras" (for example, the firmware
  2141. * message queue). We _need_ at least one "Queue Set" per Virtual
  2142. * Interface plus those needed for our "extras". So now we get to see
  2143. * if the song is right ...
  2144. */
  2145. want = s->max_ethqsets + MSIX_EXTRAS;
  2146. need = adapter->params.nports + MSIX_EXTRAS;
  2147. while ((err = pci_enable_msix(adapter->pdev, entries, want)) >= need)
  2148. want = err;
  2149. if (err == 0) {
  2150. int nqsets = want - MSIX_EXTRAS;
  2151. if (nqsets < s->max_ethqsets) {
  2152. dev_warn(adapter->pdev_dev, "only enough MSI-X vectors"
  2153. " for %d Queue Sets\n", nqsets);
  2154. s->max_ethqsets = nqsets;
  2155. if (nqsets < s->ethqsets)
  2156. reduce_ethqs(adapter, nqsets);
  2157. }
  2158. for (i = 0; i < want; ++i)
  2159. adapter->msix_info[i].vec = entries[i].vector;
  2160. } else if (err > 0) {
  2161. pci_disable_msix(adapter->pdev);
  2162. dev_info(adapter->pdev_dev, "only %d MSI-X vectors left,"
  2163. " not using MSI-X\n", err);
  2164. }
  2165. return err;
  2166. }
  2167. #ifdef HAVE_NET_DEVICE_OPS
  2168. static const struct net_device_ops cxgb4vf_netdev_ops = {
  2169. .ndo_open = cxgb4vf_open,
  2170. .ndo_stop = cxgb4vf_stop,
  2171. .ndo_start_xmit = t4vf_eth_xmit,
  2172. .ndo_get_stats = cxgb4vf_get_stats,
  2173. .ndo_set_rx_mode = cxgb4vf_set_rxmode,
  2174. .ndo_set_mac_address = cxgb4vf_set_mac_addr,
  2175. .ndo_validate_addr = eth_validate_addr,
  2176. .ndo_do_ioctl = cxgb4vf_do_ioctl,
  2177. .ndo_change_mtu = cxgb4vf_change_mtu,
  2178. .ndo_vlan_rx_register = cxgb4vf_vlan_rx_register,
  2179. #ifdef CONFIG_NET_POLL_CONTROLLER
  2180. .ndo_poll_controller = cxgb4vf_poll_controller,
  2181. #endif
  2182. };
  2183. #endif
  2184. /*
  2185. * "Probe" a device: initialize a device and construct all kernel and driver
  2186. * state needed to manage the device. This routine is called "init_one" in
  2187. * the PF Driver ...
  2188. */
  2189. static int __devinit cxgb4vf_pci_probe(struct pci_dev *pdev,
  2190. const struct pci_device_id *ent)
  2191. {
  2192. static int version_printed;
  2193. int pci_using_dac;
  2194. int err, pidx;
  2195. unsigned int pmask;
  2196. struct adapter *adapter;
  2197. struct port_info *pi;
  2198. struct net_device *netdev;
  2199. /*
  2200. * Print our driver banner the first time we're called to initialize a
  2201. * device.
  2202. */
  2203. if (version_printed == 0) {
  2204. printk(KERN_INFO "%s - version %s\n", DRV_DESC, DRV_VERSION);
  2205. version_printed = 1;
  2206. }
  2207. /*
  2208. * Initialize generic PCI device state.
  2209. */
  2210. err = pci_enable_device(pdev);
  2211. if (err) {
  2212. dev_err(&pdev->dev, "cannot enable PCI device\n");
  2213. return err;
  2214. }
  2215. /*
  2216. * Reserve PCI resources for the device. If we can't get them some
  2217. * other driver may have already claimed the device ...
  2218. */
  2219. err = pci_request_regions(pdev, KBUILD_MODNAME);
  2220. if (err) {
  2221. dev_err(&pdev->dev, "cannot obtain PCI resources\n");
  2222. goto err_disable_device;
  2223. }
  2224. /*
  2225. * Set up our DMA mask: try for 64-bit address masking first and
  2226. * fall back to 32-bit if we can't get 64 bits ...
  2227. */
  2228. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  2229. if (err == 0) {
  2230. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  2231. if (err) {
  2232. dev_err(&pdev->dev, "unable to obtain 64-bit DMA for"
  2233. " coherent allocations\n");
  2234. goto err_release_regions;
  2235. }
  2236. pci_using_dac = 1;
  2237. } else {
  2238. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  2239. if (err != 0) {
  2240. dev_err(&pdev->dev, "no usable DMA configuration\n");
  2241. goto err_release_regions;
  2242. }
  2243. pci_using_dac = 0;
  2244. }
  2245. /*
  2246. * Enable bus mastering for the device ...
  2247. */
  2248. pci_set_master(pdev);
  2249. /*
  2250. * Allocate our adapter data structure and attach it to the device.
  2251. */
  2252. adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
  2253. if (!adapter) {
  2254. err = -ENOMEM;
  2255. goto err_release_regions;
  2256. }
  2257. pci_set_drvdata(pdev, adapter);
  2258. adapter->pdev = pdev;
  2259. adapter->pdev_dev = &pdev->dev;
  2260. /*
  2261. * Initialize SMP data synchronization resources.
  2262. */
  2263. spin_lock_init(&adapter->stats_lock);
  2264. /*
  2265. * Map our I/O registers in BAR0.
  2266. */
  2267. adapter->regs = pci_ioremap_bar(pdev, 0);
  2268. if (!adapter->regs) {
  2269. dev_err(&pdev->dev, "cannot map device registers\n");
  2270. err = -ENOMEM;
  2271. goto err_free_adapter;
  2272. }
  2273. /*
  2274. * Initialize adapter level features.
  2275. */
  2276. adapter->name = pci_name(pdev);
  2277. adapter->msg_enable = dflt_msg_enable;
  2278. err = adap_init0(adapter);
  2279. if (err)
  2280. goto err_unmap_bar;
  2281. /*
  2282. * Allocate our "adapter ports" and stitch everything together.
  2283. */
  2284. pmask = adapter->params.vfres.pmask;
  2285. for_each_port(adapter, pidx) {
  2286. int port_id, viid;
  2287. /*
  2288. * We simplistically allocate our virtual interfaces
  2289. * sequentially across the port numbers to which we have
  2290. * access rights. This should be configurable in some manner
  2291. * ...
  2292. */
  2293. if (pmask == 0)
  2294. break;
  2295. port_id = ffs(pmask) - 1;
  2296. pmask &= ~(1 << port_id);
  2297. viid = t4vf_alloc_vi(adapter, port_id);
  2298. if (viid < 0) {
  2299. dev_err(&pdev->dev, "cannot allocate VI for port %d:"
  2300. " err=%d\n", port_id, viid);
  2301. err = viid;
  2302. goto err_free_dev;
  2303. }
  2304. /*
  2305. * Allocate our network device and stitch things together.
  2306. */
  2307. netdev = alloc_etherdev_mq(sizeof(struct port_info),
  2308. MAX_PORT_QSETS);
  2309. if (netdev == NULL) {
  2310. dev_err(&pdev->dev, "cannot allocate netdev for"
  2311. " port %d\n", port_id);
  2312. t4vf_free_vi(adapter, viid);
  2313. err = -ENOMEM;
  2314. goto err_free_dev;
  2315. }
  2316. adapter->port[pidx] = netdev;
  2317. SET_NETDEV_DEV(netdev, &pdev->dev);
  2318. pi = netdev_priv(netdev);
  2319. pi->adapter = adapter;
  2320. pi->pidx = pidx;
  2321. pi->port_id = port_id;
  2322. pi->viid = viid;
  2323. /*
  2324. * Initialize the starting state of our "port" and register
  2325. * it.
  2326. */
  2327. pi->xact_addr_filt = -1;
  2328. pi->rx_offload = RX_CSO;
  2329. netif_carrier_off(netdev);
  2330. netdev->irq = pdev->irq;
  2331. netdev->features = (NETIF_F_SG | TSO_FLAGS |
  2332. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  2333. NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
  2334. NETIF_F_GRO);
  2335. if (pci_using_dac)
  2336. netdev->features |= NETIF_F_HIGHDMA;
  2337. netdev->vlan_features =
  2338. (netdev->features &
  2339. ~(NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX));
  2340. #ifdef HAVE_NET_DEVICE_OPS
  2341. netdev->netdev_ops = &cxgb4vf_netdev_ops;
  2342. #else
  2343. netdev->vlan_rx_register = cxgb4vf_vlan_rx_register;
  2344. netdev->open = cxgb4vf_open;
  2345. netdev->stop = cxgb4vf_stop;
  2346. netdev->hard_start_xmit = t4vf_eth_xmit;
  2347. netdev->get_stats = cxgb4vf_get_stats;
  2348. netdev->set_rx_mode = cxgb4vf_set_rxmode;
  2349. netdev->do_ioctl = cxgb4vf_do_ioctl;
  2350. netdev->change_mtu = cxgb4vf_change_mtu;
  2351. netdev->set_mac_address = cxgb4vf_set_mac_addr;
  2352. #ifdef CONFIG_NET_POLL_CONTROLLER
  2353. netdev->poll_controller = cxgb4vf_poll_controller;
  2354. #endif
  2355. #endif
  2356. SET_ETHTOOL_OPS(netdev, &cxgb4vf_ethtool_ops);
  2357. /*
  2358. * Initialize the hardware/software state for the port.
  2359. */
  2360. err = t4vf_port_init(adapter, pidx);
  2361. if (err) {
  2362. dev_err(&pdev->dev, "cannot initialize port %d\n",
  2363. pidx);
  2364. goto err_free_dev;
  2365. }
  2366. }
  2367. /*
  2368. * The "card" is now ready to go. If any errors occur during device
  2369. * registration we do not fail the whole "card" but rather proceed
  2370. * only with the ports we manage to register successfully. However we
  2371. * must register at least one net device.
  2372. */
  2373. for_each_port(adapter, pidx) {
  2374. netdev = adapter->port[pidx];
  2375. if (netdev == NULL)
  2376. continue;
  2377. err = register_netdev(netdev);
  2378. if (err) {
  2379. dev_warn(&pdev->dev, "cannot register net device %s,"
  2380. " skipping\n", netdev->name);
  2381. continue;
  2382. }
  2383. set_bit(pidx, &adapter->registered_device_map);
  2384. }
  2385. if (adapter->registered_device_map == 0) {
  2386. dev_err(&pdev->dev, "could not register any net devices\n");
  2387. goto err_free_dev;
  2388. }
  2389. /*
  2390. * Set up our debugfs entries.
  2391. */
  2392. if (!IS_ERR_OR_NULL(cxgb4vf_debugfs_root)) {
  2393. adapter->debugfs_root =
  2394. debugfs_create_dir(pci_name(pdev),
  2395. cxgb4vf_debugfs_root);
  2396. if (IS_ERR_OR_NULL(adapter->debugfs_root))
  2397. dev_warn(&pdev->dev, "could not create debugfs"
  2398. " directory");
  2399. else
  2400. setup_debugfs(adapter);
  2401. }
  2402. /*
  2403. * See what interrupts we'll be using. If we've been configured to
  2404. * use MSI-X interrupts, try to enable them but fall back to using
  2405. * MSI interrupts if we can't enable MSI-X interrupts. If we can't
  2406. * get MSI interrupts we bail with the error.
  2407. */
  2408. if (msi == MSI_MSIX && enable_msix(adapter) == 0)
  2409. adapter->flags |= USING_MSIX;
  2410. else {
  2411. err = pci_enable_msi(pdev);
  2412. if (err) {
  2413. dev_err(&pdev->dev, "Unable to allocate %s interrupts;"
  2414. " err=%d\n",
  2415. msi == MSI_MSIX ? "MSI-X or MSI" : "MSI", err);
  2416. goto err_free_debugfs;
  2417. }
  2418. adapter->flags |= USING_MSI;
  2419. }
  2420. /*
  2421. * Now that we know how many "ports" we have and what their types are,
  2422. * and how many Queue Sets we can support, we can configure our queue
  2423. * resources.
  2424. */
  2425. cfg_queues(adapter);
  2426. /*
  2427. * Print a short notice on the existance and configuration of the new
  2428. * VF network device ...
  2429. */
  2430. for_each_port(adapter, pidx) {
  2431. dev_info(adapter->pdev_dev, "%s: Chelsio VF NIC PCIe %s\n",
  2432. adapter->port[pidx]->name,
  2433. (adapter->flags & USING_MSIX) ? "MSI-X" :
  2434. (adapter->flags & USING_MSI) ? "MSI" : "");
  2435. }
  2436. /*
  2437. * Return success!
  2438. */
  2439. return 0;
  2440. /*
  2441. * Error recovery and exit code. Unwind state that's been created
  2442. * so far and return the error.
  2443. */
  2444. err_free_debugfs:
  2445. if (!IS_ERR_OR_NULL(adapter->debugfs_root)) {
  2446. cleanup_debugfs(adapter);
  2447. debugfs_remove_recursive(adapter->debugfs_root);
  2448. }
  2449. err_free_dev:
  2450. for_each_port(adapter, pidx) {
  2451. netdev = adapter->port[pidx];
  2452. if (netdev == NULL)
  2453. continue;
  2454. pi = netdev_priv(netdev);
  2455. t4vf_free_vi(adapter, pi->viid);
  2456. if (test_bit(pidx, &adapter->registered_device_map))
  2457. unregister_netdev(netdev);
  2458. free_netdev(netdev);
  2459. }
  2460. err_unmap_bar:
  2461. iounmap(adapter->regs);
  2462. err_free_adapter:
  2463. kfree(adapter);
  2464. pci_set_drvdata(pdev, NULL);
  2465. err_release_regions:
  2466. pci_release_regions(pdev);
  2467. pci_set_drvdata(pdev, NULL);
  2468. pci_clear_master(pdev);
  2469. err_disable_device:
  2470. pci_disable_device(pdev);
  2471. return err;
  2472. }
  2473. /*
  2474. * "Remove" a device: tear down all kernel and driver state created in the
  2475. * "probe" routine and quiesce the device (disable interrupts, etc.). (Note
  2476. * that this is called "remove_one" in the PF Driver.)
  2477. */
  2478. static void __devexit cxgb4vf_pci_remove(struct pci_dev *pdev)
  2479. {
  2480. struct adapter *adapter = pci_get_drvdata(pdev);
  2481. /*
  2482. * Tear down driver state associated with device.
  2483. */
  2484. if (adapter) {
  2485. int pidx;
  2486. /*
  2487. * Stop all of our activity. Unregister network port,
  2488. * disable interrupts, etc.
  2489. */
  2490. for_each_port(adapter, pidx)
  2491. if (test_bit(pidx, &adapter->registered_device_map))
  2492. unregister_netdev(adapter->port[pidx]);
  2493. t4vf_sge_stop(adapter);
  2494. if (adapter->flags & USING_MSIX) {
  2495. pci_disable_msix(adapter->pdev);
  2496. adapter->flags &= ~USING_MSIX;
  2497. } else if (adapter->flags & USING_MSI) {
  2498. pci_disable_msi(adapter->pdev);
  2499. adapter->flags &= ~USING_MSI;
  2500. }
  2501. /*
  2502. * Tear down our debugfs entries.
  2503. */
  2504. if (!IS_ERR_OR_NULL(adapter->debugfs_root)) {
  2505. cleanup_debugfs(adapter);
  2506. debugfs_remove_recursive(adapter->debugfs_root);
  2507. }
  2508. /*
  2509. * Free all of the various resources which we've acquired ...
  2510. */
  2511. t4vf_free_sge_resources(adapter);
  2512. for_each_port(adapter, pidx) {
  2513. struct net_device *netdev = adapter->port[pidx];
  2514. struct port_info *pi;
  2515. if (netdev == NULL)
  2516. continue;
  2517. pi = netdev_priv(netdev);
  2518. t4vf_free_vi(adapter, pi->viid);
  2519. free_netdev(netdev);
  2520. }
  2521. iounmap(adapter->regs);
  2522. kfree(adapter);
  2523. pci_set_drvdata(pdev, NULL);
  2524. }
  2525. /*
  2526. * Disable the device and release its PCI resources.
  2527. */
  2528. pci_disable_device(pdev);
  2529. pci_clear_master(pdev);
  2530. pci_release_regions(pdev);
  2531. }
  2532. /*
  2533. * "Shutdown" quiesce the device, stopping Ingress Packet and Interrupt
  2534. * delivery.
  2535. */
  2536. static void __devexit cxgb4vf_pci_shutdown(struct pci_dev *pdev)
  2537. {
  2538. struct adapter *adapter;
  2539. int pidx;
  2540. adapter = pci_get_drvdata(pdev);
  2541. if (!adapter)
  2542. return;
  2543. /*
  2544. * Disable all Virtual Interfaces. This will shut down the
  2545. * delivery of all ingress packets into the chip for these
  2546. * Virtual Interfaces.
  2547. */
  2548. for_each_port(adapter, pidx) {
  2549. struct net_device *netdev;
  2550. struct port_info *pi;
  2551. if (!test_bit(pidx, &adapter->registered_device_map))
  2552. continue;
  2553. netdev = adapter->port[pidx];
  2554. if (!netdev)
  2555. continue;
  2556. pi = netdev_priv(netdev);
  2557. t4vf_enable_vi(adapter, pi->viid, false, false);
  2558. }
  2559. /*
  2560. * Free up all Queues which will prevent further DMA and
  2561. * Interrupts allowing various internal pathways to drain.
  2562. */
  2563. t4vf_free_sge_resources(adapter);
  2564. }
  2565. /*
  2566. * PCI Device registration data structures.
  2567. */
  2568. #define CH_DEVICE(devid, idx) \
  2569. { PCI_VENDOR_ID_CHELSIO, devid, PCI_ANY_ID, PCI_ANY_ID, 0, 0, idx }
  2570. static struct pci_device_id cxgb4vf_pci_tbl[] = {
  2571. CH_DEVICE(0xb000, 0), /* PE10K FPGA */
  2572. CH_DEVICE(0x4800, 0), /* T440-dbg */
  2573. CH_DEVICE(0x4801, 0), /* T420-cr */
  2574. CH_DEVICE(0x4802, 0), /* T422-cr */
  2575. CH_DEVICE(0x4803, 0), /* T440-cr */
  2576. CH_DEVICE(0x4804, 0), /* T420-bch */
  2577. CH_DEVICE(0x4805, 0), /* T440-bch */
  2578. CH_DEVICE(0x4806, 0), /* T460-ch */
  2579. CH_DEVICE(0x4807, 0), /* T420-so */
  2580. CH_DEVICE(0x4808, 0), /* T420-cx */
  2581. CH_DEVICE(0x4809, 0), /* T420-bt */
  2582. CH_DEVICE(0x480a, 0), /* T404-bt */
  2583. { 0, }
  2584. };
  2585. MODULE_DESCRIPTION(DRV_DESC);
  2586. MODULE_AUTHOR("Chelsio Communications");
  2587. MODULE_LICENSE("Dual BSD/GPL");
  2588. MODULE_VERSION(DRV_VERSION);
  2589. MODULE_DEVICE_TABLE(pci, cxgb4vf_pci_tbl);
  2590. static struct pci_driver cxgb4vf_driver = {
  2591. .name = KBUILD_MODNAME,
  2592. .id_table = cxgb4vf_pci_tbl,
  2593. .probe = cxgb4vf_pci_probe,
  2594. .remove = __devexit_p(cxgb4vf_pci_remove),
  2595. .shutdown = __devexit_p(cxgb4vf_pci_shutdown),
  2596. };
  2597. /*
  2598. * Initialize global driver state.
  2599. */
  2600. static int __init cxgb4vf_module_init(void)
  2601. {
  2602. int ret;
  2603. /*
  2604. * Vet our module parameters.
  2605. */
  2606. if (msi != MSI_MSIX && msi != MSI_MSI) {
  2607. printk(KERN_WARNING KBUILD_MODNAME
  2608. ": bad module parameter msi=%d; must be %d"
  2609. " (MSI-X or MSI) or %d (MSI)\n",
  2610. msi, MSI_MSIX, MSI_MSI);
  2611. return -EINVAL;
  2612. }
  2613. /* Debugfs support is optional, just warn if this fails */
  2614. cxgb4vf_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
  2615. if (IS_ERR_OR_NULL(cxgb4vf_debugfs_root))
  2616. printk(KERN_WARNING KBUILD_MODNAME ": could not create"
  2617. " debugfs entry, continuing\n");
  2618. ret = pci_register_driver(&cxgb4vf_driver);
  2619. if (ret < 0 && !IS_ERR_OR_NULL(cxgb4vf_debugfs_root))
  2620. debugfs_remove(cxgb4vf_debugfs_root);
  2621. return ret;
  2622. }
  2623. /*
  2624. * Tear down global driver state.
  2625. */
  2626. static void __exit cxgb4vf_module_exit(void)
  2627. {
  2628. pci_unregister_driver(&cxgb4vf_driver);
  2629. debugfs_remove(cxgb4vf_debugfs_root);
  2630. }
  2631. module_init(cxgb4vf_module_init);
  2632. module_exit(cxgb4vf_module_exit);