sge.c 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706
  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/skbuff.h>
  36. #include <linux/netdevice.h>
  37. #include <linux/etherdevice.h>
  38. #include <linux/if_vlan.h>
  39. #include <linux/ip.h>
  40. #include <net/ipv6.h>
  41. #include <net/tcp.h>
  42. #include <linux/dma-mapping.h>
  43. #include <linux/prefetch.h>
  44. #include "t4vf_common.h"
  45. #include "t4vf_defs.h"
  46. #include "../cxgb4/t4_regs.h"
  47. #include "../cxgb4/t4_values.h"
  48. #include "../cxgb4/t4fw_api.h"
  49. #include "../cxgb4/t4_msg.h"
  50. /*
  51. * Constants ...
  52. */
  53. enum {
  54. /*
  55. * Egress Queue sizes, producer and consumer indices are all in units
  56. * of Egress Context Units bytes. Note that as far as the hardware is
  57. * concerned, the free list is an Egress Queue (the host produces free
  58. * buffers which the hardware consumes) and free list entries are
  59. * 64-bit PCI DMA addresses.
  60. */
  61. EQ_UNIT = SGE_EQ_IDXSIZE,
  62. FL_PER_EQ_UNIT = EQ_UNIT / sizeof(__be64),
  63. TXD_PER_EQ_UNIT = EQ_UNIT / sizeof(__be64),
  64. /*
  65. * Max number of TX descriptors we clean up at a time. Should be
  66. * modest as freeing skbs isn't cheap and it happens while holding
  67. * locks. We just need to free packets faster than they arrive, we
  68. * eventually catch up and keep the amortized cost reasonable.
  69. */
  70. MAX_TX_RECLAIM = 16,
  71. /*
  72. * Max number of Rx buffers we replenish at a time. Again keep this
  73. * modest, allocating buffers isn't cheap either.
  74. */
  75. MAX_RX_REFILL = 16,
  76. /*
  77. * Period of the Rx queue check timer. This timer is infrequent as it
  78. * has something to do only when the system experiences severe memory
  79. * shortage.
  80. */
  81. RX_QCHECK_PERIOD = (HZ / 2),
  82. /*
  83. * Period of the TX queue check timer and the maximum number of TX
  84. * descriptors to be reclaimed by the TX timer.
  85. */
  86. TX_QCHECK_PERIOD = (HZ / 2),
  87. MAX_TIMER_TX_RECLAIM = 100,
  88. /*
  89. * Suspend an Ethernet TX queue with fewer available descriptors than
  90. * this. We always want to have room for a maximum sized packet:
  91. * inline immediate data + MAX_SKB_FRAGS. This is the same as
  92. * calc_tx_flits() for a TSO packet with nr_frags == MAX_SKB_FRAGS
  93. * (see that function and its helpers for a description of the
  94. * calculation).
  95. */
  96. ETHTXQ_MAX_FRAGS = MAX_SKB_FRAGS + 1,
  97. ETHTXQ_MAX_SGL_LEN = ((3 * (ETHTXQ_MAX_FRAGS-1))/2 +
  98. ((ETHTXQ_MAX_FRAGS-1) & 1) +
  99. 2),
  100. ETHTXQ_MAX_HDR = (sizeof(struct fw_eth_tx_pkt_vm_wr) +
  101. sizeof(struct cpl_tx_pkt_lso_core) +
  102. sizeof(struct cpl_tx_pkt_core)) / sizeof(__be64),
  103. ETHTXQ_MAX_FLITS = ETHTXQ_MAX_SGL_LEN + ETHTXQ_MAX_HDR,
  104. ETHTXQ_STOP_THRES = 1 + DIV_ROUND_UP(ETHTXQ_MAX_FLITS, TXD_PER_EQ_UNIT),
  105. /*
  106. * Max TX descriptor space we allow for an Ethernet packet to be
  107. * inlined into a WR. This is limited by the maximum value which
  108. * we can specify for immediate data in the firmware Ethernet TX
  109. * Work Request.
  110. */
  111. MAX_IMM_TX_PKT_LEN = FW_WR_IMMDLEN_M,
  112. /*
  113. * Max size of a WR sent through a control TX queue.
  114. */
  115. MAX_CTRL_WR_LEN = 256,
  116. /*
  117. * Maximum amount of data which we'll ever need to inline into a
  118. * TX ring: max(MAX_IMM_TX_PKT_LEN, MAX_CTRL_WR_LEN).
  119. */
  120. MAX_IMM_TX_LEN = (MAX_IMM_TX_PKT_LEN > MAX_CTRL_WR_LEN
  121. ? MAX_IMM_TX_PKT_LEN
  122. : MAX_CTRL_WR_LEN),
  123. /*
  124. * For incoming packets less than RX_COPY_THRES, we copy the data into
  125. * an skb rather than referencing the data. We allocate enough
  126. * in-line room in skb's to accommodate pulling in RX_PULL_LEN bytes
  127. * of the data (header).
  128. */
  129. RX_COPY_THRES = 256,
  130. RX_PULL_LEN = 128,
  131. /*
  132. * Main body length for sk_buffs used for RX Ethernet packets with
  133. * fragments. Should be >= RX_PULL_LEN but possibly bigger to give
  134. * pskb_may_pull() some room.
  135. */
  136. RX_SKB_LEN = 512,
  137. };
  138. /*
  139. * Software state per TX descriptor.
  140. */
  141. struct tx_sw_desc {
  142. struct sk_buff *skb; /* socket buffer of TX data source */
  143. struct ulptx_sgl *sgl; /* scatter/gather list in TX Queue */
  144. };
  145. /*
  146. * Software state per RX Free List descriptor. We keep track of the allocated
  147. * FL page, its size, and its PCI DMA address (if the page is mapped). The FL
  148. * page size and its PCI DMA mapped state are stored in the low bits of the
  149. * PCI DMA address as per below.
  150. */
  151. struct rx_sw_desc {
  152. struct page *page; /* Free List page buffer */
  153. dma_addr_t dma_addr; /* PCI DMA address (if mapped) */
  154. /* and flags (see below) */
  155. };
  156. /*
  157. * The low bits of rx_sw_desc.dma_addr have special meaning. Note that the
  158. * SGE also uses the low 4 bits to determine the size of the buffer. It uses
  159. * those bits to index into the SGE_FL_BUFFER_SIZE[index] register array.
  160. * Since we only use SGE_FL_BUFFER_SIZE0 and SGE_FL_BUFFER_SIZE1, these low 4
  161. * bits can only contain a 0 or a 1 to indicate which size buffer we're giving
  162. * to the SGE. Thus, our software state of "is the buffer mapped for DMA" is
  163. * maintained in an inverse sense so the hardware never sees that bit high.
  164. */
  165. enum {
  166. RX_LARGE_BUF = 1 << 0, /* buffer is SGE_FL_BUFFER_SIZE[1] */
  167. RX_UNMAPPED_BUF = 1 << 1, /* buffer is not mapped */
  168. };
  169. /**
  170. * get_buf_addr - return DMA buffer address of software descriptor
  171. * @sdesc: pointer to the software buffer descriptor
  172. *
  173. * Return the DMA buffer address of a software descriptor (stripping out
  174. * our low-order flag bits).
  175. */
  176. static inline dma_addr_t get_buf_addr(const struct rx_sw_desc *sdesc)
  177. {
  178. return sdesc->dma_addr & ~(dma_addr_t)(RX_LARGE_BUF | RX_UNMAPPED_BUF);
  179. }
  180. /**
  181. * is_buf_mapped - is buffer mapped for DMA?
  182. * @sdesc: pointer to the software buffer descriptor
  183. *
  184. * Determine whether the buffer associated with a software descriptor in
  185. * mapped for DMA or not.
  186. */
  187. static inline bool is_buf_mapped(const struct rx_sw_desc *sdesc)
  188. {
  189. return !(sdesc->dma_addr & RX_UNMAPPED_BUF);
  190. }
  191. /**
  192. * need_skb_unmap - does the platform need unmapping of sk_buffs?
  193. *
  194. * Returns true if the platform needs sk_buff unmapping. The compiler
  195. * optimizes away unnecessary code if this returns true.
  196. */
  197. static inline int need_skb_unmap(void)
  198. {
  199. #ifdef CONFIG_NEED_DMA_MAP_STATE
  200. return 1;
  201. #else
  202. return 0;
  203. #endif
  204. }
  205. /**
  206. * txq_avail - return the number of available slots in a TX queue
  207. * @tq: the TX queue
  208. *
  209. * Returns the number of available descriptors in a TX queue.
  210. */
  211. static inline unsigned int txq_avail(const struct sge_txq *tq)
  212. {
  213. return tq->size - 1 - tq->in_use;
  214. }
  215. /**
  216. * fl_cap - return the capacity of a Free List
  217. * @fl: the Free List
  218. *
  219. * Returns the capacity of a Free List. The capacity is less than the
  220. * size because an Egress Queue Index Unit worth of descriptors needs to
  221. * be left unpopulated, otherwise the Producer and Consumer indices PIDX
  222. * and CIDX will match and the hardware will think the FL is empty.
  223. */
  224. static inline unsigned int fl_cap(const struct sge_fl *fl)
  225. {
  226. return fl->size - FL_PER_EQ_UNIT;
  227. }
  228. /**
  229. * fl_starving - return whether a Free List is starving.
  230. * @adapter: pointer to the adapter
  231. * @fl: the Free List
  232. *
  233. * Tests specified Free List to see whether the number of buffers
  234. * available to the hardware has falled below our "starvation"
  235. * threshold.
  236. */
  237. static inline bool fl_starving(const struct adapter *adapter,
  238. const struct sge_fl *fl)
  239. {
  240. const struct sge *s = &adapter->sge;
  241. return fl->avail - fl->pend_cred <= s->fl_starve_thres;
  242. }
  243. /**
  244. * map_skb - map an skb for DMA to the device
  245. * @dev: the egress net device
  246. * @skb: the packet to map
  247. * @addr: a pointer to the base of the DMA mapping array
  248. *
  249. * Map an skb for DMA to the device and return an array of DMA addresses.
  250. */
  251. static int map_skb(struct device *dev, const struct sk_buff *skb,
  252. dma_addr_t *addr)
  253. {
  254. const skb_frag_t *fp, *end;
  255. const struct skb_shared_info *si;
  256. *addr = dma_map_single(dev, skb->data, skb_headlen(skb), DMA_TO_DEVICE);
  257. if (dma_mapping_error(dev, *addr))
  258. goto out_err;
  259. si = skb_shinfo(skb);
  260. end = &si->frags[si->nr_frags];
  261. for (fp = si->frags; fp < end; fp++) {
  262. *++addr = skb_frag_dma_map(dev, fp, 0, skb_frag_size(fp),
  263. DMA_TO_DEVICE);
  264. if (dma_mapping_error(dev, *addr))
  265. goto unwind;
  266. }
  267. return 0;
  268. unwind:
  269. while (fp-- > si->frags)
  270. dma_unmap_page(dev, *--addr, skb_frag_size(fp), DMA_TO_DEVICE);
  271. dma_unmap_single(dev, addr[-1], skb_headlen(skb), DMA_TO_DEVICE);
  272. out_err:
  273. return -ENOMEM;
  274. }
  275. static void unmap_sgl(struct device *dev, const struct sk_buff *skb,
  276. const struct ulptx_sgl *sgl, const struct sge_txq *tq)
  277. {
  278. const struct ulptx_sge_pair *p;
  279. unsigned int nfrags = skb_shinfo(skb)->nr_frags;
  280. if (likely(skb_headlen(skb)))
  281. dma_unmap_single(dev, be64_to_cpu(sgl->addr0),
  282. be32_to_cpu(sgl->len0), DMA_TO_DEVICE);
  283. else {
  284. dma_unmap_page(dev, be64_to_cpu(sgl->addr0),
  285. be32_to_cpu(sgl->len0), DMA_TO_DEVICE);
  286. nfrags--;
  287. }
  288. /*
  289. * the complexity below is because of the possibility of a wrap-around
  290. * in the middle of an SGL
  291. */
  292. for (p = sgl->sge; nfrags >= 2; nfrags -= 2) {
  293. if (likely((u8 *)(p + 1) <= (u8 *)tq->stat)) {
  294. unmap:
  295. dma_unmap_page(dev, be64_to_cpu(p->addr[0]),
  296. be32_to_cpu(p->len[0]), DMA_TO_DEVICE);
  297. dma_unmap_page(dev, be64_to_cpu(p->addr[1]),
  298. be32_to_cpu(p->len[1]), DMA_TO_DEVICE);
  299. p++;
  300. } else if ((u8 *)p == (u8 *)tq->stat) {
  301. p = (const struct ulptx_sge_pair *)tq->desc;
  302. goto unmap;
  303. } else if ((u8 *)p + 8 == (u8 *)tq->stat) {
  304. const __be64 *addr = (const __be64 *)tq->desc;
  305. dma_unmap_page(dev, be64_to_cpu(addr[0]),
  306. be32_to_cpu(p->len[0]), DMA_TO_DEVICE);
  307. dma_unmap_page(dev, be64_to_cpu(addr[1]),
  308. be32_to_cpu(p->len[1]), DMA_TO_DEVICE);
  309. p = (const struct ulptx_sge_pair *)&addr[2];
  310. } else {
  311. const __be64 *addr = (const __be64 *)tq->desc;
  312. dma_unmap_page(dev, be64_to_cpu(p->addr[0]),
  313. be32_to_cpu(p->len[0]), DMA_TO_DEVICE);
  314. dma_unmap_page(dev, be64_to_cpu(addr[0]),
  315. be32_to_cpu(p->len[1]), DMA_TO_DEVICE);
  316. p = (const struct ulptx_sge_pair *)&addr[1];
  317. }
  318. }
  319. if (nfrags) {
  320. __be64 addr;
  321. if ((u8 *)p == (u8 *)tq->stat)
  322. p = (const struct ulptx_sge_pair *)tq->desc;
  323. addr = ((u8 *)p + 16 <= (u8 *)tq->stat
  324. ? p->addr[0]
  325. : *(const __be64 *)tq->desc);
  326. dma_unmap_page(dev, be64_to_cpu(addr), be32_to_cpu(p->len[0]),
  327. DMA_TO_DEVICE);
  328. }
  329. }
  330. /**
  331. * free_tx_desc - reclaims TX descriptors and their buffers
  332. * @adapter: the adapter
  333. * @tq: the TX queue to reclaim descriptors from
  334. * @n: the number of descriptors to reclaim
  335. * @unmap: whether the buffers should be unmapped for DMA
  336. *
  337. * Reclaims TX descriptors from an SGE TX queue and frees the associated
  338. * TX buffers. Called with the TX queue lock held.
  339. */
  340. static void free_tx_desc(struct adapter *adapter, struct sge_txq *tq,
  341. unsigned int n, bool unmap)
  342. {
  343. struct tx_sw_desc *sdesc;
  344. unsigned int cidx = tq->cidx;
  345. struct device *dev = adapter->pdev_dev;
  346. const int need_unmap = need_skb_unmap() && unmap;
  347. sdesc = &tq->sdesc[cidx];
  348. while (n--) {
  349. /*
  350. * If we kept a reference to the original TX skb, we need to
  351. * unmap it from PCI DMA space (if required) and free it.
  352. */
  353. if (sdesc->skb) {
  354. if (need_unmap)
  355. unmap_sgl(dev, sdesc->skb, sdesc->sgl, tq);
  356. dev_consume_skb_any(sdesc->skb);
  357. sdesc->skb = NULL;
  358. }
  359. sdesc++;
  360. if (++cidx == tq->size) {
  361. cidx = 0;
  362. sdesc = tq->sdesc;
  363. }
  364. }
  365. tq->cidx = cidx;
  366. }
  367. /*
  368. * Return the number of reclaimable descriptors in a TX queue.
  369. */
  370. static inline int reclaimable(const struct sge_txq *tq)
  371. {
  372. int hw_cidx = be16_to_cpu(tq->stat->cidx);
  373. int reclaimable = hw_cidx - tq->cidx;
  374. if (reclaimable < 0)
  375. reclaimable += tq->size;
  376. return reclaimable;
  377. }
  378. /**
  379. * reclaim_completed_tx - reclaims completed TX descriptors
  380. * @adapter: the adapter
  381. * @tq: the TX queue to reclaim completed descriptors from
  382. * @unmap: whether the buffers should be unmapped for DMA
  383. *
  384. * Reclaims TX descriptors that the SGE has indicated it has processed,
  385. * and frees the associated buffers if possible. Called with the TX
  386. * queue locked.
  387. */
  388. static inline void reclaim_completed_tx(struct adapter *adapter,
  389. struct sge_txq *tq,
  390. bool unmap)
  391. {
  392. int avail = reclaimable(tq);
  393. if (avail) {
  394. /*
  395. * Limit the amount of clean up work we do at a time to keep
  396. * the TX lock hold time O(1).
  397. */
  398. if (avail > MAX_TX_RECLAIM)
  399. avail = MAX_TX_RECLAIM;
  400. free_tx_desc(adapter, tq, avail, unmap);
  401. tq->in_use -= avail;
  402. }
  403. }
  404. /**
  405. * get_buf_size - return the size of an RX Free List buffer.
  406. * @adapter: pointer to the associated adapter
  407. * @sdesc: pointer to the software buffer descriptor
  408. */
  409. static inline int get_buf_size(const struct adapter *adapter,
  410. const struct rx_sw_desc *sdesc)
  411. {
  412. const struct sge *s = &adapter->sge;
  413. return (s->fl_pg_order > 0 && (sdesc->dma_addr & RX_LARGE_BUF)
  414. ? (PAGE_SIZE << s->fl_pg_order) : PAGE_SIZE);
  415. }
  416. /**
  417. * free_rx_bufs - free RX buffers on an SGE Free List
  418. * @adapter: the adapter
  419. * @fl: the SGE Free List to free buffers from
  420. * @n: how many buffers to free
  421. *
  422. * Release the next @n buffers on an SGE Free List RX queue. The
  423. * buffers must be made inaccessible to hardware before calling this
  424. * function.
  425. */
  426. static void free_rx_bufs(struct adapter *adapter, struct sge_fl *fl, int n)
  427. {
  428. while (n--) {
  429. struct rx_sw_desc *sdesc = &fl->sdesc[fl->cidx];
  430. if (is_buf_mapped(sdesc))
  431. dma_unmap_page(adapter->pdev_dev, get_buf_addr(sdesc),
  432. get_buf_size(adapter, sdesc),
  433. DMA_FROM_DEVICE);
  434. put_page(sdesc->page);
  435. sdesc->page = NULL;
  436. if (++fl->cidx == fl->size)
  437. fl->cidx = 0;
  438. fl->avail--;
  439. }
  440. }
  441. /**
  442. * unmap_rx_buf - unmap the current RX buffer on an SGE Free List
  443. * @adapter: the adapter
  444. * @fl: the SGE Free List
  445. *
  446. * Unmap the current buffer on an SGE Free List RX queue. The
  447. * buffer must be made inaccessible to HW before calling this function.
  448. *
  449. * This is similar to @free_rx_bufs above but does not free the buffer.
  450. * Do note that the FL still loses any further access to the buffer.
  451. * This is used predominantly to "transfer ownership" of an FL buffer
  452. * to another entity (typically an skb's fragment list).
  453. */
  454. static void unmap_rx_buf(struct adapter *adapter, struct sge_fl *fl)
  455. {
  456. struct rx_sw_desc *sdesc = &fl->sdesc[fl->cidx];
  457. if (is_buf_mapped(sdesc))
  458. dma_unmap_page(adapter->pdev_dev, get_buf_addr(sdesc),
  459. get_buf_size(adapter, sdesc),
  460. DMA_FROM_DEVICE);
  461. sdesc->page = NULL;
  462. if (++fl->cidx == fl->size)
  463. fl->cidx = 0;
  464. fl->avail--;
  465. }
  466. /**
  467. * ring_fl_db - righ doorbell on free list
  468. * @adapter: the adapter
  469. * @fl: the Free List whose doorbell should be rung ...
  470. *
  471. * Tell the Scatter Gather Engine that there are new free list entries
  472. * available.
  473. */
  474. static inline void ring_fl_db(struct adapter *adapter, struct sge_fl *fl)
  475. {
  476. u32 val = adapter->params.arch.sge_fl_db;
  477. /* The SGE keeps track of its Producer and Consumer Indices in terms
  478. * of Egress Queue Units so we can only tell it about integral numbers
  479. * of multiples of Free List Entries per Egress Queue Units ...
  480. */
  481. if (fl->pend_cred >= FL_PER_EQ_UNIT) {
  482. if (is_t4(adapter->params.chip))
  483. val |= PIDX_V(fl->pend_cred / FL_PER_EQ_UNIT);
  484. else
  485. val |= PIDX_T5_V(fl->pend_cred / FL_PER_EQ_UNIT);
  486. /* Make sure all memory writes to the Free List queue are
  487. * committed before we tell the hardware about them.
  488. */
  489. wmb();
  490. /* If we don't have access to the new User Doorbell (T5+), use
  491. * the old doorbell mechanism; otherwise use the new BAR2
  492. * mechanism.
  493. */
  494. if (unlikely(fl->bar2_addr == NULL)) {
  495. t4_write_reg(adapter,
  496. T4VF_SGE_BASE_ADDR + SGE_VF_KDOORBELL,
  497. QID_V(fl->cntxt_id) | val);
  498. } else {
  499. writel(val | QID_V(fl->bar2_qid),
  500. fl->bar2_addr + SGE_UDB_KDOORBELL);
  501. /* This Write memory Barrier will force the write to
  502. * the User Doorbell area to be flushed.
  503. */
  504. wmb();
  505. }
  506. fl->pend_cred %= FL_PER_EQ_UNIT;
  507. }
  508. }
  509. /**
  510. * set_rx_sw_desc - initialize software RX buffer descriptor
  511. * @sdesc: pointer to the softwore RX buffer descriptor
  512. * @page: pointer to the page data structure backing the RX buffer
  513. * @dma_addr: PCI DMA address (possibly with low-bit flags)
  514. */
  515. static inline void set_rx_sw_desc(struct rx_sw_desc *sdesc, struct page *page,
  516. dma_addr_t dma_addr)
  517. {
  518. sdesc->page = page;
  519. sdesc->dma_addr = dma_addr;
  520. }
  521. /*
  522. * Support for poisoning RX buffers ...
  523. */
  524. #define POISON_BUF_VAL -1
  525. static inline void poison_buf(struct page *page, size_t sz)
  526. {
  527. #if POISON_BUF_VAL >= 0
  528. memset(page_address(page), POISON_BUF_VAL, sz);
  529. #endif
  530. }
  531. /**
  532. * refill_fl - refill an SGE RX buffer ring
  533. * @adapter: the adapter
  534. * @fl: the Free List ring to refill
  535. * @n: the number of new buffers to allocate
  536. * @gfp: the gfp flags for the allocations
  537. *
  538. * (Re)populate an SGE free-buffer queue with up to @n new packet buffers,
  539. * allocated with the supplied gfp flags. The caller must assure that
  540. * @n does not exceed the queue's capacity -- i.e. (cidx == pidx) _IN
  541. * EGRESS QUEUE UNITS_ indicates an empty Free List! Returns the number
  542. * of buffers allocated. If afterwards the queue is found critically low,
  543. * mark it as starving in the bitmap of starving FLs.
  544. */
  545. static unsigned int refill_fl(struct adapter *adapter, struct sge_fl *fl,
  546. int n, gfp_t gfp)
  547. {
  548. struct sge *s = &adapter->sge;
  549. struct page *page;
  550. dma_addr_t dma_addr;
  551. unsigned int cred = fl->avail;
  552. __be64 *d = &fl->desc[fl->pidx];
  553. struct rx_sw_desc *sdesc = &fl->sdesc[fl->pidx];
  554. /*
  555. * Sanity: ensure that the result of adding n Free List buffers
  556. * won't result in wrapping the SGE's Producer Index around to
  557. * it's Consumer Index thereby indicating an empty Free List ...
  558. */
  559. BUG_ON(fl->avail + n > fl->size - FL_PER_EQ_UNIT);
  560. gfp |= __GFP_NOWARN;
  561. /*
  562. * If we support large pages, prefer large buffers and fail over to
  563. * small pages if we can't allocate large pages to satisfy the refill.
  564. * If we don't support large pages, drop directly into the small page
  565. * allocation code.
  566. */
  567. if (s->fl_pg_order == 0)
  568. goto alloc_small_pages;
  569. while (n) {
  570. page = __dev_alloc_pages(gfp, s->fl_pg_order);
  571. if (unlikely(!page)) {
  572. /*
  573. * We've failed inour attempt to allocate a "large
  574. * page". Fail over to the "small page" allocation
  575. * below.
  576. */
  577. fl->large_alloc_failed++;
  578. break;
  579. }
  580. poison_buf(page, PAGE_SIZE << s->fl_pg_order);
  581. dma_addr = dma_map_page(adapter->pdev_dev, page, 0,
  582. PAGE_SIZE << s->fl_pg_order,
  583. DMA_FROM_DEVICE);
  584. if (unlikely(dma_mapping_error(adapter->pdev_dev, dma_addr))) {
  585. /*
  586. * We've run out of DMA mapping space. Free up the
  587. * buffer and return with what we've managed to put
  588. * into the free list. We don't want to fail over to
  589. * the small page allocation below in this case
  590. * because DMA mapping resources are typically
  591. * critical resources once they become scarse.
  592. */
  593. __free_pages(page, s->fl_pg_order);
  594. goto out;
  595. }
  596. dma_addr |= RX_LARGE_BUF;
  597. *d++ = cpu_to_be64(dma_addr);
  598. set_rx_sw_desc(sdesc, page, dma_addr);
  599. sdesc++;
  600. fl->avail++;
  601. if (++fl->pidx == fl->size) {
  602. fl->pidx = 0;
  603. sdesc = fl->sdesc;
  604. d = fl->desc;
  605. }
  606. n--;
  607. }
  608. alloc_small_pages:
  609. while (n--) {
  610. page = __dev_alloc_page(gfp);
  611. if (unlikely(!page)) {
  612. fl->alloc_failed++;
  613. break;
  614. }
  615. poison_buf(page, PAGE_SIZE);
  616. dma_addr = dma_map_page(adapter->pdev_dev, page, 0, PAGE_SIZE,
  617. DMA_FROM_DEVICE);
  618. if (unlikely(dma_mapping_error(adapter->pdev_dev, dma_addr))) {
  619. put_page(page);
  620. break;
  621. }
  622. *d++ = cpu_to_be64(dma_addr);
  623. set_rx_sw_desc(sdesc, page, dma_addr);
  624. sdesc++;
  625. fl->avail++;
  626. if (++fl->pidx == fl->size) {
  627. fl->pidx = 0;
  628. sdesc = fl->sdesc;
  629. d = fl->desc;
  630. }
  631. }
  632. out:
  633. /*
  634. * Update our accounting state to incorporate the new Free List
  635. * buffers, tell the hardware about them and return the number of
  636. * buffers which we were able to allocate.
  637. */
  638. cred = fl->avail - cred;
  639. fl->pend_cred += cred;
  640. ring_fl_db(adapter, fl);
  641. if (unlikely(fl_starving(adapter, fl))) {
  642. smp_wmb();
  643. set_bit(fl->cntxt_id, adapter->sge.starving_fl);
  644. }
  645. return cred;
  646. }
  647. /*
  648. * Refill a Free List to its capacity or the Maximum Refill Increment,
  649. * whichever is smaller ...
  650. */
  651. static inline void __refill_fl(struct adapter *adapter, struct sge_fl *fl)
  652. {
  653. refill_fl(adapter, fl,
  654. min((unsigned int)MAX_RX_REFILL, fl_cap(fl) - fl->avail),
  655. GFP_ATOMIC);
  656. }
  657. /**
  658. * alloc_ring - allocate resources for an SGE descriptor ring
  659. * @dev: the PCI device's core device
  660. * @nelem: the number of descriptors
  661. * @hwsize: the size of each hardware descriptor
  662. * @swsize: the size of each software descriptor
  663. * @busaddrp: the physical PCI bus address of the allocated ring
  664. * @swringp: return address pointer for software ring
  665. * @stat_size: extra space in hardware ring for status information
  666. *
  667. * Allocates resources for an SGE descriptor ring, such as TX queues,
  668. * free buffer lists, response queues, etc. Each SGE ring requires
  669. * space for its hardware descriptors plus, optionally, space for software
  670. * state associated with each hardware entry (the metadata). The function
  671. * returns three values: the virtual address for the hardware ring (the
  672. * return value of the function), the PCI bus address of the hardware
  673. * ring (in *busaddrp), and the address of the software ring (in swringp).
  674. * Both the hardware and software rings are returned zeroed out.
  675. */
  676. static void *alloc_ring(struct device *dev, size_t nelem, size_t hwsize,
  677. size_t swsize, dma_addr_t *busaddrp, void *swringp,
  678. size_t stat_size)
  679. {
  680. /*
  681. * Allocate the hardware ring and PCI DMA bus address space for said.
  682. */
  683. size_t hwlen = nelem * hwsize + stat_size;
  684. void *hwring = dma_alloc_coherent(dev, hwlen, busaddrp, GFP_KERNEL);
  685. if (!hwring)
  686. return NULL;
  687. /*
  688. * If the caller wants a software ring, allocate it and return a
  689. * pointer to it in *swringp.
  690. */
  691. BUG_ON((swsize != 0) != (swringp != NULL));
  692. if (swsize) {
  693. void *swring = kcalloc(nelem, swsize, GFP_KERNEL);
  694. if (!swring) {
  695. dma_free_coherent(dev, hwlen, hwring, *busaddrp);
  696. return NULL;
  697. }
  698. *(void **)swringp = swring;
  699. }
  700. return hwring;
  701. }
  702. /**
  703. * sgl_len - calculates the size of an SGL of the given capacity
  704. * @n: the number of SGL entries
  705. *
  706. * Calculates the number of flits (8-byte units) needed for a Direct
  707. * Scatter/Gather List that can hold the given number of entries.
  708. */
  709. static inline unsigned int sgl_len(unsigned int n)
  710. {
  711. /*
  712. * A Direct Scatter Gather List uses 32-bit lengths and 64-bit PCI DMA
  713. * addresses. The DSGL Work Request starts off with a 32-bit DSGL
  714. * ULPTX header, then Length0, then Address0, then, for 1 <= i <= N,
  715. * repeated sequences of { Length[i], Length[i+1], Address[i],
  716. * Address[i+1] } (this ensures that all addresses are on 64-bit
  717. * boundaries). If N is even, then Length[N+1] should be set to 0 and
  718. * Address[N+1] is omitted.
  719. *
  720. * The following calculation incorporates all of the above. It's
  721. * somewhat hard to follow but, briefly: the "+2" accounts for the
  722. * first two flits which include the DSGL header, Length0 and
  723. * Address0; the "(3*(n-1))/2" covers the main body of list entries (3
  724. * flits for every pair of the remaining N) +1 if (n-1) is odd; and
  725. * finally the "+((n-1)&1)" adds the one remaining flit needed if
  726. * (n-1) is odd ...
  727. */
  728. n--;
  729. return (3 * n) / 2 + (n & 1) + 2;
  730. }
  731. /**
  732. * flits_to_desc - returns the num of TX descriptors for the given flits
  733. * @flits: the number of flits
  734. *
  735. * Returns the number of TX descriptors needed for the supplied number
  736. * of flits.
  737. */
  738. static inline unsigned int flits_to_desc(unsigned int flits)
  739. {
  740. BUG_ON(flits > SGE_MAX_WR_LEN / sizeof(__be64));
  741. return DIV_ROUND_UP(flits, TXD_PER_EQ_UNIT);
  742. }
  743. /**
  744. * is_eth_imm - can an Ethernet packet be sent as immediate data?
  745. * @skb: the packet
  746. *
  747. * Returns whether an Ethernet packet is small enough to fit completely as
  748. * immediate data.
  749. */
  750. static inline int is_eth_imm(const struct sk_buff *skb)
  751. {
  752. /*
  753. * The VF Driver uses the FW_ETH_TX_PKT_VM_WR firmware Work Request
  754. * which does not accommodate immediate data. We could dike out all
  755. * of the support code for immediate data but that would tie our hands
  756. * too much if we ever want to enhace the firmware. It would also
  757. * create more differences between the PF and VF Drivers.
  758. */
  759. return false;
  760. }
  761. /**
  762. * calc_tx_flits - calculate the number of flits for a packet TX WR
  763. * @skb: the packet
  764. *
  765. * Returns the number of flits needed for a TX Work Request for the
  766. * given Ethernet packet, including the needed WR and CPL headers.
  767. */
  768. static inline unsigned int calc_tx_flits(const struct sk_buff *skb)
  769. {
  770. unsigned int flits;
  771. /*
  772. * If the skb is small enough, we can pump it out as a work request
  773. * with only immediate data. In that case we just have to have the
  774. * TX Packet header plus the skb data in the Work Request.
  775. */
  776. if (is_eth_imm(skb))
  777. return DIV_ROUND_UP(skb->len + sizeof(struct cpl_tx_pkt),
  778. sizeof(__be64));
  779. /*
  780. * Otherwise, we're going to have to construct a Scatter gather list
  781. * of the skb body and fragments. We also include the flits necessary
  782. * for the TX Packet Work Request and CPL. We always have a firmware
  783. * Write Header (incorporated as part of the cpl_tx_pkt_lso and
  784. * cpl_tx_pkt structures), followed by either a TX Packet Write CPL
  785. * message or, if we're doing a Large Send Offload, an LSO CPL message
  786. * with an embedded TX Packet Write CPL message.
  787. */
  788. flits = sgl_len(skb_shinfo(skb)->nr_frags + 1);
  789. if (skb_shinfo(skb)->gso_size)
  790. flits += (sizeof(struct fw_eth_tx_pkt_vm_wr) +
  791. sizeof(struct cpl_tx_pkt_lso_core) +
  792. sizeof(struct cpl_tx_pkt_core)) / sizeof(__be64);
  793. else
  794. flits += (sizeof(struct fw_eth_tx_pkt_vm_wr) +
  795. sizeof(struct cpl_tx_pkt_core)) / sizeof(__be64);
  796. return flits;
  797. }
  798. /**
  799. * write_sgl - populate a Scatter/Gather List for a packet
  800. * @skb: the packet
  801. * @tq: the TX queue we are writing into
  802. * @sgl: starting location for writing the SGL
  803. * @end: points right after the end of the SGL
  804. * @start: start offset into skb main-body data to include in the SGL
  805. * @addr: the list of DMA bus addresses for the SGL elements
  806. *
  807. * Generates a Scatter/Gather List for the buffers that make up a packet.
  808. * The caller must provide adequate space for the SGL that will be written.
  809. * The SGL includes all of the packet's page fragments and the data in its
  810. * main body except for the first @start bytes. @pos must be 16-byte
  811. * aligned and within a TX descriptor with available space. @end points
  812. * write after the end of the SGL but does not account for any potential
  813. * wrap around, i.e., @end > @tq->stat.
  814. */
  815. static void write_sgl(const struct sk_buff *skb, struct sge_txq *tq,
  816. struct ulptx_sgl *sgl, u64 *end, unsigned int start,
  817. const dma_addr_t *addr)
  818. {
  819. unsigned int i, len;
  820. struct ulptx_sge_pair *to;
  821. const struct skb_shared_info *si = skb_shinfo(skb);
  822. unsigned int nfrags = si->nr_frags;
  823. struct ulptx_sge_pair buf[MAX_SKB_FRAGS / 2 + 1];
  824. len = skb_headlen(skb) - start;
  825. if (likely(len)) {
  826. sgl->len0 = htonl(len);
  827. sgl->addr0 = cpu_to_be64(addr[0] + start);
  828. nfrags++;
  829. } else {
  830. sgl->len0 = htonl(skb_frag_size(&si->frags[0]));
  831. sgl->addr0 = cpu_to_be64(addr[1]);
  832. }
  833. sgl->cmd_nsge = htonl(ULPTX_CMD_V(ULP_TX_SC_DSGL) |
  834. ULPTX_NSGE_V(nfrags));
  835. if (likely(--nfrags == 0))
  836. return;
  837. /*
  838. * Most of the complexity below deals with the possibility we hit the
  839. * end of the queue in the middle of writing the SGL. For this case
  840. * only we create the SGL in a temporary buffer and then copy it.
  841. */
  842. to = (u8 *)end > (u8 *)tq->stat ? buf : sgl->sge;
  843. for (i = (nfrags != si->nr_frags); nfrags >= 2; nfrags -= 2, to++) {
  844. to->len[0] = cpu_to_be32(skb_frag_size(&si->frags[i]));
  845. to->len[1] = cpu_to_be32(skb_frag_size(&si->frags[++i]));
  846. to->addr[0] = cpu_to_be64(addr[i]);
  847. to->addr[1] = cpu_to_be64(addr[++i]);
  848. }
  849. if (nfrags) {
  850. to->len[0] = cpu_to_be32(skb_frag_size(&si->frags[i]));
  851. to->len[1] = cpu_to_be32(0);
  852. to->addr[0] = cpu_to_be64(addr[i + 1]);
  853. }
  854. if (unlikely((u8 *)end > (u8 *)tq->stat)) {
  855. unsigned int part0 = (u8 *)tq->stat - (u8 *)sgl->sge, part1;
  856. if (likely(part0))
  857. memcpy(sgl->sge, buf, part0);
  858. part1 = (u8 *)end - (u8 *)tq->stat;
  859. memcpy(tq->desc, (u8 *)buf + part0, part1);
  860. end = (void *)tq->desc + part1;
  861. }
  862. if ((uintptr_t)end & 8) /* 0-pad to multiple of 16 */
  863. *end = 0;
  864. }
  865. /**
  866. * ring_tx_db - check and potentially ring a TX queue's doorbell
  867. * @adapter: the adapter
  868. * @tq: the TX queue
  869. * @n: number of new descriptors to give to HW
  870. *
  871. * Ring the doorbel for a TX queue.
  872. */
  873. static inline void ring_tx_db(struct adapter *adapter, struct sge_txq *tq,
  874. int n)
  875. {
  876. /* Make sure that all writes to the TX Descriptors are committed
  877. * before we tell the hardware about them.
  878. */
  879. wmb();
  880. /* If we don't have access to the new User Doorbell (T5+), use the old
  881. * doorbell mechanism; otherwise use the new BAR2 mechanism.
  882. */
  883. if (unlikely(tq->bar2_addr == NULL)) {
  884. u32 val = PIDX_V(n);
  885. t4_write_reg(adapter, T4VF_SGE_BASE_ADDR + SGE_VF_KDOORBELL,
  886. QID_V(tq->cntxt_id) | val);
  887. } else {
  888. u32 val = PIDX_T5_V(n);
  889. /* T4 and later chips share the same PIDX field offset within
  890. * the doorbell, but T5 and later shrank the field in order to
  891. * gain a bit for Doorbell Priority. The field was absurdly
  892. * large in the first place (14 bits) so we just use the T5
  893. * and later limits and warn if a Queue ID is too large.
  894. */
  895. WARN_ON(val & DBPRIO_F);
  896. /* If we're only writing a single Egress Unit and the BAR2
  897. * Queue ID is 0, we can use the Write Combining Doorbell
  898. * Gather Buffer; otherwise we use the simple doorbell.
  899. */
  900. if (n == 1 && tq->bar2_qid == 0) {
  901. unsigned int index = (tq->pidx
  902. ? (tq->pidx - 1)
  903. : (tq->size - 1));
  904. __be64 *src = (__be64 *)&tq->desc[index];
  905. __be64 __iomem *dst = (__be64 __iomem *)(tq->bar2_addr +
  906. SGE_UDB_WCDOORBELL);
  907. unsigned int count = EQ_UNIT / sizeof(__be64);
  908. /* Copy the TX Descriptor in a tight loop in order to
  909. * try to get it to the adapter in a single Write
  910. * Combined transfer on the PCI-E Bus. If the Write
  911. * Combine fails (say because of an interrupt, etc.)
  912. * the hardware will simply take the last write as a
  913. * simple doorbell write with a PIDX Increment of 1
  914. * and will fetch the TX Descriptor from memory via
  915. * DMA.
  916. */
  917. while (count) {
  918. /* the (__force u64) is because the compiler
  919. * doesn't understand the endian swizzling
  920. * going on
  921. */
  922. writeq((__force u64)*src, dst);
  923. src++;
  924. dst++;
  925. count--;
  926. }
  927. } else
  928. writel(val | QID_V(tq->bar2_qid),
  929. tq->bar2_addr + SGE_UDB_KDOORBELL);
  930. /* This Write Memory Barrier will force the write to the User
  931. * Doorbell area to be flushed. This is needed to prevent
  932. * writes on different CPUs for the same queue from hitting
  933. * the adapter out of order. This is required when some Work
  934. * Requests take the Write Combine Gather Buffer path (user
  935. * doorbell area offset [SGE_UDB_WCDOORBELL..+63]) and some
  936. * take the traditional path where we simply increment the
  937. * PIDX (User Doorbell area SGE_UDB_KDOORBELL) and have the
  938. * hardware DMA read the actual Work Request.
  939. */
  940. wmb();
  941. }
  942. }
  943. /**
  944. * inline_tx_skb - inline a packet's data into TX descriptors
  945. * @skb: the packet
  946. * @tq: the TX queue where the packet will be inlined
  947. * @pos: starting position in the TX queue to inline the packet
  948. *
  949. * Inline a packet's contents directly into TX descriptors, starting at
  950. * the given position within the TX DMA ring.
  951. * Most of the complexity of this operation is dealing with wrap arounds
  952. * in the middle of the packet we want to inline.
  953. */
  954. static void inline_tx_skb(const struct sk_buff *skb, const struct sge_txq *tq,
  955. void *pos)
  956. {
  957. u64 *p;
  958. int left = (void *)tq->stat - pos;
  959. if (likely(skb->len <= left)) {
  960. if (likely(!skb->data_len))
  961. skb_copy_from_linear_data(skb, pos, skb->len);
  962. else
  963. skb_copy_bits(skb, 0, pos, skb->len);
  964. pos += skb->len;
  965. } else {
  966. skb_copy_bits(skb, 0, pos, left);
  967. skb_copy_bits(skb, left, tq->desc, skb->len - left);
  968. pos = (void *)tq->desc + (skb->len - left);
  969. }
  970. /* 0-pad to multiple of 16 */
  971. p = PTR_ALIGN(pos, 8);
  972. if ((uintptr_t)p & 8)
  973. *p = 0;
  974. }
  975. /*
  976. * Figure out what HW csum a packet wants and return the appropriate control
  977. * bits.
  978. */
  979. static u64 hwcsum(enum chip_type chip, const struct sk_buff *skb)
  980. {
  981. int csum_type;
  982. const struct iphdr *iph = ip_hdr(skb);
  983. if (iph->version == 4) {
  984. if (iph->protocol == IPPROTO_TCP)
  985. csum_type = TX_CSUM_TCPIP;
  986. else if (iph->protocol == IPPROTO_UDP)
  987. csum_type = TX_CSUM_UDPIP;
  988. else {
  989. nocsum:
  990. /*
  991. * unknown protocol, disable HW csum
  992. * and hope a bad packet is detected
  993. */
  994. return TXPKT_L4CSUM_DIS_F;
  995. }
  996. } else {
  997. /*
  998. * this doesn't work with extension headers
  999. */
  1000. const struct ipv6hdr *ip6h = (const struct ipv6hdr *)iph;
  1001. if (ip6h->nexthdr == IPPROTO_TCP)
  1002. csum_type = TX_CSUM_TCPIP6;
  1003. else if (ip6h->nexthdr == IPPROTO_UDP)
  1004. csum_type = TX_CSUM_UDPIP6;
  1005. else
  1006. goto nocsum;
  1007. }
  1008. if (likely(csum_type >= TX_CSUM_TCPIP)) {
  1009. u64 hdr_len = TXPKT_IPHDR_LEN_V(skb_network_header_len(skb));
  1010. int eth_hdr_len = skb_network_offset(skb) - ETH_HLEN;
  1011. if (chip <= CHELSIO_T5)
  1012. hdr_len |= TXPKT_ETHHDR_LEN_V(eth_hdr_len);
  1013. else
  1014. hdr_len |= T6_TXPKT_ETHHDR_LEN_V(eth_hdr_len);
  1015. return TXPKT_CSUM_TYPE_V(csum_type) | hdr_len;
  1016. } else {
  1017. int start = skb_transport_offset(skb);
  1018. return TXPKT_CSUM_TYPE_V(csum_type) |
  1019. TXPKT_CSUM_START_V(start) |
  1020. TXPKT_CSUM_LOC_V(start + skb->csum_offset);
  1021. }
  1022. }
  1023. /*
  1024. * Stop an Ethernet TX queue and record that state change.
  1025. */
  1026. static void txq_stop(struct sge_eth_txq *txq)
  1027. {
  1028. netif_tx_stop_queue(txq->txq);
  1029. txq->q.stops++;
  1030. }
  1031. /*
  1032. * Advance our software state for a TX queue by adding n in use descriptors.
  1033. */
  1034. static inline void txq_advance(struct sge_txq *tq, unsigned int n)
  1035. {
  1036. tq->in_use += n;
  1037. tq->pidx += n;
  1038. if (tq->pidx >= tq->size)
  1039. tq->pidx -= tq->size;
  1040. }
  1041. /**
  1042. * t4vf_eth_xmit - add a packet to an Ethernet TX queue
  1043. * @skb: the packet
  1044. * @dev: the egress net device
  1045. *
  1046. * Add a packet to an SGE Ethernet TX queue. Runs with softirqs disabled.
  1047. */
  1048. netdev_tx_t t4vf_eth_xmit(struct sk_buff *skb, struct net_device *dev)
  1049. {
  1050. u32 wr_mid;
  1051. u64 cntrl, *end;
  1052. int qidx, credits, max_pkt_len;
  1053. unsigned int flits, ndesc;
  1054. struct adapter *adapter;
  1055. struct sge_eth_txq *txq;
  1056. const struct port_info *pi;
  1057. struct fw_eth_tx_pkt_vm_wr *wr;
  1058. struct cpl_tx_pkt_core *cpl;
  1059. const struct skb_shared_info *ssi;
  1060. dma_addr_t addr[MAX_SKB_FRAGS + 1];
  1061. const size_t fw_hdr_copy_len = sizeof(wr->firmware);
  1062. /*
  1063. * The chip minimum packet length is 10 octets but the firmware
  1064. * command that we are using requires that we copy the Ethernet header
  1065. * (including the VLAN tag) into the header so we reject anything
  1066. * smaller than that ...
  1067. */
  1068. if (unlikely(skb->len < fw_hdr_copy_len))
  1069. goto out_free;
  1070. /* Discard the packet if the length is greater than mtu */
  1071. max_pkt_len = ETH_HLEN + dev->mtu;
  1072. if (skb_vlan_tagged(skb))
  1073. max_pkt_len += VLAN_HLEN;
  1074. if (!skb_shinfo(skb)->gso_size && (unlikely(skb->len > max_pkt_len)))
  1075. goto out_free;
  1076. /*
  1077. * Figure out which TX Queue we're going to use.
  1078. */
  1079. pi = netdev_priv(dev);
  1080. adapter = pi->adapter;
  1081. qidx = skb_get_queue_mapping(skb);
  1082. BUG_ON(qidx >= pi->nqsets);
  1083. txq = &adapter->sge.ethtxq[pi->first_qset + qidx];
  1084. if (pi->vlan_id && !skb_vlan_tag_present(skb))
  1085. __vlan_hwaccel_put_tag(skb, cpu_to_be16(ETH_P_8021Q),
  1086. pi->vlan_id);
  1087. /*
  1088. * Take this opportunity to reclaim any TX Descriptors whose DMA
  1089. * transfers have completed.
  1090. */
  1091. reclaim_completed_tx(adapter, &txq->q, true);
  1092. /*
  1093. * Calculate the number of flits and TX Descriptors we're going to
  1094. * need along with how many TX Descriptors will be left over after
  1095. * we inject our Work Request.
  1096. */
  1097. flits = calc_tx_flits(skb);
  1098. ndesc = flits_to_desc(flits);
  1099. credits = txq_avail(&txq->q) - ndesc;
  1100. if (unlikely(credits < 0)) {
  1101. /*
  1102. * Not enough room for this packet's Work Request. Stop the
  1103. * TX Queue and return a "busy" condition. The queue will get
  1104. * started later on when the firmware informs us that space
  1105. * has opened up.
  1106. */
  1107. txq_stop(txq);
  1108. dev_err(adapter->pdev_dev,
  1109. "%s: TX ring %u full while queue awake!\n",
  1110. dev->name, qidx);
  1111. return NETDEV_TX_BUSY;
  1112. }
  1113. if (!is_eth_imm(skb) &&
  1114. unlikely(map_skb(adapter->pdev_dev, skb, addr) < 0)) {
  1115. /*
  1116. * We need to map the skb into PCI DMA space (because it can't
  1117. * be in-lined directly into the Work Request) and the mapping
  1118. * operation failed. Record the error and drop the packet.
  1119. */
  1120. txq->mapping_err++;
  1121. goto out_free;
  1122. }
  1123. wr_mid = FW_WR_LEN16_V(DIV_ROUND_UP(flits, 2));
  1124. if (unlikely(credits < ETHTXQ_STOP_THRES)) {
  1125. /*
  1126. * After we're done injecting the Work Request for this
  1127. * packet, we'll be below our "stop threshold" so stop the TX
  1128. * Queue now and schedule a request for an SGE Egress Queue
  1129. * Update message. The queue will get started later on when
  1130. * the firmware processes this Work Request and sends us an
  1131. * Egress Queue Status Update message indicating that space
  1132. * has opened up.
  1133. */
  1134. txq_stop(txq);
  1135. wr_mid |= FW_WR_EQUEQ_F | FW_WR_EQUIQ_F;
  1136. }
  1137. /*
  1138. * Start filling in our Work Request. Note that we do _not_ handle
  1139. * the WR Header wrapping around the TX Descriptor Ring. If our
  1140. * maximum header size ever exceeds one TX Descriptor, we'll need to
  1141. * do something else here.
  1142. */
  1143. BUG_ON(DIV_ROUND_UP(ETHTXQ_MAX_HDR, TXD_PER_EQ_UNIT) > 1);
  1144. wr = (void *)&txq->q.desc[txq->q.pidx];
  1145. wr->equiq_to_len16 = cpu_to_be32(wr_mid);
  1146. wr->r3[0] = cpu_to_be32(0);
  1147. wr->r3[1] = cpu_to_be32(0);
  1148. skb_copy_from_linear_data(skb, &wr->firmware, fw_hdr_copy_len);
  1149. end = (u64 *)wr + flits;
  1150. /*
  1151. * If this is a Large Send Offload packet we'll put in an LSO CPL
  1152. * message with an encapsulated TX Packet CPL message. Otherwise we
  1153. * just use a TX Packet CPL message.
  1154. */
  1155. ssi = skb_shinfo(skb);
  1156. if (ssi->gso_size) {
  1157. struct cpl_tx_pkt_lso_core *lso = (void *)(wr + 1);
  1158. bool v6 = (ssi->gso_type & SKB_GSO_TCPV6) != 0;
  1159. int l3hdr_len = skb_network_header_len(skb);
  1160. int eth_xtra_len = skb_network_offset(skb) - ETH_HLEN;
  1161. wr->op_immdlen =
  1162. cpu_to_be32(FW_WR_OP_V(FW_ETH_TX_PKT_VM_WR) |
  1163. FW_WR_IMMDLEN_V(sizeof(*lso) +
  1164. sizeof(*cpl)));
  1165. /*
  1166. * Fill in the LSO CPL message.
  1167. */
  1168. lso->lso_ctrl =
  1169. cpu_to_be32(LSO_OPCODE_V(CPL_TX_PKT_LSO) |
  1170. LSO_FIRST_SLICE_F |
  1171. LSO_LAST_SLICE_F |
  1172. LSO_IPV6_V(v6) |
  1173. LSO_ETHHDR_LEN_V(eth_xtra_len / 4) |
  1174. LSO_IPHDR_LEN_V(l3hdr_len / 4) |
  1175. LSO_TCPHDR_LEN_V(tcp_hdr(skb)->doff));
  1176. lso->ipid_ofst = cpu_to_be16(0);
  1177. lso->mss = cpu_to_be16(ssi->gso_size);
  1178. lso->seqno_offset = cpu_to_be32(0);
  1179. if (is_t4(adapter->params.chip))
  1180. lso->len = cpu_to_be32(skb->len);
  1181. else
  1182. lso->len = cpu_to_be32(LSO_T5_XFER_SIZE_V(skb->len));
  1183. /*
  1184. * Set up TX Packet CPL pointer, control word and perform
  1185. * accounting.
  1186. */
  1187. cpl = (void *)(lso + 1);
  1188. if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5)
  1189. cntrl = TXPKT_ETHHDR_LEN_V(eth_xtra_len);
  1190. else
  1191. cntrl = T6_TXPKT_ETHHDR_LEN_V(eth_xtra_len);
  1192. cntrl |= TXPKT_CSUM_TYPE_V(v6 ?
  1193. TX_CSUM_TCPIP6 : TX_CSUM_TCPIP) |
  1194. TXPKT_IPHDR_LEN_V(l3hdr_len);
  1195. txq->tso++;
  1196. txq->tx_cso += ssi->gso_segs;
  1197. } else {
  1198. int len;
  1199. len = is_eth_imm(skb) ? skb->len + sizeof(*cpl) : sizeof(*cpl);
  1200. wr->op_immdlen =
  1201. cpu_to_be32(FW_WR_OP_V(FW_ETH_TX_PKT_VM_WR) |
  1202. FW_WR_IMMDLEN_V(len));
  1203. /*
  1204. * Set up TX Packet CPL pointer, control word and perform
  1205. * accounting.
  1206. */
  1207. cpl = (void *)(wr + 1);
  1208. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  1209. cntrl = hwcsum(adapter->params.chip, skb) |
  1210. TXPKT_IPCSUM_DIS_F;
  1211. txq->tx_cso++;
  1212. } else
  1213. cntrl = TXPKT_L4CSUM_DIS_F | TXPKT_IPCSUM_DIS_F;
  1214. }
  1215. /*
  1216. * If there's a VLAN tag present, add that to the list of things to
  1217. * do in this Work Request.
  1218. */
  1219. if (skb_vlan_tag_present(skb)) {
  1220. txq->vlan_ins++;
  1221. cntrl |= TXPKT_VLAN_VLD_F | TXPKT_VLAN_V(skb_vlan_tag_get(skb));
  1222. }
  1223. /*
  1224. * Fill in the TX Packet CPL message header.
  1225. */
  1226. cpl->ctrl0 = cpu_to_be32(TXPKT_OPCODE_V(CPL_TX_PKT_XT) |
  1227. TXPKT_INTF_V(pi->port_id) |
  1228. TXPKT_PF_V(0));
  1229. cpl->pack = cpu_to_be16(0);
  1230. cpl->len = cpu_to_be16(skb->len);
  1231. cpl->ctrl1 = cpu_to_be64(cntrl);
  1232. #ifdef T4_TRACE
  1233. T4_TRACE5(adapter->tb[txq->q.cntxt_id & 7],
  1234. "eth_xmit: ndesc %u, credits %u, pidx %u, len %u, frags %u",
  1235. ndesc, credits, txq->q.pidx, skb->len, ssi->nr_frags);
  1236. #endif
  1237. /*
  1238. * Fill in the body of the TX Packet CPL message with either in-lined
  1239. * data or a Scatter/Gather List.
  1240. */
  1241. if (is_eth_imm(skb)) {
  1242. /*
  1243. * In-line the packet's data and free the skb since we don't
  1244. * need it any longer.
  1245. */
  1246. inline_tx_skb(skb, &txq->q, cpl + 1);
  1247. dev_consume_skb_any(skb);
  1248. } else {
  1249. /*
  1250. * Write the skb's Scatter/Gather list into the TX Packet CPL
  1251. * message and retain a pointer to the skb so we can free it
  1252. * later when its DMA completes. (We store the skb pointer
  1253. * in the Software Descriptor corresponding to the last TX
  1254. * Descriptor used by the Work Request.)
  1255. *
  1256. * The retained skb will be freed when the corresponding TX
  1257. * Descriptors are reclaimed after their DMAs complete.
  1258. * However, this could take quite a while since, in general,
  1259. * the hardware is set up to be lazy about sending DMA
  1260. * completion notifications to us and we mostly perform TX
  1261. * reclaims in the transmit routine.
  1262. *
  1263. * This is good for performamce but means that we rely on new
  1264. * TX packets arriving to run the destructors of completed
  1265. * packets, which open up space in their sockets' send queues.
  1266. * Sometimes we do not get such new packets causing TX to
  1267. * stall. A single UDP transmitter is a good example of this
  1268. * situation. We have a clean up timer that periodically
  1269. * reclaims completed packets but it doesn't run often enough
  1270. * (nor do we want it to) to prevent lengthy stalls. A
  1271. * solution to this problem is to run the destructor early,
  1272. * after the packet is queued but before it's DMAd. A con is
  1273. * that we lie to socket memory accounting, but the amount of
  1274. * extra memory is reasonable (limited by the number of TX
  1275. * descriptors), the packets do actually get freed quickly by
  1276. * new packets almost always, and for protocols like TCP that
  1277. * wait for acks to really free up the data the extra memory
  1278. * is even less. On the positive side we run the destructors
  1279. * on the sending CPU rather than on a potentially different
  1280. * completing CPU, usually a good thing.
  1281. *
  1282. * Run the destructor before telling the DMA engine about the
  1283. * packet to make sure it doesn't complete and get freed
  1284. * prematurely.
  1285. */
  1286. struct ulptx_sgl *sgl = (struct ulptx_sgl *)(cpl + 1);
  1287. struct sge_txq *tq = &txq->q;
  1288. int last_desc;
  1289. /*
  1290. * If the Work Request header was an exact multiple of our TX
  1291. * Descriptor length, then it's possible that the starting SGL
  1292. * pointer lines up exactly with the end of our TX Descriptor
  1293. * ring. If that's the case, wrap around to the beginning
  1294. * here ...
  1295. */
  1296. if (unlikely((void *)sgl == (void *)tq->stat)) {
  1297. sgl = (void *)tq->desc;
  1298. end = ((void *)tq->desc + ((void *)end - (void *)tq->stat));
  1299. }
  1300. write_sgl(skb, tq, sgl, end, 0, addr);
  1301. skb_orphan(skb);
  1302. last_desc = tq->pidx + ndesc - 1;
  1303. if (last_desc >= tq->size)
  1304. last_desc -= tq->size;
  1305. tq->sdesc[last_desc].skb = skb;
  1306. tq->sdesc[last_desc].sgl = sgl;
  1307. }
  1308. /*
  1309. * Advance our internal TX Queue state, tell the hardware about
  1310. * the new TX descriptors and return success.
  1311. */
  1312. txq_advance(&txq->q, ndesc);
  1313. netif_trans_update(dev);
  1314. ring_tx_db(adapter, &txq->q, ndesc);
  1315. return NETDEV_TX_OK;
  1316. out_free:
  1317. /*
  1318. * An error of some sort happened. Free the TX skb and tell the
  1319. * OS that we've "dealt" with the packet ...
  1320. */
  1321. dev_kfree_skb_any(skb);
  1322. return NETDEV_TX_OK;
  1323. }
  1324. /**
  1325. * copy_frags - copy fragments from gather list into skb_shared_info
  1326. * @skb: destination skb
  1327. * @gl: source internal packet gather list
  1328. * @offset: packet start offset in first page
  1329. *
  1330. * Copy an internal packet gather list into a Linux skb_shared_info
  1331. * structure.
  1332. */
  1333. static inline void copy_frags(struct sk_buff *skb,
  1334. const struct pkt_gl *gl,
  1335. unsigned int offset)
  1336. {
  1337. int i;
  1338. /* usually there's just one frag */
  1339. __skb_fill_page_desc(skb, 0, gl->frags[0].page,
  1340. gl->frags[0].offset + offset,
  1341. gl->frags[0].size - offset);
  1342. skb_shinfo(skb)->nr_frags = gl->nfrags;
  1343. for (i = 1; i < gl->nfrags; i++)
  1344. __skb_fill_page_desc(skb, i, gl->frags[i].page,
  1345. gl->frags[i].offset,
  1346. gl->frags[i].size);
  1347. /* get a reference to the last page, we don't own it */
  1348. get_page(gl->frags[gl->nfrags - 1].page);
  1349. }
  1350. /**
  1351. * t4vf_pktgl_to_skb - build an sk_buff from a packet gather list
  1352. * @gl: the gather list
  1353. * @skb_len: size of sk_buff main body if it carries fragments
  1354. * @pull_len: amount of data to move to the sk_buff's main body
  1355. *
  1356. * Builds an sk_buff from the given packet gather list. Returns the
  1357. * sk_buff or %NULL if sk_buff allocation failed.
  1358. */
  1359. static struct sk_buff *t4vf_pktgl_to_skb(const struct pkt_gl *gl,
  1360. unsigned int skb_len,
  1361. unsigned int pull_len)
  1362. {
  1363. struct sk_buff *skb;
  1364. /*
  1365. * If the ingress packet is small enough, allocate an skb large enough
  1366. * for all of the data and copy it inline. Otherwise, allocate an skb
  1367. * with enough room to pull in the header and reference the rest of
  1368. * the data via the skb fragment list.
  1369. *
  1370. * Below we rely on RX_COPY_THRES being less than the smallest Rx
  1371. * buff! size, which is expected since buffers are at least
  1372. * PAGE_SIZEd. In this case packets up to RX_COPY_THRES have only one
  1373. * fragment.
  1374. */
  1375. if (gl->tot_len <= RX_COPY_THRES) {
  1376. /* small packets have only one fragment */
  1377. skb = alloc_skb(gl->tot_len, GFP_ATOMIC);
  1378. if (unlikely(!skb))
  1379. goto out;
  1380. __skb_put(skb, gl->tot_len);
  1381. skb_copy_to_linear_data(skb, gl->va, gl->tot_len);
  1382. } else {
  1383. skb = alloc_skb(skb_len, GFP_ATOMIC);
  1384. if (unlikely(!skb))
  1385. goto out;
  1386. __skb_put(skb, pull_len);
  1387. skb_copy_to_linear_data(skb, gl->va, pull_len);
  1388. copy_frags(skb, gl, pull_len);
  1389. skb->len = gl->tot_len;
  1390. skb->data_len = skb->len - pull_len;
  1391. skb->truesize += skb->data_len;
  1392. }
  1393. out:
  1394. return skb;
  1395. }
  1396. /**
  1397. * t4vf_pktgl_free - free a packet gather list
  1398. * @gl: the gather list
  1399. *
  1400. * Releases the pages of a packet gather list. We do not own the last
  1401. * page on the list and do not free it.
  1402. */
  1403. static void t4vf_pktgl_free(const struct pkt_gl *gl)
  1404. {
  1405. int frag;
  1406. frag = gl->nfrags - 1;
  1407. while (frag--)
  1408. put_page(gl->frags[frag].page);
  1409. }
  1410. /**
  1411. * do_gro - perform Generic Receive Offload ingress packet processing
  1412. * @rxq: ingress RX Ethernet Queue
  1413. * @gl: gather list for ingress packet
  1414. * @pkt: CPL header for last packet fragment
  1415. *
  1416. * Perform Generic Receive Offload (GRO) ingress packet processing.
  1417. * We use the standard Linux GRO interfaces for this.
  1418. */
  1419. static void do_gro(struct sge_eth_rxq *rxq, const struct pkt_gl *gl,
  1420. const struct cpl_rx_pkt *pkt)
  1421. {
  1422. struct adapter *adapter = rxq->rspq.adapter;
  1423. struct sge *s = &adapter->sge;
  1424. struct port_info *pi;
  1425. int ret;
  1426. struct sk_buff *skb;
  1427. skb = napi_get_frags(&rxq->rspq.napi);
  1428. if (unlikely(!skb)) {
  1429. t4vf_pktgl_free(gl);
  1430. rxq->stats.rx_drops++;
  1431. return;
  1432. }
  1433. copy_frags(skb, gl, s->pktshift);
  1434. skb->len = gl->tot_len - s->pktshift;
  1435. skb->data_len = skb->len;
  1436. skb->truesize += skb->data_len;
  1437. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1438. skb_record_rx_queue(skb, rxq->rspq.idx);
  1439. pi = netdev_priv(skb->dev);
  1440. if (pkt->vlan_ex && !pi->vlan_id) {
  1441. __vlan_hwaccel_put_tag(skb, cpu_to_be16(ETH_P_8021Q),
  1442. be16_to_cpu(pkt->vlan));
  1443. rxq->stats.vlan_ex++;
  1444. }
  1445. ret = napi_gro_frags(&rxq->rspq.napi);
  1446. if (ret == GRO_HELD)
  1447. rxq->stats.lro_pkts++;
  1448. else if (ret == GRO_MERGED || ret == GRO_MERGED_FREE)
  1449. rxq->stats.lro_merged++;
  1450. rxq->stats.pkts++;
  1451. rxq->stats.rx_cso++;
  1452. }
  1453. /**
  1454. * t4vf_ethrx_handler - process an ingress ethernet packet
  1455. * @rspq: the response queue that received the packet
  1456. * @rsp: the response queue descriptor holding the RX_PKT message
  1457. * @gl: the gather list of packet fragments
  1458. *
  1459. * Process an ingress ethernet packet and deliver it to the stack.
  1460. */
  1461. int t4vf_ethrx_handler(struct sge_rspq *rspq, const __be64 *rsp,
  1462. const struct pkt_gl *gl)
  1463. {
  1464. struct sk_buff *skb;
  1465. const struct cpl_rx_pkt *pkt = (void *)rsp;
  1466. bool csum_ok = pkt->csum_calc && !pkt->err_vec &&
  1467. (rspq->netdev->features & NETIF_F_RXCSUM);
  1468. struct sge_eth_rxq *rxq = container_of(rspq, struct sge_eth_rxq, rspq);
  1469. struct adapter *adapter = rspq->adapter;
  1470. struct sge *s = &adapter->sge;
  1471. struct port_info *pi;
  1472. /*
  1473. * If this is a good TCP packet and we have Generic Receive Offload
  1474. * enabled, handle the packet in the GRO path.
  1475. */
  1476. if ((pkt->l2info & cpu_to_be32(RXF_TCP_F)) &&
  1477. (rspq->netdev->features & NETIF_F_GRO) && csum_ok &&
  1478. !pkt->ip_frag) {
  1479. do_gro(rxq, gl, pkt);
  1480. return 0;
  1481. }
  1482. /*
  1483. * Convert the Packet Gather List into an skb.
  1484. */
  1485. skb = t4vf_pktgl_to_skb(gl, RX_SKB_LEN, RX_PULL_LEN);
  1486. if (unlikely(!skb)) {
  1487. t4vf_pktgl_free(gl);
  1488. rxq->stats.rx_drops++;
  1489. return 0;
  1490. }
  1491. __skb_pull(skb, s->pktshift);
  1492. skb->protocol = eth_type_trans(skb, rspq->netdev);
  1493. skb_record_rx_queue(skb, rspq->idx);
  1494. pi = netdev_priv(skb->dev);
  1495. rxq->stats.pkts++;
  1496. if (csum_ok && !pkt->err_vec &&
  1497. (be32_to_cpu(pkt->l2info) & (RXF_UDP_F | RXF_TCP_F))) {
  1498. if (!pkt->ip_frag) {
  1499. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1500. rxq->stats.rx_cso++;
  1501. } else if (pkt->l2info & htonl(RXF_IP_F)) {
  1502. __sum16 c = (__force __sum16)pkt->csum;
  1503. skb->csum = csum_unfold(c);
  1504. skb->ip_summed = CHECKSUM_COMPLETE;
  1505. rxq->stats.rx_cso++;
  1506. }
  1507. } else
  1508. skb_checksum_none_assert(skb);
  1509. if (pkt->vlan_ex && !pi->vlan_id) {
  1510. rxq->stats.vlan_ex++;
  1511. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
  1512. be16_to_cpu(pkt->vlan));
  1513. }
  1514. netif_receive_skb(skb);
  1515. return 0;
  1516. }
  1517. /**
  1518. * is_new_response - check if a response is newly written
  1519. * @rc: the response control descriptor
  1520. * @rspq: the response queue
  1521. *
  1522. * Returns true if a response descriptor contains a yet unprocessed
  1523. * response.
  1524. */
  1525. static inline bool is_new_response(const struct rsp_ctrl *rc,
  1526. const struct sge_rspq *rspq)
  1527. {
  1528. return ((rc->type_gen >> RSPD_GEN_S) & 0x1) == rspq->gen;
  1529. }
  1530. /**
  1531. * restore_rx_bufs - put back a packet's RX buffers
  1532. * @gl: the packet gather list
  1533. * @fl: the SGE Free List
  1534. * @frags: how many fragments in @si
  1535. *
  1536. * Called when we find out that the current packet, @si, can't be
  1537. * processed right away for some reason. This is a very rare event and
  1538. * there's no effort to make this suspension/resumption process
  1539. * particularly efficient.
  1540. *
  1541. * We implement the suspension by putting all of the RX buffers associated
  1542. * with the current packet back on the original Free List. The buffers
  1543. * have already been unmapped and are left unmapped, we mark them as
  1544. * unmapped in order to prevent further unmapping attempts. (Effectively
  1545. * this function undoes the series of @unmap_rx_buf calls which were done
  1546. * to create the current packet's gather list.) This leaves us ready to
  1547. * restart processing of the packet the next time we start processing the
  1548. * RX Queue ...
  1549. */
  1550. static void restore_rx_bufs(const struct pkt_gl *gl, struct sge_fl *fl,
  1551. int frags)
  1552. {
  1553. struct rx_sw_desc *sdesc;
  1554. while (frags--) {
  1555. if (fl->cidx == 0)
  1556. fl->cidx = fl->size - 1;
  1557. else
  1558. fl->cidx--;
  1559. sdesc = &fl->sdesc[fl->cidx];
  1560. sdesc->page = gl->frags[frags].page;
  1561. sdesc->dma_addr |= RX_UNMAPPED_BUF;
  1562. fl->avail++;
  1563. }
  1564. }
  1565. /**
  1566. * rspq_next - advance to the next entry in a response queue
  1567. * @rspq: the queue
  1568. *
  1569. * Updates the state of a response queue to advance it to the next entry.
  1570. */
  1571. static inline void rspq_next(struct sge_rspq *rspq)
  1572. {
  1573. rspq->cur_desc = (void *)rspq->cur_desc + rspq->iqe_len;
  1574. if (unlikely(++rspq->cidx == rspq->size)) {
  1575. rspq->cidx = 0;
  1576. rspq->gen ^= 1;
  1577. rspq->cur_desc = rspq->desc;
  1578. }
  1579. }
  1580. /**
  1581. * process_responses - process responses from an SGE response queue
  1582. * @rspq: the ingress response queue to process
  1583. * @budget: how many responses can be processed in this round
  1584. *
  1585. * Process responses from a Scatter Gather Engine response queue up to
  1586. * the supplied budget. Responses include received packets as well as
  1587. * control messages from firmware or hardware.
  1588. *
  1589. * Additionally choose the interrupt holdoff time for the next interrupt
  1590. * on this queue. If the system is under memory shortage use a fairly
  1591. * long delay to help recovery.
  1592. */
  1593. static int process_responses(struct sge_rspq *rspq, int budget)
  1594. {
  1595. struct sge_eth_rxq *rxq = container_of(rspq, struct sge_eth_rxq, rspq);
  1596. struct adapter *adapter = rspq->adapter;
  1597. struct sge *s = &adapter->sge;
  1598. int budget_left = budget;
  1599. while (likely(budget_left)) {
  1600. int ret, rsp_type;
  1601. const struct rsp_ctrl *rc;
  1602. rc = (void *)rspq->cur_desc + (rspq->iqe_len - sizeof(*rc));
  1603. if (!is_new_response(rc, rspq))
  1604. break;
  1605. /*
  1606. * Figure out what kind of response we've received from the
  1607. * SGE.
  1608. */
  1609. dma_rmb();
  1610. rsp_type = RSPD_TYPE_G(rc->type_gen);
  1611. if (likely(rsp_type == RSPD_TYPE_FLBUF_X)) {
  1612. struct page_frag *fp;
  1613. struct pkt_gl gl;
  1614. const struct rx_sw_desc *sdesc;
  1615. u32 bufsz, frag;
  1616. u32 len = be32_to_cpu(rc->pldbuflen_qid);
  1617. /*
  1618. * If we get a "new buffer" message from the SGE we
  1619. * need to move on to the next Free List buffer.
  1620. */
  1621. if (len & RSPD_NEWBUF_F) {
  1622. /*
  1623. * We get one "new buffer" message when we
  1624. * first start up a queue so we need to ignore
  1625. * it when our offset into the buffer is 0.
  1626. */
  1627. if (likely(rspq->offset > 0)) {
  1628. free_rx_bufs(rspq->adapter, &rxq->fl,
  1629. 1);
  1630. rspq->offset = 0;
  1631. }
  1632. len = RSPD_LEN_G(len);
  1633. }
  1634. gl.tot_len = len;
  1635. /*
  1636. * Gather packet fragments.
  1637. */
  1638. for (frag = 0, fp = gl.frags; /**/; frag++, fp++) {
  1639. BUG_ON(frag >= MAX_SKB_FRAGS);
  1640. BUG_ON(rxq->fl.avail == 0);
  1641. sdesc = &rxq->fl.sdesc[rxq->fl.cidx];
  1642. bufsz = get_buf_size(adapter, sdesc);
  1643. fp->page = sdesc->page;
  1644. fp->offset = rspq->offset;
  1645. fp->size = min(bufsz, len);
  1646. len -= fp->size;
  1647. if (!len)
  1648. break;
  1649. unmap_rx_buf(rspq->adapter, &rxq->fl);
  1650. }
  1651. gl.nfrags = frag+1;
  1652. /*
  1653. * Last buffer remains mapped so explicitly make it
  1654. * coherent for CPU access and start preloading first
  1655. * cache line ...
  1656. */
  1657. dma_sync_single_for_cpu(rspq->adapter->pdev_dev,
  1658. get_buf_addr(sdesc),
  1659. fp->size, DMA_FROM_DEVICE);
  1660. gl.va = (page_address(gl.frags[0].page) +
  1661. gl.frags[0].offset);
  1662. prefetch(gl.va);
  1663. /*
  1664. * Hand the new ingress packet to the handler for
  1665. * this Response Queue.
  1666. */
  1667. ret = rspq->handler(rspq, rspq->cur_desc, &gl);
  1668. if (likely(ret == 0))
  1669. rspq->offset += ALIGN(fp->size, s->fl_align);
  1670. else
  1671. restore_rx_bufs(&gl, &rxq->fl, frag);
  1672. } else if (likely(rsp_type == RSPD_TYPE_CPL_X)) {
  1673. ret = rspq->handler(rspq, rspq->cur_desc, NULL);
  1674. } else {
  1675. WARN_ON(rsp_type > RSPD_TYPE_CPL_X);
  1676. ret = 0;
  1677. }
  1678. if (unlikely(ret)) {
  1679. /*
  1680. * Couldn't process descriptor, back off for recovery.
  1681. * We use the SGE's last timer which has the longest
  1682. * interrupt coalescing value ...
  1683. */
  1684. const int NOMEM_TIMER_IDX = SGE_NTIMERS-1;
  1685. rspq->next_intr_params =
  1686. QINTR_TIMER_IDX_V(NOMEM_TIMER_IDX);
  1687. break;
  1688. }
  1689. rspq_next(rspq);
  1690. budget_left--;
  1691. }
  1692. /*
  1693. * If this is a Response Queue with an associated Free List and
  1694. * at least two Egress Queue units available in the Free List
  1695. * for new buffer pointers, refill the Free List.
  1696. */
  1697. if (rspq->offset >= 0 &&
  1698. fl_cap(&rxq->fl) - rxq->fl.avail >= 2*FL_PER_EQ_UNIT)
  1699. __refill_fl(rspq->adapter, &rxq->fl);
  1700. return budget - budget_left;
  1701. }
  1702. /**
  1703. * napi_rx_handler - the NAPI handler for RX processing
  1704. * @napi: the napi instance
  1705. * @budget: how many packets we can process in this round
  1706. *
  1707. * Handler for new data events when using NAPI. This does not need any
  1708. * locking or protection from interrupts as data interrupts are off at
  1709. * this point and other adapter interrupts do not interfere (the latter
  1710. * in not a concern at all with MSI-X as non-data interrupts then have
  1711. * a separate handler).
  1712. */
  1713. static int napi_rx_handler(struct napi_struct *napi, int budget)
  1714. {
  1715. unsigned int intr_params;
  1716. struct sge_rspq *rspq = container_of(napi, struct sge_rspq, napi);
  1717. int work_done = process_responses(rspq, budget);
  1718. u32 val;
  1719. if (likely(work_done < budget)) {
  1720. napi_complete_done(napi, work_done);
  1721. intr_params = rspq->next_intr_params;
  1722. rspq->next_intr_params = rspq->intr_params;
  1723. } else
  1724. intr_params = QINTR_TIMER_IDX_V(SGE_TIMER_UPD_CIDX);
  1725. if (unlikely(work_done == 0))
  1726. rspq->unhandled_irqs++;
  1727. val = CIDXINC_V(work_done) | SEINTARM_V(intr_params);
  1728. /* If we don't have access to the new User GTS (T5+), use the old
  1729. * doorbell mechanism; otherwise use the new BAR2 mechanism.
  1730. */
  1731. if (unlikely(!rspq->bar2_addr)) {
  1732. t4_write_reg(rspq->adapter,
  1733. T4VF_SGE_BASE_ADDR + SGE_VF_GTS,
  1734. val | INGRESSQID_V((u32)rspq->cntxt_id));
  1735. } else {
  1736. writel(val | INGRESSQID_V(rspq->bar2_qid),
  1737. rspq->bar2_addr + SGE_UDB_GTS);
  1738. wmb();
  1739. }
  1740. return work_done;
  1741. }
  1742. /*
  1743. * The MSI-X interrupt handler for an SGE response queue for the NAPI case
  1744. * (i.e., response queue serviced by NAPI polling).
  1745. */
  1746. irqreturn_t t4vf_sge_intr_msix(int irq, void *cookie)
  1747. {
  1748. struct sge_rspq *rspq = cookie;
  1749. napi_schedule(&rspq->napi);
  1750. return IRQ_HANDLED;
  1751. }
  1752. /*
  1753. * Process the indirect interrupt entries in the interrupt queue and kick off
  1754. * NAPI for each queue that has generated an entry.
  1755. */
  1756. static unsigned int process_intrq(struct adapter *adapter)
  1757. {
  1758. struct sge *s = &adapter->sge;
  1759. struct sge_rspq *intrq = &s->intrq;
  1760. unsigned int work_done;
  1761. u32 val;
  1762. spin_lock(&adapter->sge.intrq_lock);
  1763. for (work_done = 0; ; work_done++) {
  1764. const struct rsp_ctrl *rc;
  1765. unsigned int qid, iq_idx;
  1766. struct sge_rspq *rspq;
  1767. /*
  1768. * Grab the next response from the interrupt queue and bail
  1769. * out if it's not a new response.
  1770. */
  1771. rc = (void *)intrq->cur_desc + (intrq->iqe_len - sizeof(*rc));
  1772. if (!is_new_response(rc, intrq))
  1773. break;
  1774. /*
  1775. * If the response isn't a forwarded interrupt message issue a
  1776. * error and go on to the next response message. This should
  1777. * never happen ...
  1778. */
  1779. dma_rmb();
  1780. if (unlikely(RSPD_TYPE_G(rc->type_gen) != RSPD_TYPE_INTR_X)) {
  1781. dev_err(adapter->pdev_dev,
  1782. "Unexpected INTRQ response type %d\n",
  1783. RSPD_TYPE_G(rc->type_gen));
  1784. continue;
  1785. }
  1786. /*
  1787. * Extract the Queue ID from the interrupt message and perform
  1788. * sanity checking to make sure it really refers to one of our
  1789. * Ingress Queues which is active and matches the queue's ID.
  1790. * None of these error conditions should ever happen so we may
  1791. * want to either make them fatal and/or conditionalized under
  1792. * DEBUG.
  1793. */
  1794. qid = RSPD_QID_G(be32_to_cpu(rc->pldbuflen_qid));
  1795. iq_idx = IQ_IDX(s, qid);
  1796. if (unlikely(iq_idx >= MAX_INGQ)) {
  1797. dev_err(adapter->pdev_dev,
  1798. "Ingress QID %d out of range\n", qid);
  1799. continue;
  1800. }
  1801. rspq = s->ingr_map[iq_idx];
  1802. if (unlikely(rspq == NULL)) {
  1803. dev_err(adapter->pdev_dev,
  1804. "Ingress QID %d RSPQ=NULL\n", qid);
  1805. continue;
  1806. }
  1807. if (unlikely(rspq->abs_id != qid)) {
  1808. dev_err(adapter->pdev_dev,
  1809. "Ingress QID %d refers to RSPQ %d\n",
  1810. qid, rspq->abs_id);
  1811. continue;
  1812. }
  1813. /*
  1814. * Schedule NAPI processing on the indicated Response Queue
  1815. * and move on to the next entry in the Forwarded Interrupt
  1816. * Queue.
  1817. */
  1818. napi_schedule(&rspq->napi);
  1819. rspq_next(intrq);
  1820. }
  1821. val = CIDXINC_V(work_done) | SEINTARM_V(intrq->intr_params);
  1822. /* If we don't have access to the new User GTS (T5+), use the old
  1823. * doorbell mechanism; otherwise use the new BAR2 mechanism.
  1824. */
  1825. if (unlikely(!intrq->bar2_addr)) {
  1826. t4_write_reg(adapter, T4VF_SGE_BASE_ADDR + SGE_VF_GTS,
  1827. val | INGRESSQID_V(intrq->cntxt_id));
  1828. } else {
  1829. writel(val | INGRESSQID_V(intrq->bar2_qid),
  1830. intrq->bar2_addr + SGE_UDB_GTS);
  1831. wmb();
  1832. }
  1833. spin_unlock(&adapter->sge.intrq_lock);
  1834. return work_done;
  1835. }
  1836. /*
  1837. * The MSI interrupt handler handles data events from SGE response queues as
  1838. * well as error and other async events as they all use the same MSI vector.
  1839. */
  1840. static irqreturn_t t4vf_intr_msi(int irq, void *cookie)
  1841. {
  1842. struct adapter *adapter = cookie;
  1843. process_intrq(adapter);
  1844. return IRQ_HANDLED;
  1845. }
  1846. /**
  1847. * t4vf_intr_handler - select the top-level interrupt handler
  1848. * @adapter: the adapter
  1849. *
  1850. * Selects the top-level interrupt handler based on the type of interrupts
  1851. * (MSI-X or MSI).
  1852. */
  1853. irq_handler_t t4vf_intr_handler(struct adapter *adapter)
  1854. {
  1855. BUG_ON((adapter->flags &
  1856. (CXGB4VF_USING_MSIX | CXGB4VF_USING_MSI)) == 0);
  1857. if (adapter->flags & CXGB4VF_USING_MSIX)
  1858. return t4vf_sge_intr_msix;
  1859. else
  1860. return t4vf_intr_msi;
  1861. }
  1862. /**
  1863. * sge_rx_timer_cb - perform periodic maintenance of SGE RX queues
  1864. * @t: Rx timer
  1865. *
  1866. * Runs periodically from a timer to perform maintenance of SGE RX queues.
  1867. *
  1868. * a) Replenishes RX queues that have run out due to memory shortage.
  1869. * Normally new RX buffers are added when existing ones are consumed but
  1870. * when out of memory a queue can become empty. We schedule NAPI to do
  1871. * the actual refill.
  1872. */
  1873. static void sge_rx_timer_cb(struct timer_list *t)
  1874. {
  1875. struct adapter *adapter = from_timer(adapter, t, sge.rx_timer);
  1876. struct sge *s = &adapter->sge;
  1877. unsigned int i;
  1878. /*
  1879. * Scan the "Starving Free Lists" flag array looking for any Free
  1880. * Lists in need of more free buffers. If we find one and it's not
  1881. * being actively polled, then bump its "starving" counter and attempt
  1882. * to refill it. If we're successful in adding enough buffers to push
  1883. * the Free List over the starving threshold, then we can clear its
  1884. * "starving" status.
  1885. */
  1886. for (i = 0; i < ARRAY_SIZE(s->starving_fl); i++) {
  1887. unsigned long m;
  1888. for (m = s->starving_fl[i]; m; m &= m - 1) {
  1889. unsigned int id = __ffs(m) + i * BITS_PER_LONG;
  1890. struct sge_fl *fl = s->egr_map[id];
  1891. clear_bit(id, s->starving_fl);
  1892. smp_mb__after_atomic();
  1893. /*
  1894. * Since we are accessing fl without a lock there's a
  1895. * small probability of a false positive where we
  1896. * schedule napi but the FL is no longer starving.
  1897. * No biggie.
  1898. */
  1899. if (fl_starving(adapter, fl)) {
  1900. struct sge_eth_rxq *rxq;
  1901. rxq = container_of(fl, struct sge_eth_rxq, fl);
  1902. if (napi_reschedule(&rxq->rspq.napi))
  1903. fl->starving++;
  1904. else
  1905. set_bit(id, s->starving_fl);
  1906. }
  1907. }
  1908. }
  1909. /*
  1910. * Reschedule the next scan for starving Free Lists ...
  1911. */
  1912. mod_timer(&s->rx_timer, jiffies + RX_QCHECK_PERIOD);
  1913. }
  1914. /**
  1915. * sge_tx_timer_cb - perform periodic maintenance of SGE Tx queues
  1916. * @t: Tx timer
  1917. *
  1918. * Runs periodically from a timer to perform maintenance of SGE TX queues.
  1919. *
  1920. * b) Reclaims completed Tx packets for the Ethernet queues. Normally
  1921. * packets are cleaned up by new Tx packets, this timer cleans up packets
  1922. * when no new packets are being submitted. This is essential for pktgen,
  1923. * at least.
  1924. */
  1925. static void sge_tx_timer_cb(struct timer_list *t)
  1926. {
  1927. struct adapter *adapter = from_timer(adapter, t, sge.tx_timer);
  1928. struct sge *s = &adapter->sge;
  1929. unsigned int i, budget;
  1930. budget = MAX_TIMER_TX_RECLAIM;
  1931. i = s->ethtxq_rover;
  1932. do {
  1933. struct sge_eth_txq *txq = &s->ethtxq[i];
  1934. if (reclaimable(&txq->q) && __netif_tx_trylock(txq->txq)) {
  1935. int avail = reclaimable(&txq->q);
  1936. if (avail > budget)
  1937. avail = budget;
  1938. free_tx_desc(adapter, &txq->q, avail, true);
  1939. txq->q.in_use -= avail;
  1940. __netif_tx_unlock(txq->txq);
  1941. budget -= avail;
  1942. if (!budget)
  1943. break;
  1944. }
  1945. i++;
  1946. if (i >= s->ethqsets)
  1947. i = 0;
  1948. } while (i != s->ethtxq_rover);
  1949. s->ethtxq_rover = i;
  1950. /*
  1951. * If we found too many reclaimable packets schedule a timer in the
  1952. * near future to continue where we left off. Otherwise the next timer
  1953. * will be at its normal interval.
  1954. */
  1955. mod_timer(&s->tx_timer, jiffies + (budget ? TX_QCHECK_PERIOD : 2));
  1956. }
  1957. /**
  1958. * bar2_address - return the BAR2 address for an SGE Queue's Registers
  1959. * @adapter: the adapter
  1960. * @qid: the SGE Queue ID
  1961. * @qtype: the SGE Queue Type (Egress or Ingress)
  1962. * @pbar2_qid: BAR2 Queue ID or 0 for Queue ID inferred SGE Queues
  1963. *
  1964. * Returns the BAR2 address for the SGE Queue Registers associated with
  1965. * @qid. If BAR2 SGE Registers aren't available, returns NULL. Also
  1966. * returns the BAR2 Queue ID to be used with writes to the BAR2 SGE
  1967. * Queue Registers. If the BAR2 Queue ID is 0, then "Inferred Queue ID"
  1968. * Registers are supported (e.g. the Write Combining Doorbell Buffer).
  1969. */
  1970. static void __iomem *bar2_address(struct adapter *adapter,
  1971. unsigned int qid,
  1972. enum t4_bar2_qtype qtype,
  1973. unsigned int *pbar2_qid)
  1974. {
  1975. u64 bar2_qoffset;
  1976. int ret;
  1977. ret = t4vf_bar2_sge_qregs(adapter, qid, qtype,
  1978. &bar2_qoffset, pbar2_qid);
  1979. if (ret)
  1980. return NULL;
  1981. return adapter->bar2 + bar2_qoffset;
  1982. }
  1983. /**
  1984. * t4vf_sge_alloc_rxq - allocate an SGE RX Queue
  1985. * @adapter: the adapter
  1986. * @rspq: pointer to to the new rxq's Response Queue to be filled in
  1987. * @iqasynch: if 0, a normal rspq; if 1, an asynchronous event queue
  1988. * @dev: the network device associated with the new rspq
  1989. * @intr_dest: MSI-X vector index (overriden in MSI mode)
  1990. * @fl: pointer to the new rxq's Free List to be filled in
  1991. * @hnd: the interrupt handler to invoke for the rspq
  1992. */
  1993. int t4vf_sge_alloc_rxq(struct adapter *adapter, struct sge_rspq *rspq,
  1994. bool iqasynch, struct net_device *dev,
  1995. int intr_dest,
  1996. struct sge_fl *fl, rspq_handler_t hnd)
  1997. {
  1998. struct sge *s = &adapter->sge;
  1999. struct port_info *pi = netdev_priv(dev);
  2000. struct fw_iq_cmd cmd, rpl;
  2001. int ret, iqandst, flsz = 0;
  2002. int relaxed = !(adapter->flags & CXGB4VF_ROOT_NO_RELAXED_ORDERING);
  2003. /*
  2004. * If we're using MSI interrupts and we're not initializing the
  2005. * Forwarded Interrupt Queue itself, then set up this queue for
  2006. * indirect interrupts to the Forwarded Interrupt Queue. Obviously
  2007. * the Forwarded Interrupt Queue must be set up before any other
  2008. * ingress queue ...
  2009. */
  2010. if ((adapter->flags & CXGB4VF_USING_MSI) &&
  2011. rspq != &adapter->sge.intrq) {
  2012. iqandst = SGE_INTRDST_IQ;
  2013. intr_dest = adapter->sge.intrq.abs_id;
  2014. } else
  2015. iqandst = SGE_INTRDST_PCI;
  2016. /*
  2017. * Allocate the hardware ring for the Response Queue. The size needs
  2018. * to be a multiple of 16 which includes the mandatory status entry
  2019. * (regardless of whether the Status Page capabilities are enabled or
  2020. * not).
  2021. */
  2022. rspq->size = roundup(rspq->size, 16);
  2023. rspq->desc = alloc_ring(adapter->pdev_dev, rspq->size, rspq->iqe_len,
  2024. 0, &rspq->phys_addr, NULL, 0);
  2025. if (!rspq->desc)
  2026. return -ENOMEM;
  2027. /*
  2028. * Fill in the Ingress Queue Command. Note: Ideally this code would
  2029. * be in t4vf_hw.c but there are so many parameters and dependencies
  2030. * on our Linux SGE state that we would end up having to pass tons of
  2031. * parameters. We'll have to think about how this might be migrated
  2032. * into OS-independent common code ...
  2033. */
  2034. memset(&cmd, 0, sizeof(cmd));
  2035. cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_IQ_CMD) |
  2036. FW_CMD_REQUEST_F |
  2037. FW_CMD_WRITE_F |
  2038. FW_CMD_EXEC_F);
  2039. cmd.alloc_to_len16 = cpu_to_be32(FW_IQ_CMD_ALLOC_F |
  2040. FW_IQ_CMD_IQSTART_F |
  2041. FW_LEN16(cmd));
  2042. cmd.type_to_iqandstindex =
  2043. cpu_to_be32(FW_IQ_CMD_TYPE_V(FW_IQ_TYPE_FL_INT_CAP) |
  2044. FW_IQ_CMD_IQASYNCH_V(iqasynch) |
  2045. FW_IQ_CMD_VIID_V(pi->viid) |
  2046. FW_IQ_CMD_IQANDST_V(iqandst) |
  2047. FW_IQ_CMD_IQANUS_V(1) |
  2048. FW_IQ_CMD_IQANUD_V(SGE_UPDATEDEL_INTR) |
  2049. FW_IQ_CMD_IQANDSTINDEX_V(intr_dest));
  2050. cmd.iqdroprss_to_iqesize =
  2051. cpu_to_be16(FW_IQ_CMD_IQPCIECH_V(pi->port_id) |
  2052. FW_IQ_CMD_IQGTSMODE_F |
  2053. FW_IQ_CMD_IQINTCNTTHRESH_V(rspq->pktcnt_idx) |
  2054. FW_IQ_CMD_IQESIZE_V(ilog2(rspq->iqe_len) - 4));
  2055. cmd.iqsize = cpu_to_be16(rspq->size);
  2056. cmd.iqaddr = cpu_to_be64(rspq->phys_addr);
  2057. if (fl) {
  2058. unsigned int chip_ver =
  2059. CHELSIO_CHIP_VERSION(adapter->params.chip);
  2060. /*
  2061. * Allocate the ring for the hardware free list (with space
  2062. * for its status page) along with the associated software
  2063. * descriptor ring. The free list size needs to be a multiple
  2064. * of the Egress Queue Unit and at least 2 Egress Units larger
  2065. * than the SGE's Egress Congrestion Threshold
  2066. * (fl_starve_thres - 1).
  2067. */
  2068. if (fl->size < s->fl_starve_thres - 1 + 2 * FL_PER_EQ_UNIT)
  2069. fl->size = s->fl_starve_thres - 1 + 2 * FL_PER_EQ_UNIT;
  2070. fl->size = roundup(fl->size, FL_PER_EQ_UNIT);
  2071. fl->desc = alloc_ring(adapter->pdev_dev, fl->size,
  2072. sizeof(__be64), sizeof(struct rx_sw_desc),
  2073. &fl->addr, &fl->sdesc, s->stat_len);
  2074. if (!fl->desc) {
  2075. ret = -ENOMEM;
  2076. goto err;
  2077. }
  2078. /*
  2079. * Calculate the size of the hardware free list ring plus
  2080. * Status Page (which the SGE will place after the end of the
  2081. * free list ring) in Egress Queue Units.
  2082. */
  2083. flsz = (fl->size / FL_PER_EQ_UNIT +
  2084. s->stat_len / EQ_UNIT);
  2085. /*
  2086. * Fill in all the relevant firmware Ingress Queue Command
  2087. * fields for the free list.
  2088. */
  2089. cmd.iqns_to_fl0congen =
  2090. cpu_to_be32(
  2091. FW_IQ_CMD_FL0HOSTFCMODE_V(SGE_HOSTFCMODE_NONE) |
  2092. FW_IQ_CMD_FL0PACKEN_F |
  2093. FW_IQ_CMD_FL0FETCHRO_V(relaxed) |
  2094. FW_IQ_CMD_FL0DATARO_V(relaxed) |
  2095. FW_IQ_CMD_FL0PADEN_F);
  2096. /* In T6, for egress queue type FL there is internal overhead
  2097. * of 16B for header going into FLM module. Hence the maximum
  2098. * allowed burst size is 448 bytes. For T4/T5, the hardware
  2099. * doesn't coalesce fetch requests if more than 64 bytes of
  2100. * Free List pointers are provided, so we use a 128-byte Fetch
  2101. * Burst Minimum there (T6 implements coalescing so we can use
  2102. * the smaller 64-byte value there).
  2103. */
  2104. cmd.fl0dcaen_to_fl0cidxfthresh =
  2105. cpu_to_be16(
  2106. FW_IQ_CMD_FL0FBMIN_V(chip_ver <= CHELSIO_T5
  2107. ? FETCHBURSTMIN_128B_X
  2108. : FETCHBURSTMIN_64B_T6_X) |
  2109. FW_IQ_CMD_FL0FBMAX_V((chip_ver <= CHELSIO_T5) ?
  2110. FETCHBURSTMAX_512B_X :
  2111. FETCHBURSTMAX_256B_X));
  2112. cmd.fl0size = cpu_to_be16(flsz);
  2113. cmd.fl0addr = cpu_to_be64(fl->addr);
  2114. }
  2115. /*
  2116. * Issue the firmware Ingress Queue Command and extract the results if
  2117. * it completes successfully.
  2118. */
  2119. ret = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
  2120. if (ret)
  2121. goto err;
  2122. netif_napi_add(dev, &rspq->napi, napi_rx_handler);
  2123. rspq->cur_desc = rspq->desc;
  2124. rspq->cidx = 0;
  2125. rspq->gen = 1;
  2126. rspq->next_intr_params = rspq->intr_params;
  2127. rspq->cntxt_id = be16_to_cpu(rpl.iqid);
  2128. rspq->bar2_addr = bar2_address(adapter,
  2129. rspq->cntxt_id,
  2130. T4_BAR2_QTYPE_INGRESS,
  2131. &rspq->bar2_qid);
  2132. rspq->abs_id = be16_to_cpu(rpl.physiqid);
  2133. rspq->size--; /* subtract status entry */
  2134. rspq->adapter = adapter;
  2135. rspq->netdev = dev;
  2136. rspq->handler = hnd;
  2137. /* set offset to -1 to distinguish ingress queues without FL */
  2138. rspq->offset = fl ? 0 : -1;
  2139. if (fl) {
  2140. fl->cntxt_id = be16_to_cpu(rpl.fl0id);
  2141. fl->avail = 0;
  2142. fl->pend_cred = 0;
  2143. fl->pidx = 0;
  2144. fl->cidx = 0;
  2145. fl->alloc_failed = 0;
  2146. fl->large_alloc_failed = 0;
  2147. fl->starving = 0;
  2148. /* Note, we must initialize the BAR2 Free List User Doorbell
  2149. * information before refilling the Free List!
  2150. */
  2151. fl->bar2_addr = bar2_address(adapter,
  2152. fl->cntxt_id,
  2153. T4_BAR2_QTYPE_EGRESS,
  2154. &fl->bar2_qid);
  2155. refill_fl(adapter, fl, fl_cap(fl), GFP_KERNEL);
  2156. }
  2157. return 0;
  2158. err:
  2159. /*
  2160. * An error occurred. Clean up our partial allocation state and
  2161. * return the error.
  2162. */
  2163. if (rspq->desc) {
  2164. dma_free_coherent(adapter->pdev_dev, rspq->size * rspq->iqe_len,
  2165. rspq->desc, rspq->phys_addr);
  2166. rspq->desc = NULL;
  2167. }
  2168. if (fl && fl->desc) {
  2169. kfree(fl->sdesc);
  2170. fl->sdesc = NULL;
  2171. dma_free_coherent(adapter->pdev_dev, flsz * EQ_UNIT,
  2172. fl->desc, fl->addr);
  2173. fl->desc = NULL;
  2174. }
  2175. return ret;
  2176. }
  2177. /**
  2178. * t4vf_sge_alloc_eth_txq - allocate an SGE Ethernet TX Queue
  2179. * @adapter: the adapter
  2180. * @txq: pointer to the new txq to be filled in
  2181. * @dev: the network device
  2182. * @devq: the network TX queue associated with the new txq
  2183. * @iqid: the relative ingress queue ID to which events relating to
  2184. * the new txq should be directed
  2185. */
  2186. int t4vf_sge_alloc_eth_txq(struct adapter *adapter, struct sge_eth_txq *txq,
  2187. struct net_device *dev, struct netdev_queue *devq,
  2188. unsigned int iqid)
  2189. {
  2190. unsigned int chip_ver = CHELSIO_CHIP_VERSION(adapter->params.chip);
  2191. struct port_info *pi = netdev_priv(dev);
  2192. struct fw_eq_eth_cmd cmd, rpl;
  2193. struct sge *s = &adapter->sge;
  2194. int ret, nentries;
  2195. /*
  2196. * Calculate the size of the hardware TX Queue (including the Status
  2197. * Page on the end of the TX Queue) in units of TX Descriptors.
  2198. */
  2199. nentries = txq->q.size + s->stat_len / sizeof(struct tx_desc);
  2200. /*
  2201. * Allocate the hardware ring for the TX ring (with space for its
  2202. * status page) along with the associated software descriptor ring.
  2203. */
  2204. txq->q.desc = alloc_ring(adapter->pdev_dev, txq->q.size,
  2205. sizeof(struct tx_desc),
  2206. sizeof(struct tx_sw_desc),
  2207. &txq->q.phys_addr, &txq->q.sdesc, s->stat_len);
  2208. if (!txq->q.desc)
  2209. return -ENOMEM;
  2210. /*
  2211. * Fill in the Egress Queue Command. Note: As with the direct use of
  2212. * the firmware Ingress Queue COmmand above in our RXQ allocation
  2213. * routine, ideally, this code would be in t4vf_hw.c. Again, we'll
  2214. * have to see if there's some reasonable way to parameterize it
  2215. * into the common code ...
  2216. */
  2217. memset(&cmd, 0, sizeof(cmd));
  2218. cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_EQ_ETH_CMD) |
  2219. FW_CMD_REQUEST_F |
  2220. FW_CMD_WRITE_F |
  2221. FW_CMD_EXEC_F);
  2222. cmd.alloc_to_len16 = cpu_to_be32(FW_EQ_ETH_CMD_ALLOC_F |
  2223. FW_EQ_ETH_CMD_EQSTART_F |
  2224. FW_LEN16(cmd));
  2225. cmd.autoequiqe_to_viid = cpu_to_be32(FW_EQ_ETH_CMD_AUTOEQUEQE_F |
  2226. FW_EQ_ETH_CMD_VIID_V(pi->viid));
  2227. cmd.fetchszm_to_iqid =
  2228. cpu_to_be32(FW_EQ_ETH_CMD_HOSTFCMODE_V(SGE_HOSTFCMODE_STPG) |
  2229. FW_EQ_ETH_CMD_PCIECHN_V(pi->port_id) |
  2230. FW_EQ_ETH_CMD_IQID_V(iqid));
  2231. cmd.dcaen_to_eqsize =
  2232. cpu_to_be32(FW_EQ_ETH_CMD_FBMIN_V(chip_ver <= CHELSIO_T5
  2233. ? FETCHBURSTMIN_64B_X
  2234. : FETCHBURSTMIN_64B_T6_X) |
  2235. FW_EQ_ETH_CMD_FBMAX_V(FETCHBURSTMAX_512B_X) |
  2236. FW_EQ_ETH_CMD_CIDXFTHRESH_V(
  2237. CIDXFLUSHTHRESH_32_X) |
  2238. FW_EQ_ETH_CMD_EQSIZE_V(nentries));
  2239. cmd.eqaddr = cpu_to_be64(txq->q.phys_addr);
  2240. /*
  2241. * Issue the firmware Egress Queue Command and extract the results if
  2242. * it completes successfully.
  2243. */
  2244. ret = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
  2245. if (ret) {
  2246. /*
  2247. * The girmware Ingress Queue Command failed for some reason.
  2248. * Free up our partial allocation state and return the error.
  2249. */
  2250. kfree(txq->q.sdesc);
  2251. txq->q.sdesc = NULL;
  2252. dma_free_coherent(adapter->pdev_dev,
  2253. nentries * sizeof(struct tx_desc),
  2254. txq->q.desc, txq->q.phys_addr);
  2255. txq->q.desc = NULL;
  2256. return ret;
  2257. }
  2258. txq->q.in_use = 0;
  2259. txq->q.cidx = 0;
  2260. txq->q.pidx = 0;
  2261. txq->q.stat = (void *)&txq->q.desc[txq->q.size];
  2262. txq->q.cntxt_id = FW_EQ_ETH_CMD_EQID_G(be32_to_cpu(rpl.eqid_pkd));
  2263. txq->q.bar2_addr = bar2_address(adapter,
  2264. txq->q.cntxt_id,
  2265. T4_BAR2_QTYPE_EGRESS,
  2266. &txq->q.bar2_qid);
  2267. txq->q.abs_id =
  2268. FW_EQ_ETH_CMD_PHYSEQID_G(be32_to_cpu(rpl.physeqid_pkd));
  2269. txq->txq = devq;
  2270. txq->tso = 0;
  2271. txq->tx_cso = 0;
  2272. txq->vlan_ins = 0;
  2273. txq->q.stops = 0;
  2274. txq->q.restarts = 0;
  2275. txq->mapping_err = 0;
  2276. return 0;
  2277. }
  2278. /*
  2279. * Free the DMA map resources associated with a TX queue.
  2280. */
  2281. static void free_txq(struct adapter *adapter, struct sge_txq *tq)
  2282. {
  2283. struct sge *s = &adapter->sge;
  2284. dma_free_coherent(adapter->pdev_dev,
  2285. tq->size * sizeof(*tq->desc) + s->stat_len,
  2286. tq->desc, tq->phys_addr);
  2287. tq->cntxt_id = 0;
  2288. tq->sdesc = NULL;
  2289. tq->desc = NULL;
  2290. }
  2291. /*
  2292. * Free the resources associated with a response queue (possibly including a
  2293. * free list).
  2294. */
  2295. static void free_rspq_fl(struct adapter *adapter, struct sge_rspq *rspq,
  2296. struct sge_fl *fl)
  2297. {
  2298. struct sge *s = &adapter->sge;
  2299. unsigned int flid = fl ? fl->cntxt_id : 0xffff;
  2300. t4vf_iq_free(adapter, FW_IQ_TYPE_FL_INT_CAP,
  2301. rspq->cntxt_id, flid, 0xffff);
  2302. dma_free_coherent(adapter->pdev_dev, (rspq->size + 1) * rspq->iqe_len,
  2303. rspq->desc, rspq->phys_addr);
  2304. netif_napi_del(&rspq->napi);
  2305. rspq->netdev = NULL;
  2306. rspq->cntxt_id = 0;
  2307. rspq->abs_id = 0;
  2308. rspq->desc = NULL;
  2309. if (fl) {
  2310. free_rx_bufs(adapter, fl, fl->avail);
  2311. dma_free_coherent(adapter->pdev_dev,
  2312. fl->size * sizeof(*fl->desc) + s->stat_len,
  2313. fl->desc, fl->addr);
  2314. kfree(fl->sdesc);
  2315. fl->sdesc = NULL;
  2316. fl->cntxt_id = 0;
  2317. fl->desc = NULL;
  2318. }
  2319. }
  2320. /**
  2321. * t4vf_free_sge_resources - free SGE resources
  2322. * @adapter: the adapter
  2323. *
  2324. * Frees resources used by the SGE queue sets.
  2325. */
  2326. void t4vf_free_sge_resources(struct adapter *adapter)
  2327. {
  2328. struct sge *s = &adapter->sge;
  2329. struct sge_eth_rxq *rxq = s->ethrxq;
  2330. struct sge_eth_txq *txq = s->ethtxq;
  2331. struct sge_rspq *evtq = &s->fw_evtq;
  2332. struct sge_rspq *intrq = &s->intrq;
  2333. int qs;
  2334. for (qs = 0; qs < adapter->sge.ethqsets; qs++, rxq++, txq++) {
  2335. if (rxq->rspq.desc)
  2336. free_rspq_fl(adapter, &rxq->rspq, &rxq->fl);
  2337. if (txq->q.desc) {
  2338. t4vf_eth_eq_free(adapter, txq->q.cntxt_id);
  2339. free_tx_desc(adapter, &txq->q, txq->q.in_use, true);
  2340. kfree(txq->q.sdesc);
  2341. free_txq(adapter, &txq->q);
  2342. }
  2343. }
  2344. if (evtq->desc)
  2345. free_rspq_fl(adapter, evtq, NULL);
  2346. if (intrq->desc)
  2347. free_rspq_fl(adapter, intrq, NULL);
  2348. }
  2349. /**
  2350. * t4vf_sge_start - enable SGE operation
  2351. * @adapter: the adapter
  2352. *
  2353. * Start tasklets and timers associated with the DMA engine.
  2354. */
  2355. void t4vf_sge_start(struct adapter *adapter)
  2356. {
  2357. adapter->sge.ethtxq_rover = 0;
  2358. mod_timer(&adapter->sge.rx_timer, jiffies + RX_QCHECK_PERIOD);
  2359. mod_timer(&adapter->sge.tx_timer, jiffies + TX_QCHECK_PERIOD);
  2360. }
  2361. /**
  2362. * t4vf_sge_stop - disable SGE operation
  2363. * @adapter: the adapter
  2364. *
  2365. * Stop tasklets and timers associated with the DMA engine. Note that
  2366. * this is effective only if measures have been taken to disable any HW
  2367. * events that may restart them.
  2368. */
  2369. void t4vf_sge_stop(struct adapter *adapter)
  2370. {
  2371. struct sge *s = &adapter->sge;
  2372. if (s->rx_timer.function)
  2373. del_timer_sync(&s->rx_timer);
  2374. if (s->tx_timer.function)
  2375. del_timer_sync(&s->tx_timer);
  2376. }
  2377. /**
  2378. * t4vf_sge_init - initialize SGE
  2379. * @adapter: the adapter
  2380. *
  2381. * Performs SGE initialization needed every time after a chip reset.
  2382. * We do not initialize any of the queue sets here, instead the driver
  2383. * top-level must request those individually. We also do not enable DMA
  2384. * here, that should be done after the queues have been set up.
  2385. */
  2386. int t4vf_sge_init(struct adapter *adapter)
  2387. {
  2388. struct sge_params *sge_params = &adapter->params.sge;
  2389. u32 fl_small_pg = sge_params->sge_fl_buffer_size[0];
  2390. u32 fl_large_pg = sge_params->sge_fl_buffer_size[1];
  2391. struct sge *s = &adapter->sge;
  2392. /*
  2393. * Start by vetting the basic SGE parameters which have been set up by
  2394. * the Physical Function Driver. Ideally we should be able to deal
  2395. * with _any_ configuration. Practice is different ...
  2396. */
  2397. /* We only bother using the Large Page logic if the Large Page Buffer
  2398. * is larger than our Page Size Buffer.
  2399. */
  2400. if (fl_large_pg <= fl_small_pg)
  2401. fl_large_pg = 0;
  2402. /* The Page Size Buffer must be exactly equal to our Page Size and the
  2403. * Large Page Size Buffer should be 0 (per above) or a power of 2.
  2404. */
  2405. if (fl_small_pg != PAGE_SIZE ||
  2406. (fl_large_pg & (fl_large_pg - 1)) != 0) {
  2407. dev_err(adapter->pdev_dev, "bad SGE FL buffer sizes [%d, %d]\n",
  2408. fl_small_pg, fl_large_pg);
  2409. return -EINVAL;
  2410. }
  2411. if ((sge_params->sge_control & RXPKTCPLMODE_F) !=
  2412. RXPKTCPLMODE_V(RXPKTCPLMODE_SPLIT_X)) {
  2413. dev_err(adapter->pdev_dev, "bad SGE CPL MODE\n");
  2414. return -EINVAL;
  2415. }
  2416. /*
  2417. * Now translate the adapter parameters into our internal forms.
  2418. */
  2419. if (fl_large_pg)
  2420. s->fl_pg_order = ilog2(fl_large_pg) - PAGE_SHIFT;
  2421. s->stat_len = ((sge_params->sge_control & EGRSTATUSPAGESIZE_F)
  2422. ? 128 : 64);
  2423. s->pktshift = PKTSHIFT_G(sge_params->sge_control);
  2424. s->fl_align = t4vf_fl_pkt_align(adapter);
  2425. /* A FL with <= fl_starve_thres buffers is starving and a periodic
  2426. * timer will attempt to refill it. This needs to be larger than the
  2427. * SGE's Egress Congestion Threshold. If it isn't, then we can get
  2428. * stuck waiting for new packets while the SGE is waiting for us to
  2429. * give it more Free List entries. (Note that the SGE's Egress
  2430. * Congestion Threshold is in units of 2 Free List pointers.)
  2431. */
  2432. switch (CHELSIO_CHIP_VERSION(adapter->params.chip)) {
  2433. case CHELSIO_T4:
  2434. s->fl_starve_thres =
  2435. EGRTHRESHOLD_G(sge_params->sge_congestion_control);
  2436. break;
  2437. case CHELSIO_T5:
  2438. s->fl_starve_thres =
  2439. EGRTHRESHOLDPACKING_G(sge_params->sge_congestion_control);
  2440. break;
  2441. case CHELSIO_T6:
  2442. default:
  2443. s->fl_starve_thres =
  2444. T6_EGRTHRESHOLDPACKING_G(sge_params->sge_congestion_control);
  2445. break;
  2446. }
  2447. s->fl_starve_thres = s->fl_starve_thres * 2 + 1;
  2448. /*
  2449. * Set up tasklet timers.
  2450. */
  2451. timer_setup(&s->rx_timer, sge_rx_timer_cb, 0);
  2452. timer_setup(&s->tx_timer, sge_tx_timer_cb, 0);
  2453. /*
  2454. * Initialize Forwarded Interrupt Queue lock.
  2455. */
  2456. spin_lock_init(&s->intrq_lock);
  2457. return 0;
  2458. }