sge.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683
  1. /*****************************************************************************
  2. * *
  3. * File: sge.c *
  4. * $Revision: 1.26 $ *
  5. * $Date: 2005/06/21 18:29:48 $ *
  6. * Description: *
  7. * DMA engine. *
  8. * part of the Chelsio 10Gb Ethernet Driver. *
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License, version 2, as *
  12. * published by the Free Software Foundation. *
  13. * *
  14. * You should have received a copy of the GNU General Public License along *
  15. * with this program; if not, write to the Free Software Foundation, Inc., *
  16. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  17. * *
  18. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED *
  19. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF *
  20. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. *
  21. * *
  22. * http://www.chelsio.com *
  23. * *
  24. * Copyright (c) 2003 - 2005 Chelsio Communications, Inc. *
  25. * All rights reserved. *
  26. * *
  27. * Maintainers: maintainers@chelsio.com *
  28. * *
  29. * Authors: Dimitrios Michailidis <dm@chelsio.com> *
  30. * Tina Yang <tainay@chelsio.com> *
  31. * Felix Marti <felix@chelsio.com> *
  32. * Scott Bardone <sbardone@chelsio.com> *
  33. * Kurt Ottaway <kottaway@chelsio.com> *
  34. * Frank DiMambro <frank@chelsio.com> *
  35. * *
  36. * History: *
  37. * *
  38. ****************************************************************************/
  39. #include "common.h"
  40. #include <linux/types.h>
  41. #include <linux/errno.h>
  42. #include <linux/pci.h>
  43. #include <linux/netdevice.h>
  44. #include <linux/etherdevice.h>
  45. #include <linux/if_vlan.h>
  46. #include <linux/skbuff.h>
  47. #include <linux/init.h>
  48. #include <linux/mm.h>
  49. #include <linux/ip.h>
  50. #include <linux/in.h>
  51. #include <linux/if_arp.h>
  52. #include "cpl5_cmd.h"
  53. #include "sge.h"
  54. #include "regs.h"
  55. #include "espi.h"
  56. #ifdef NETIF_F_TSO
  57. #include <linux/tcp.h>
  58. #endif
  59. #define SGE_CMDQ_N 2
  60. #define SGE_FREELQ_N 2
  61. #define SGE_CMDQ0_E_N 1024
  62. #define SGE_CMDQ1_E_N 128
  63. #define SGE_FREEL_SIZE 4096
  64. #define SGE_JUMBO_FREEL_SIZE 512
  65. #define SGE_FREEL_REFILL_THRESH 16
  66. #define SGE_RESPQ_E_N 1024
  67. #define SGE_INTRTIMER_NRES 1000
  68. #define SGE_RX_COPY_THRES 256
  69. #define SGE_RX_SM_BUF_SIZE 1536
  70. # define SGE_RX_DROP_THRES 2
  71. #define SGE_RESPQ_REPLENISH_THRES (SGE_RESPQ_E_N / 4)
  72. /*
  73. * Period of the TX buffer reclaim timer. This timer does not need to run
  74. * frequently as TX buffers are usually reclaimed by new TX packets.
  75. */
  76. #define TX_RECLAIM_PERIOD (HZ / 4)
  77. #ifndef NET_IP_ALIGN
  78. # define NET_IP_ALIGN 2
  79. #endif
  80. #define M_CMD_LEN 0x7fffffff
  81. #define V_CMD_LEN(v) (v)
  82. #define G_CMD_LEN(v) ((v) & M_CMD_LEN)
  83. #define V_CMD_GEN1(v) ((v) << 31)
  84. #define V_CMD_GEN2(v) (v)
  85. #define F_CMD_DATAVALID (1 << 1)
  86. #define F_CMD_SOP (1 << 2)
  87. #define V_CMD_EOP(v) ((v) << 3)
  88. /*
  89. * Command queue, receive buffer list, and response queue descriptors.
  90. */
  91. #if defined(__BIG_ENDIAN_BITFIELD)
  92. struct cmdQ_e {
  93. u32 addr_lo;
  94. u32 len_gen;
  95. u32 flags;
  96. u32 addr_hi;
  97. };
  98. struct freelQ_e {
  99. u32 addr_lo;
  100. u32 len_gen;
  101. u32 gen2;
  102. u32 addr_hi;
  103. };
  104. struct respQ_e {
  105. u32 Qsleeping : 4;
  106. u32 Cmdq1CreditReturn : 5;
  107. u32 Cmdq1DmaComplete : 5;
  108. u32 Cmdq0CreditReturn : 5;
  109. u32 Cmdq0DmaComplete : 5;
  110. u32 FreelistQid : 2;
  111. u32 CreditValid : 1;
  112. u32 DataValid : 1;
  113. u32 Offload : 1;
  114. u32 Eop : 1;
  115. u32 Sop : 1;
  116. u32 GenerationBit : 1;
  117. u32 BufferLength;
  118. };
  119. #elif defined(__LITTLE_ENDIAN_BITFIELD)
  120. struct cmdQ_e {
  121. u32 len_gen;
  122. u32 addr_lo;
  123. u32 addr_hi;
  124. u32 flags;
  125. };
  126. struct freelQ_e {
  127. u32 len_gen;
  128. u32 addr_lo;
  129. u32 addr_hi;
  130. u32 gen2;
  131. };
  132. struct respQ_e {
  133. u32 BufferLength;
  134. u32 GenerationBit : 1;
  135. u32 Sop : 1;
  136. u32 Eop : 1;
  137. u32 Offload : 1;
  138. u32 DataValid : 1;
  139. u32 CreditValid : 1;
  140. u32 FreelistQid : 2;
  141. u32 Cmdq0DmaComplete : 5;
  142. u32 Cmdq0CreditReturn : 5;
  143. u32 Cmdq1DmaComplete : 5;
  144. u32 Cmdq1CreditReturn : 5;
  145. u32 Qsleeping : 4;
  146. } ;
  147. #endif
  148. /*
  149. * SW Context Command and Freelist Queue Descriptors
  150. */
  151. struct cmdQ_ce {
  152. struct sk_buff *skb;
  153. DECLARE_PCI_UNMAP_ADDR(dma_addr);
  154. DECLARE_PCI_UNMAP_LEN(dma_len);
  155. };
  156. struct freelQ_ce {
  157. struct sk_buff *skb;
  158. DECLARE_PCI_UNMAP_ADDR(dma_addr);
  159. DECLARE_PCI_UNMAP_LEN(dma_len);
  160. };
  161. /*
  162. * SW command, freelist and response rings
  163. */
  164. struct cmdQ {
  165. unsigned long status; /* HW DMA fetch status */
  166. unsigned int in_use; /* # of in-use command descriptors */
  167. unsigned int size; /* # of descriptors */
  168. unsigned int processed; /* total # of descs HW has processed */
  169. unsigned int cleaned; /* total # of descs SW has reclaimed */
  170. unsigned int stop_thres; /* SW TX queue suspend threshold */
  171. u16 pidx; /* producer index (SW) */
  172. u16 cidx; /* consumer index (HW) */
  173. u8 genbit; /* current generation (=valid) bit */
  174. u8 sop; /* is next entry start of packet? */
  175. struct cmdQ_e *entries; /* HW command descriptor Q */
  176. struct cmdQ_ce *centries; /* SW command context descriptor Q */
  177. spinlock_t lock; /* Lock to protect cmdQ enqueuing */
  178. dma_addr_t dma_addr; /* DMA addr HW command descriptor Q */
  179. };
  180. struct freelQ {
  181. unsigned int credits; /* # of available RX buffers */
  182. unsigned int size; /* free list capacity */
  183. u16 pidx; /* producer index (SW) */
  184. u16 cidx; /* consumer index (HW) */
  185. u16 rx_buffer_size; /* Buffer size on this free list */
  186. u16 dma_offset; /* DMA offset to align IP headers */
  187. u16 recycleq_idx; /* skb recycle q to use */
  188. u8 genbit; /* current generation (=valid) bit */
  189. struct freelQ_e *entries; /* HW freelist descriptor Q */
  190. struct freelQ_ce *centries; /* SW freelist context descriptor Q */
  191. dma_addr_t dma_addr; /* DMA addr HW freelist descriptor Q */
  192. };
  193. struct respQ {
  194. unsigned int credits; /* credits to be returned to SGE */
  195. unsigned int size; /* # of response Q descriptors */
  196. u16 cidx; /* consumer index (SW) */
  197. u8 genbit; /* current generation(=valid) bit */
  198. struct respQ_e *entries; /* HW response descriptor Q */
  199. dma_addr_t dma_addr; /* DMA addr HW response descriptor Q */
  200. };
  201. /* Bit flags for cmdQ.status */
  202. enum {
  203. CMDQ_STAT_RUNNING = 1, /* fetch engine is running */
  204. CMDQ_STAT_LAST_PKT_DB = 2 /* last packet rung the doorbell */
  205. };
  206. /*
  207. * Main SGE data structure
  208. *
  209. * Interrupts are handled by a single CPU and it is likely that on a MP system
  210. * the application is migrated to another CPU. In that scenario, we try to
  211. * seperate the RX(in irq context) and TX state in order to decrease memory
  212. * contention.
  213. */
  214. struct sge {
  215. struct adapter *adapter; /* adapter backpointer */
  216. struct net_device *netdev; /* netdevice backpointer */
  217. struct freelQ freelQ[SGE_FREELQ_N]; /* buffer free lists */
  218. struct respQ respQ; /* response Q */
  219. unsigned long stopped_tx_queues; /* bitmap of suspended Tx queues */
  220. unsigned int rx_pkt_pad; /* RX padding for L2 packets */
  221. unsigned int jumbo_fl; /* jumbo freelist Q index */
  222. unsigned int intrtimer_nres; /* no-resource interrupt timer */
  223. unsigned int fixed_intrtimer;/* non-adaptive interrupt timer */
  224. struct timer_list tx_reclaim_timer; /* reclaims TX buffers */
  225. struct timer_list espibug_timer;
  226. unsigned int espibug_timeout;
  227. struct sk_buff *espibug_skb;
  228. u32 sge_control; /* shadow value of sge control reg */
  229. struct sge_intr_counts stats;
  230. struct sge_port_stats port_stats[MAX_NPORTS];
  231. struct cmdQ cmdQ[SGE_CMDQ_N] ____cacheline_aligned_in_smp;
  232. };
  233. /*
  234. * PIO to indicate that memory mapped Q contains valid descriptor(s).
  235. */
  236. static inline void doorbell_pio(struct adapter *adapter, u32 val)
  237. {
  238. wmb();
  239. writel(val, adapter->regs + A_SG_DOORBELL);
  240. }
  241. /*
  242. * Frees all RX buffers on the freelist Q. The caller must make sure that
  243. * the SGE is turned off before calling this function.
  244. */
  245. static void free_freelQ_buffers(struct pci_dev *pdev, struct freelQ *q)
  246. {
  247. unsigned int cidx = q->cidx;
  248. while (q->credits--) {
  249. struct freelQ_ce *ce = &q->centries[cidx];
  250. pci_unmap_single(pdev, pci_unmap_addr(ce, dma_addr),
  251. pci_unmap_len(ce, dma_len),
  252. PCI_DMA_FROMDEVICE);
  253. dev_kfree_skb(ce->skb);
  254. ce->skb = NULL;
  255. if (++cidx == q->size)
  256. cidx = 0;
  257. }
  258. }
  259. /*
  260. * Free RX free list and response queue resources.
  261. */
  262. static void free_rx_resources(struct sge *sge)
  263. {
  264. struct pci_dev *pdev = sge->adapter->pdev;
  265. unsigned int size, i;
  266. if (sge->respQ.entries) {
  267. size = sizeof(struct respQ_e) * sge->respQ.size;
  268. pci_free_consistent(pdev, size, sge->respQ.entries,
  269. sge->respQ.dma_addr);
  270. }
  271. for (i = 0; i < SGE_FREELQ_N; i++) {
  272. struct freelQ *q = &sge->freelQ[i];
  273. if (q->centries) {
  274. free_freelQ_buffers(pdev, q);
  275. kfree(q->centries);
  276. }
  277. if (q->entries) {
  278. size = sizeof(struct freelQ_e) * q->size;
  279. pci_free_consistent(pdev, size, q->entries,
  280. q->dma_addr);
  281. }
  282. }
  283. }
  284. /*
  285. * Allocates basic RX resources, consisting of memory mapped freelist Qs and a
  286. * response queue.
  287. */
  288. static int alloc_rx_resources(struct sge *sge, struct sge_params *p)
  289. {
  290. struct pci_dev *pdev = sge->adapter->pdev;
  291. unsigned int size, i;
  292. for (i = 0; i < SGE_FREELQ_N; i++) {
  293. struct freelQ *q = &sge->freelQ[i];
  294. q->genbit = 1;
  295. q->size = p->freelQ_size[i];
  296. q->dma_offset = sge->rx_pkt_pad ? 0 : NET_IP_ALIGN;
  297. size = sizeof(struct freelQ_e) * q->size;
  298. q->entries = (struct freelQ_e *)
  299. pci_alloc_consistent(pdev, size, &q->dma_addr);
  300. if (!q->entries)
  301. goto err_no_mem;
  302. memset(q->entries, 0, size);
  303. size = sizeof(struct freelQ_ce) * q->size;
  304. q->centries = kmalloc(size, GFP_KERNEL);
  305. if (!q->centries)
  306. goto err_no_mem;
  307. memset(q->centries, 0, size);
  308. }
  309. /*
  310. * Calculate the buffer sizes for the two free lists. FL0 accommodates
  311. * regular sized Ethernet frames, FL1 is sized not to exceed 16K,
  312. * including all the sk_buff overhead.
  313. *
  314. * Note: For T2 FL0 and FL1 are reversed.
  315. */
  316. sge->freelQ[!sge->jumbo_fl].rx_buffer_size = SGE_RX_SM_BUF_SIZE +
  317. sizeof(struct cpl_rx_data) +
  318. sge->freelQ[!sge->jumbo_fl].dma_offset;
  319. sge->freelQ[sge->jumbo_fl].rx_buffer_size = (16 * 1024) -
  320. SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
  321. /*
  322. * Setup which skb recycle Q should be used when recycling buffers from
  323. * each free list.
  324. */
  325. sge->freelQ[!sge->jumbo_fl].recycleq_idx = 0;
  326. sge->freelQ[sge->jumbo_fl].recycleq_idx = 1;
  327. sge->respQ.genbit = 1;
  328. sge->respQ.size = SGE_RESPQ_E_N;
  329. sge->respQ.credits = 0;
  330. size = sizeof(struct respQ_e) * sge->respQ.size;
  331. sge->respQ.entries = (struct respQ_e *)
  332. pci_alloc_consistent(pdev, size, &sge->respQ.dma_addr);
  333. if (!sge->respQ.entries)
  334. goto err_no_mem;
  335. memset(sge->respQ.entries, 0, size);
  336. return 0;
  337. err_no_mem:
  338. free_rx_resources(sge);
  339. return -ENOMEM;
  340. }
  341. /*
  342. * Reclaims n TX descriptors and frees the buffers associated with them.
  343. */
  344. static void free_cmdQ_buffers(struct sge *sge, struct cmdQ *q, unsigned int n)
  345. {
  346. struct cmdQ_ce *ce;
  347. struct pci_dev *pdev = sge->adapter->pdev;
  348. unsigned int cidx = q->cidx;
  349. q->in_use -= n;
  350. ce = &q->centries[cidx];
  351. while (n--) {
  352. if (q->sop)
  353. pci_unmap_single(pdev, pci_unmap_addr(ce, dma_addr),
  354. pci_unmap_len(ce, dma_len),
  355. PCI_DMA_TODEVICE);
  356. else
  357. pci_unmap_page(pdev, pci_unmap_addr(ce, dma_addr),
  358. pci_unmap_len(ce, dma_len),
  359. PCI_DMA_TODEVICE);
  360. q->sop = 0;
  361. if (ce->skb) {
  362. dev_kfree_skb(ce->skb);
  363. q->sop = 1;
  364. }
  365. ce++;
  366. if (++cidx == q->size) {
  367. cidx = 0;
  368. ce = q->centries;
  369. }
  370. }
  371. q->cidx = cidx;
  372. }
  373. /*
  374. * Free TX resources.
  375. *
  376. * Assumes that SGE is stopped and all interrupts are disabled.
  377. */
  378. static void free_tx_resources(struct sge *sge)
  379. {
  380. struct pci_dev *pdev = sge->adapter->pdev;
  381. unsigned int size, i;
  382. for (i = 0; i < SGE_CMDQ_N; i++) {
  383. struct cmdQ *q = &sge->cmdQ[i];
  384. if (q->centries) {
  385. if (q->in_use)
  386. free_cmdQ_buffers(sge, q, q->in_use);
  387. kfree(q->centries);
  388. }
  389. if (q->entries) {
  390. size = sizeof(struct cmdQ_e) * q->size;
  391. pci_free_consistent(pdev, size, q->entries,
  392. q->dma_addr);
  393. }
  394. }
  395. }
  396. /*
  397. * Allocates basic TX resources, consisting of memory mapped command Qs.
  398. */
  399. static int alloc_tx_resources(struct sge *sge, struct sge_params *p)
  400. {
  401. struct pci_dev *pdev = sge->adapter->pdev;
  402. unsigned int size, i;
  403. for (i = 0; i < SGE_CMDQ_N; i++) {
  404. struct cmdQ *q = &sge->cmdQ[i];
  405. q->genbit = 1;
  406. q->sop = 1;
  407. q->size = p->cmdQ_size[i];
  408. q->in_use = 0;
  409. q->status = 0;
  410. q->processed = q->cleaned = 0;
  411. q->stop_thres = 0;
  412. spin_lock_init(&q->lock);
  413. size = sizeof(struct cmdQ_e) * q->size;
  414. q->entries = (struct cmdQ_e *)
  415. pci_alloc_consistent(pdev, size, &q->dma_addr);
  416. if (!q->entries)
  417. goto err_no_mem;
  418. memset(q->entries, 0, size);
  419. size = sizeof(struct cmdQ_ce) * q->size;
  420. q->centries = kmalloc(size, GFP_KERNEL);
  421. if (!q->centries)
  422. goto err_no_mem;
  423. memset(q->centries, 0, size);
  424. }
  425. /*
  426. * CommandQ 0 handles Ethernet and TOE packets, while queue 1 is TOE
  427. * only. For queue 0 set the stop threshold so we can handle one more
  428. * packet from each port, plus reserve an additional 24 entries for
  429. * Ethernet packets only. Queue 1 never suspends nor do we reserve
  430. * space for Ethernet packets.
  431. */
  432. sge->cmdQ[0].stop_thres = sge->adapter->params.nports *
  433. (MAX_SKB_FRAGS + 1);
  434. return 0;
  435. err_no_mem:
  436. free_tx_resources(sge);
  437. return -ENOMEM;
  438. }
  439. static inline void setup_ring_params(struct adapter *adapter, u64 addr,
  440. u32 size, int base_reg_lo,
  441. int base_reg_hi, int size_reg)
  442. {
  443. writel((u32)addr, adapter->regs + base_reg_lo);
  444. writel(addr >> 32, adapter->regs + base_reg_hi);
  445. writel(size, adapter->regs + size_reg);
  446. }
  447. /*
  448. * Enable/disable VLAN acceleration.
  449. */
  450. void t1_set_vlan_accel(struct adapter *adapter, int on_off)
  451. {
  452. struct sge *sge = adapter->sge;
  453. sge->sge_control &= ~F_VLAN_XTRACT;
  454. if (on_off)
  455. sge->sge_control |= F_VLAN_XTRACT;
  456. if (adapter->open_device_map) {
  457. writel(sge->sge_control, adapter->regs + A_SG_CONTROL);
  458. readl(adapter->regs + A_SG_CONTROL); /* flush */
  459. }
  460. }
  461. /*
  462. * Programs the various SGE registers. However, the engine is not yet enabled,
  463. * but sge->sge_control is setup and ready to go.
  464. */
  465. static void configure_sge(struct sge *sge, struct sge_params *p)
  466. {
  467. struct adapter *ap = sge->adapter;
  468. writel(0, ap->regs + A_SG_CONTROL);
  469. setup_ring_params(ap, sge->cmdQ[0].dma_addr, sge->cmdQ[0].size,
  470. A_SG_CMD0BASELWR, A_SG_CMD0BASEUPR, A_SG_CMD0SIZE);
  471. setup_ring_params(ap, sge->cmdQ[1].dma_addr, sge->cmdQ[1].size,
  472. A_SG_CMD1BASELWR, A_SG_CMD1BASEUPR, A_SG_CMD1SIZE);
  473. setup_ring_params(ap, sge->freelQ[0].dma_addr,
  474. sge->freelQ[0].size, A_SG_FL0BASELWR,
  475. A_SG_FL0BASEUPR, A_SG_FL0SIZE);
  476. setup_ring_params(ap, sge->freelQ[1].dma_addr,
  477. sge->freelQ[1].size, A_SG_FL1BASELWR,
  478. A_SG_FL1BASEUPR, A_SG_FL1SIZE);
  479. /* The threshold comparison uses <. */
  480. writel(SGE_RX_SM_BUF_SIZE + 1, ap->regs + A_SG_FLTHRESHOLD);
  481. setup_ring_params(ap, sge->respQ.dma_addr, sge->respQ.size,
  482. A_SG_RSPBASELWR, A_SG_RSPBASEUPR, A_SG_RSPSIZE);
  483. writel((u32)sge->respQ.size - 1, ap->regs + A_SG_RSPQUEUECREDIT);
  484. sge->sge_control = F_CMDQ0_ENABLE | F_CMDQ1_ENABLE | F_FL0_ENABLE |
  485. F_FL1_ENABLE | F_CPL_ENABLE | F_RESPONSE_QUEUE_ENABLE |
  486. V_CMDQ_PRIORITY(2) | F_DISABLE_CMDQ1_GTS | F_ISCSI_COALESCE |
  487. F_DISABLE_FL0_GTS | F_DISABLE_FL1_GTS |
  488. V_RX_PKT_OFFSET(sge->rx_pkt_pad);
  489. #if defined(__BIG_ENDIAN_BITFIELD)
  490. sge->sge_control |= F_ENABLE_BIG_ENDIAN;
  491. #endif
  492. /* Initialize no-resource timer */
  493. sge->intrtimer_nres = SGE_INTRTIMER_NRES * core_ticks_per_usec(ap);
  494. t1_sge_set_coalesce_params(sge, p);
  495. }
  496. /*
  497. * Return the payload capacity of the jumbo free-list buffers.
  498. */
  499. static inline unsigned int jumbo_payload_capacity(const struct sge *sge)
  500. {
  501. return sge->freelQ[sge->jumbo_fl].rx_buffer_size -
  502. sge->freelQ[sge->jumbo_fl].dma_offset -
  503. sizeof(struct cpl_rx_data);
  504. }
  505. /*
  506. * Frees all SGE related resources and the sge structure itself
  507. */
  508. void t1_sge_destroy(struct sge *sge)
  509. {
  510. if (sge->espibug_skb)
  511. kfree_skb(sge->espibug_skb);
  512. free_tx_resources(sge);
  513. free_rx_resources(sge);
  514. kfree(sge);
  515. }
  516. /*
  517. * Allocates new RX buffers on the freelist Q (and tracks them on the freelist
  518. * context Q) until the Q is full or alloc_skb fails.
  519. *
  520. * It is possible that the generation bits already match, indicating that the
  521. * buffer is already valid and nothing needs to be done. This happens when we
  522. * copied a received buffer into a new sk_buff during the interrupt processing.
  523. *
  524. * If the SGE doesn't automatically align packets properly (!sge->rx_pkt_pad),
  525. * we specify a RX_OFFSET in order to make sure that the IP header is 4B
  526. * aligned.
  527. */
  528. static void refill_free_list(struct sge *sge, struct freelQ *q)
  529. {
  530. struct pci_dev *pdev = sge->adapter->pdev;
  531. struct freelQ_ce *ce = &q->centries[q->pidx];
  532. struct freelQ_e *e = &q->entries[q->pidx];
  533. unsigned int dma_len = q->rx_buffer_size - q->dma_offset;
  534. while (q->credits < q->size) {
  535. struct sk_buff *skb;
  536. dma_addr_t mapping;
  537. skb = alloc_skb(q->rx_buffer_size, GFP_ATOMIC);
  538. if (!skb)
  539. break;
  540. skb_reserve(skb, q->dma_offset);
  541. mapping = pci_map_single(pdev, skb->data, dma_len,
  542. PCI_DMA_FROMDEVICE);
  543. ce->skb = skb;
  544. pci_unmap_addr_set(ce, dma_addr, mapping);
  545. pci_unmap_len_set(ce, dma_len, dma_len);
  546. e->addr_lo = (u32)mapping;
  547. e->addr_hi = (u64)mapping >> 32;
  548. e->len_gen = V_CMD_LEN(dma_len) | V_CMD_GEN1(q->genbit);
  549. wmb();
  550. e->gen2 = V_CMD_GEN2(q->genbit);
  551. e++;
  552. ce++;
  553. if (++q->pidx == q->size) {
  554. q->pidx = 0;
  555. q->genbit ^= 1;
  556. ce = q->centries;
  557. e = q->entries;
  558. }
  559. q->credits++;
  560. }
  561. }
  562. /*
  563. * Calls refill_free_list for both free lists. If we cannot fill at least 1/4
  564. * of both rings, we go into 'few interrupt mode' in order to give the system
  565. * time to free up resources.
  566. */
  567. static void freelQs_empty(struct sge *sge)
  568. {
  569. struct adapter *adapter = sge->adapter;
  570. u32 irq_reg = readl(adapter->regs + A_SG_INT_ENABLE);
  571. u32 irqholdoff_reg;
  572. refill_free_list(sge, &sge->freelQ[0]);
  573. refill_free_list(sge, &sge->freelQ[1]);
  574. if (sge->freelQ[0].credits > (sge->freelQ[0].size >> 2) &&
  575. sge->freelQ[1].credits > (sge->freelQ[1].size >> 2)) {
  576. irq_reg |= F_FL_EXHAUSTED;
  577. irqholdoff_reg = sge->fixed_intrtimer;
  578. } else {
  579. /* Clear the F_FL_EXHAUSTED interrupts for now */
  580. irq_reg &= ~F_FL_EXHAUSTED;
  581. irqholdoff_reg = sge->intrtimer_nres;
  582. }
  583. writel(irqholdoff_reg, adapter->regs + A_SG_INTRTIMER);
  584. writel(irq_reg, adapter->regs + A_SG_INT_ENABLE);
  585. /* We reenable the Qs to force a freelist GTS interrupt later */
  586. doorbell_pio(adapter, F_FL0_ENABLE | F_FL1_ENABLE);
  587. }
  588. #define SGE_PL_INTR_MASK (F_PL_INTR_SGE_ERR | F_PL_INTR_SGE_DATA)
  589. #define SGE_INT_FATAL (F_RESPQ_OVERFLOW | F_PACKET_TOO_BIG | F_PACKET_MISMATCH)
  590. #define SGE_INT_ENABLE (F_RESPQ_EXHAUSTED | F_RESPQ_OVERFLOW | \
  591. F_FL_EXHAUSTED | F_PACKET_TOO_BIG | F_PACKET_MISMATCH)
  592. /*
  593. * Disable SGE Interrupts
  594. */
  595. void t1_sge_intr_disable(struct sge *sge)
  596. {
  597. u32 val = readl(sge->adapter->regs + A_PL_ENABLE);
  598. writel(val & ~SGE_PL_INTR_MASK, sge->adapter->regs + A_PL_ENABLE);
  599. writel(0, sge->adapter->regs + A_SG_INT_ENABLE);
  600. }
  601. /*
  602. * Enable SGE interrupts.
  603. */
  604. void t1_sge_intr_enable(struct sge *sge)
  605. {
  606. u32 en = SGE_INT_ENABLE;
  607. u32 val = readl(sge->adapter->regs + A_PL_ENABLE);
  608. if (sge->adapter->flags & TSO_CAPABLE)
  609. en &= ~F_PACKET_TOO_BIG;
  610. writel(en, sge->adapter->regs + A_SG_INT_ENABLE);
  611. writel(val | SGE_PL_INTR_MASK, sge->adapter->regs + A_PL_ENABLE);
  612. }
  613. /*
  614. * Clear SGE interrupts.
  615. */
  616. void t1_sge_intr_clear(struct sge *sge)
  617. {
  618. writel(SGE_PL_INTR_MASK, sge->adapter->regs + A_PL_CAUSE);
  619. writel(0xffffffff, sge->adapter->regs + A_SG_INT_CAUSE);
  620. }
  621. /*
  622. * SGE 'Error' interrupt handler
  623. */
  624. int t1_sge_intr_error_handler(struct sge *sge)
  625. {
  626. struct adapter *adapter = sge->adapter;
  627. u32 cause = readl(adapter->regs + A_SG_INT_CAUSE);
  628. if (adapter->flags & TSO_CAPABLE)
  629. cause &= ~F_PACKET_TOO_BIG;
  630. if (cause & F_RESPQ_EXHAUSTED)
  631. sge->stats.respQ_empty++;
  632. if (cause & F_RESPQ_OVERFLOW) {
  633. sge->stats.respQ_overflow++;
  634. CH_ALERT("%s: SGE response queue overflow\n",
  635. adapter->name);
  636. }
  637. if (cause & F_FL_EXHAUSTED) {
  638. sge->stats.freelistQ_empty++;
  639. freelQs_empty(sge);
  640. }
  641. if (cause & F_PACKET_TOO_BIG) {
  642. sge->stats.pkt_too_big++;
  643. CH_ALERT("%s: SGE max packet size exceeded\n",
  644. adapter->name);
  645. }
  646. if (cause & F_PACKET_MISMATCH) {
  647. sge->stats.pkt_mismatch++;
  648. CH_ALERT("%s: SGE packet mismatch\n", adapter->name);
  649. }
  650. if (cause & SGE_INT_FATAL)
  651. t1_fatal_err(adapter);
  652. writel(cause, adapter->regs + A_SG_INT_CAUSE);
  653. return 0;
  654. }
  655. const struct sge_intr_counts *t1_sge_get_intr_counts(struct sge *sge)
  656. {
  657. return &sge->stats;
  658. }
  659. const struct sge_port_stats *t1_sge_get_port_stats(struct sge *sge, int port)
  660. {
  661. return &sge->port_stats[port];
  662. }
  663. /**
  664. * recycle_fl_buf - recycle a free list buffer
  665. * @fl: the free list
  666. * @idx: index of buffer to recycle
  667. *
  668. * Recycles the specified buffer on the given free list by adding it at
  669. * the next available slot on the list.
  670. */
  671. static void recycle_fl_buf(struct freelQ *fl, int idx)
  672. {
  673. struct freelQ_e *from = &fl->entries[idx];
  674. struct freelQ_e *to = &fl->entries[fl->pidx];
  675. fl->centries[fl->pidx] = fl->centries[idx];
  676. to->addr_lo = from->addr_lo;
  677. to->addr_hi = from->addr_hi;
  678. to->len_gen = G_CMD_LEN(from->len_gen) | V_CMD_GEN1(fl->genbit);
  679. wmb();
  680. to->gen2 = V_CMD_GEN2(fl->genbit);
  681. fl->credits++;
  682. if (++fl->pidx == fl->size) {
  683. fl->pidx = 0;
  684. fl->genbit ^= 1;
  685. }
  686. }
  687. /**
  688. * get_packet - return the next ingress packet buffer
  689. * @pdev: the PCI device that received the packet
  690. * @fl: the SGE free list holding the packet
  691. * @len: the actual packet length, excluding any SGE padding
  692. * @dma_pad: padding at beginning of buffer left by SGE DMA
  693. * @skb_pad: padding to be used if the packet is copied
  694. * @copy_thres: length threshold under which a packet should be copied
  695. * @drop_thres: # of remaining buffers before we start dropping packets
  696. *
  697. * Get the next packet from a free list and complete setup of the
  698. * sk_buff. If the packet is small we make a copy and recycle the
  699. * original buffer, otherwise we use the original buffer itself. If a
  700. * positive drop threshold is supplied packets are dropped and their
  701. * buffers recycled if (a) the number of remaining buffers is under the
  702. * threshold and the packet is too big to copy, or (b) the packet should
  703. * be copied but there is no memory for the copy.
  704. */
  705. static inline struct sk_buff *get_packet(struct pci_dev *pdev,
  706. struct freelQ *fl, unsigned int len,
  707. int dma_pad, int skb_pad,
  708. unsigned int copy_thres,
  709. unsigned int drop_thres)
  710. {
  711. struct sk_buff *skb;
  712. struct freelQ_ce *ce = &fl->centries[fl->cidx];
  713. if (len < copy_thres) {
  714. skb = alloc_skb(len + skb_pad, GFP_ATOMIC);
  715. if (likely(skb != NULL)) {
  716. skb_reserve(skb, skb_pad);
  717. skb_put(skb, len);
  718. pci_dma_sync_single_for_cpu(pdev,
  719. pci_unmap_addr(ce, dma_addr),
  720. pci_unmap_len(ce, dma_len),
  721. PCI_DMA_FROMDEVICE);
  722. memcpy(skb->data, ce->skb->data + dma_pad, len);
  723. pci_dma_sync_single_for_device(pdev,
  724. pci_unmap_addr(ce, dma_addr),
  725. pci_unmap_len(ce, dma_len),
  726. PCI_DMA_FROMDEVICE);
  727. } else if (!drop_thres)
  728. goto use_orig_buf;
  729. recycle_fl_buf(fl, fl->cidx);
  730. return skb;
  731. }
  732. if (fl->credits < drop_thres) {
  733. recycle_fl_buf(fl, fl->cidx);
  734. return NULL;
  735. }
  736. use_orig_buf:
  737. pci_unmap_single(pdev, pci_unmap_addr(ce, dma_addr),
  738. pci_unmap_len(ce, dma_len), PCI_DMA_FROMDEVICE);
  739. skb = ce->skb;
  740. skb_reserve(skb, dma_pad);
  741. skb_put(skb, len);
  742. return skb;
  743. }
  744. /**
  745. * unexpected_offload - handle an unexpected offload packet
  746. * @adapter: the adapter
  747. * @fl: the free list that received the packet
  748. *
  749. * Called when we receive an unexpected offload packet (e.g., the TOE
  750. * function is disabled or the card is a NIC). Prints a message and
  751. * recycles the buffer.
  752. */
  753. static void unexpected_offload(struct adapter *adapter, struct freelQ *fl)
  754. {
  755. struct freelQ_ce *ce = &fl->centries[fl->cidx];
  756. struct sk_buff *skb = ce->skb;
  757. pci_dma_sync_single_for_cpu(adapter->pdev, pci_unmap_addr(ce, dma_addr),
  758. pci_unmap_len(ce, dma_len), PCI_DMA_FROMDEVICE);
  759. CH_ERR("%s: unexpected offload packet, cmd %u\n",
  760. adapter->name, *skb->data);
  761. recycle_fl_buf(fl, fl->cidx);
  762. }
  763. /*
  764. * Write the command descriptors to transmit the given skb starting at
  765. * descriptor pidx with the given generation.
  766. */
  767. static inline void write_tx_descs(struct adapter *adapter, struct sk_buff *skb,
  768. unsigned int pidx, unsigned int gen,
  769. struct cmdQ *q)
  770. {
  771. dma_addr_t mapping;
  772. struct cmdQ_e *e, *e1;
  773. struct cmdQ_ce *ce;
  774. unsigned int i, flags, nfrags = skb_shinfo(skb)->nr_frags;
  775. mapping = pci_map_single(adapter->pdev, skb->data,
  776. skb->len - skb->data_len, PCI_DMA_TODEVICE);
  777. ce = &q->centries[pidx];
  778. ce->skb = NULL;
  779. pci_unmap_addr_set(ce, dma_addr, mapping);
  780. pci_unmap_len_set(ce, dma_len, skb->len - skb->data_len);
  781. flags = F_CMD_DATAVALID | F_CMD_SOP | V_CMD_EOP(nfrags == 0) |
  782. V_CMD_GEN2(gen);
  783. e = &q->entries[pidx];
  784. e->addr_lo = (u32)mapping;
  785. e->addr_hi = (u64)mapping >> 32;
  786. e->len_gen = V_CMD_LEN(skb->len - skb->data_len) | V_CMD_GEN1(gen);
  787. for (e1 = e, i = 0; nfrags--; i++) {
  788. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  789. ce++;
  790. e1++;
  791. if (++pidx == q->size) {
  792. pidx = 0;
  793. gen ^= 1;
  794. ce = q->centries;
  795. e1 = q->entries;
  796. }
  797. mapping = pci_map_page(adapter->pdev, frag->page,
  798. frag->page_offset, frag->size,
  799. PCI_DMA_TODEVICE);
  800. ce->skb = NULL;
  801. pci_unmap_addr_set(ce, dma_addr, mapping);
  802. pci_unmap_len_set(ce, dma_len, frag->size);
  803. e1->addr_lo = (u32)mapping;
  804. e1->addr_hi = (u64)mapping >> 32;
  805. e1->len_gen = V_CMD_LEN(frag->size) | V_CMD_GEN1(gen);
  806. e1->flags = F_CMD_DATAVALID | V_CMD_EOP(nfrags == 0) |
  807. V_CMD_GEN2(gen);
  808. }
  809. ce->skb = skb;
  810. wmb();
  811. e->flags = flags;
  812. }
  813. /*
  814. * Clean up completed Tx buffers.
  815. */
  816. static inline void reclaim_completed_tx(struct sge *sge, struct cmdQ *q)
  817. {
  818. unsigned int reclaim = q->processed - q->cleaned;
  819. if (reclaim) {
  820. free_cmdQ_buffers(sge, q, reclaim);
  821. q->cleaned += reclaim;
  822. }
  823. }
  824. #ifndef SET_ETHTOOL_OPS
  825. # define __netif_rx_complete(dev) netif_rx_complete(dev)
  826. #endif
  827. /*
  828. * We cannot use the standard netif_rx_schedule_prep() because we have multiple
  829. * ports plus the TOE all multiplexing onto a single response queue, therefore
  830. * accepting new responses cannot depend on the state of any particular port.
  831. * So define our own equivalent that omits the netif_running() test.
  832. */
  833. static inline int napi_schedule_prep(struct net_device *dev)
  834. {
  835. return !test_and_set_bit(__LINK_STATE_RX_SCHED, &dev->state);
  836. }
  837. /**
  838. * sge_rx - process an ingress ethernet packet
  839. * @sge: the sge structure
  840. * @fl: the free list that contains the packet buffer
  841. * @len: the packet length
  842. *
  843. * Process an ingress ethernet pakcet and deliver it to the stack.
  844. */
  845. static int sge_rx(struct sge *sge, struct freelQ *fl, unsigned int len)
  846. {
  847. struct sk_buff *skb;
  848. struct cpl_rx_pkt *p;
  849. struct adapter *adapter = sge->adapter;
  850. sge->stats.ethernet_pkts++;
  851. skb = get_packet(adapter->pdev, fl, len - sge->rx_pkt_pad,
  852. sge->rx_pkt_pad, 2, SGE_RX_COPY_THRES,
  853. SGE_RX_DROP_THRES);
  854. if (!skb) {
  855. sge->port_stats[0].rx_drops++; /* charge only port 0 for now */
  856. return 0;
  857. }
  858. p = (struct cpl_rx_pkt *)skb->data;
  859. skb_pull(skb, sizeof(*p));
  860. skb->dev = adapter->port[p->iff].dev;
  861. skb->dev->last_rx = jiffies;
  862. skb->protocol = eth_type_trans(skb, skb->dev);
  863. if ((adapter->flags & RX_CSUM_ENABLED) && p->csum == 0xffff &&
  864. skb->protocol == htons(ETH_P_IP) &&
  865. (skb->data[9] == IPPROTO_TCP || skb->data[9] == IPPROTO_UDP)) {
  866. sge->port_stats[p->iff].rx_cso_good++;
  867. skb->ip_summed = CHECKSUM_UNNECESSARY;
  868. } else
  869. skb->ip_summed = CHECKSUM_NONE;
  870. if (unlikely(adapter->vlan_grp && p->vlan_valid)) {
  871. sge->port_stats[p->iff].vlan_xtract++;
  872. if (adapter->params.sge.polling)
  873. vlan_hwaccel_receive_skb(skb, adapter->vlan_grp,
  874. ntohs(p->vlan));
  875. else
  876. vlan_hwaccel_rx(skb, adapter->vlan_grp,
  877. ntohs(p->vlan));
  878. } else if (adapter->params.sge.polling)
  879. netif_receive_skb(skb);
  880. else
  881. netif_rx(skb);
  882. return 0;
  883. }
  884. /*
  885. * Returns true if a command queue has enough available descriptors that
  886. * we can resume Tx operation after temporarily disabling its packet queue.
  887. */
  888. static inline int enough_free_Tx_descs(const struct cmdQ *q)
  889. {
  890. unsigned int r = q->processed - q->cleaned;
  891. return q->in_use - r < (q->size >> 1);
  892. }
  893. /*
  894. * Called when sufficient space has become available in the SGE command queues
  895. * after the Tx packet schedulers have been suspended to restart the Tx path.
  896. */
  897. static void restart_tx_queues(struct sge *sge)
  898. {
  899. struct adapter *adap = sge->adapter;
  900. if (enough_free_Tx_descs(&sge->cmdQ[0])) {
  901. int i;
  902. for_each_port(adap, i) {
  903. struct net_device *nd = adap->port[i].dev;
  904. if (test_and_clear_bit(nd->if_port,
  905. &sge->stopped_tx_queues) &&
  906. netif_running(nd)) {
  907. sge->stats.cmdQ_restarted[2]++;
  908. netif_wake_queue(nd);
  909. }
  910. }
  911. }
  912. }
  913. /*
  914. * update_tx_info is called from the interrupt handler/NAPI to return cmdQ0
  915. * information.
  916. */
  917. static unsigned int update_tx_info(struct adapter *adapter,
  918. unsigned int flags,
  919. unsigned int pr0)
  920. {
  921. struct sge *sge = adapter->sge;
  922. struct cmdQ *cmdq = &sge->cmdQ[0];
  923. cmdq->processed += pr0;
  924. if (flags & F_CMDQ0_ENABLE) {
  925. clear_bit(CMDQ_STAT_RUNNING, &cmdq->status);
  926. if (cmdq->cleaned + cmdq->in_use != cmdq->processed &&
  927. !test_and_set_bit(CMDQ_STAT_LAST_PKT_DB, &cmdq->status)) {
  928. set_bit(CMDQ_STAT_RUNNING, &cmdq->status);
  929. writel(F_CMDQ0_ENABLE, adapter->regs + A_SG_DOORBELL);
  930. }
  931. flags &= ~F_CMDQ0_ENABLE;
  932. }
  933. if (unlikely(sge->stopped_tx_queues != 0))
  934. restart_tx_queues(sge);
  935. return flags;
  936. }
  937. /*
  938. * Process SGE responses, up to the supplied budget. Returns the number of
  939. * responses processed. A negative budget is effectively unlimited.
  940. */
  941. static int process_responses(struct adapter *adapter, int budget)
  942. {
  943. struct sge *sge = adapter->sge;
  944. struct respQ *q = &sge->respQ;
  945. struct respQ_e *e = &q->entries[q->cidx];
  946. int budget_left = budget;
  947. unsigned int flags = 0;
  948. unsigned int cmdq_processed[SGE_CMDQ_N] = {0, 0};
  949. while (likely(budget_left && e->GenerationBit == q->genbit)) {
  950. flags |= e->Qsleeping;
  951. cmdq_processed[0] += e->Cmdq0CreditReturn;
  952. cmdq_processed[1] += e->Cmdq1CreditReturn;
  953. /* We batch updates to the TX side to avoid cacheline
  954. * ping-pong of TX state information on MP where the sender
  955. * might run on a different CPU than this function...
  956. */
  957. if (unlikely(flags & F_CMDQ0_ENABLE || cmdq_processed[0] > 64)) {
  958. flags = update_tx_info(adapter, flags, cmdq_processed[0]);
  959. cmdq_processed[0] = 0;
  960. }
  961. if (unlikely(cmdq_processed[1] > 16)) {
  962. sge->cmdQ[1].processed += cmdq_processed[1];
  963. cmdq_processed[1] = 0;
  964. }
  965. if (likely(e->DataValid)) {
  966. struct freelQ *fl = &sge->freelQ[e->FreelistQid];
  967. BUG_ON(!e->Sop || !e->Eop);
  968. if (unlikely(e->Offload))
  969. unexpected_offload(adapter, fl);
  970. else
  971. sge_rx(sge, fl, e->BufferLength);
  972. /*
  973. * Note: this depends on each packet consuming a
  974. * single free-list buffer; cf. the BUG above.
  975. */
  976. if (++fl->cidx == fl->size)
  977. fl->cidx = 0;
  978. if (unlikely(--fl->credits <
  979. fl->size - SGE_FREEL_REFILL_THRESH))
  980. refill_free_list(sge, fl);
  981. } else
  982. sge->stats.pure_rsps++;
  983. e++;
  984. if (unlikely(++q->cidx == q->size)) {
  985. q->cidx = 0;
  986. q->genbit ^= 1;
  987. e = q->entries;
  988. }
  989. prefetch(e);
  990. if (++q->credits > SGE_RESPQ_REPLENISH_THRES) {
  991. writel(q->credits, adapter->regs + A_SG_RSPQUEUECREDIT);
  992. q->credits = 0;
  993. }
  994. --budget_left;
  995. }
  996. flags = update_tx_info(adapter, flags, cmdq_processed[0]);
  997. sge->cmdQ[1].processed += cmdq_processed[1];
  998. budget -= budget_left;
  999. return budget;
  1000. }
  1001. /*
  1002. * A simpler version of process_responses() that handles only pure (i.e.,
  1003. * non data-carrying) responses. Such respones are too light-weight to justify
  1004. * calling a softirq when using NAPI, so we handle them specially in hard
  1005. * interrupt context. The function is called with a pointer to a response,
  1006. * which the caller must ensure is a valid pure response. Returns 1 if it
  1007. * encounters a valid data-carrying response, 0 otherwise.
  1008. */
  1009. static int process_pure_responses(struct adapter *adapter, struct respQ_e *e)
  1010. {
  1011. struct sge *sge = adapter->sge;
  1012. struct respQ *q = &sge->respQ;
  1013. unsigned int flags = 0;
  1014. unsigned int cmdq_processed[SGE_CMDQ_N] = {0, 0};
  1015. do {
  1016. flags |= e->Qsleeping;
  1017. cmdq_processed[0] += e->Cmdq0CreditReturn;
  1018. cmdq_processed[1] += e->Cmdq1CreditReturn;
  1019. e++;
  1020. if (unlikely(++q->cidx == q->size)) {
  1021. q->cidx = 0;
  1022. q->genbit ^= 1;
  1023. e = q->entries;
  1024. }
  1025. prefetch(e);
  1026. if (++q->credits > SGE_RESPQ_REPLENISH_THRES) {
  1027. writel(q->credits, adapter->regs + A_SG_RSPQUEUECREDIT);
  1028. q->credits = 0;
  1029. }
  1030. sge->stats.pure_rsps++;
  1031. } while (e->GenerationBit == q->genbit && !e->DataValid);
  1032. flags = update_tx_info(adapter, flags, cmdq_processed[0]);
  1033. sge->cmdQ[1].processed += cmdq_processed[1];
  1034. return e->GenerationBit == q->genbit;
  1035. }
  1036. /*
  1037. * Handler for new data events when using NAPI. This does not need any locking
  1038. * or protection from interrupts as data interrupts are off at this point and
  1039. * other adapter interrupts do not interfere.
  1040. */
  1041. static int t1_poll(struct net_device *dev, int *budget)
  1042. {
  1043. struct adapter *adapter = dev->priv;
  1044. int effective_budget = min(*budget, dev->quota);
  1045. int work_done = process_responses(adapter, effective_budget);
  1046. *budget -= work_done;
  1047. dev->quota -= work_done;
  1048. if (work_done >= effective_budget)
  1049. return 1;
  1050. __netif_rx_complete(dev);
  1051. /*
  1052. * Because we don't atomically flush the following write it is
  1053. * possible that in very rare cases it can reach the device in a way
  1054. * that races with a new response being written plus an error interrupt
  1055. * causing the NAPI interrupt handler below to return unhandled status
  1056. * to the OS. To protect against this would require flushing the write
  1057. * and doing both the write and the flush with interrupts off. Way too
  1058. * expensive and unjustifiable given the rarity of the race.
  1059. */
  1060. writel(adapter->sge->respQ.cidx, adapter->regs + A_SG_SLEEPING);
  1061. return 0;
  1062. }
  1063. /*
  1064. * Returns true if the device is already scheduled for polling.
  1065. */
  1066. static inline int napi_is_scheduled(struct net_device *dev)
  1067. {
  1068. return test_bit(__LINK_STATE_RX_SCHED, &dev->state);
  1069. }
  1070. /*
  1071. * NAPI version of the main interrupt handler.
  1072. */
  1073. static irqreturn_t t1_interrupt_napi(int irq, void *data)
  1074. {
  1075. int handled;
  1076. struct adapter *adapter = data;
  1077. struct sge *sge = adapter->sge;
  1078. struct respQ *q = &adapter->sge->respQ;
  1079. /*
  1080. * Clear the SGE_DATA interrupt first thing. Normally the NAPI
  1081. * handler has control of the response queue and the interrupt handler
  1082. * can look at the queue reliably only once it knows NAPI is off.
  1083. * We can't wait that long to clear the SGE_DATA interrupt because we
  1084. * could race with t1_poll rearming the SGE interrupt, so we need to
  1085. * clear the interrupt speculatively and really early on.
  1086. */
  1087. writel(F_PL_INTR_SGE_DATA, adapter->regs + A_PL_CAUSE);
  1088. spin_lock(&adapter->async_lock);
  1089. if (!napi_is_scheduled(sge->netdev)) {
  1090. struct respQ_e *e = &q->entries[q->cidx];
  1091. if (e->GenerationBit == q->genbit) {
  1092. if (e->DataValid ||
  1093. process_pure_responses(adapter, e)) {
  1094. if (likely(napi_schedule_prep(sge->netdev)))
  1095. __netif_rx_schedule(sge->netdev);
  1096. else
  1097. printk(KERN_CRIT
  1098. "NAPI schedule failure!\n");
  1099. } else
  1100. writel(q->cidx, adapter->regs + A_SG_SLEEPING);
  1101. handled = 1;
  1102. goto unlock;
  1103. } else
  1104. writel(q->cidx, adapter->regs + A_SG_SLEEPING);
  1105. } else
  1106. if (readl(adapter->regs + A_PL_CAUSE) & F_PL_INTR_SGE_DATA)
  1107. printk(KERN_ERR "data interrupt while NAPI running\n");
  1108. handled = t1_slow_intr_handler(adapter);
  1109. if (!handled)
  1110. sge->stats.unhandled_irqs++;
  1111. unlock:
  1112. spin_unlock(&adapter->async_lock);
  1113. return IRQ_RETVAL(handled != 0);
  1114. }
  1115. /*
  1116. * Main interrupt handler, optimized assuming that we took a 'DATA'
  1117. * interrupt.
  1118. *
  1119. * 1. Clear the interrupt
  1120. * 2. Loop while we find valid descriptors and process them; accumulate
  1121. * information that can be processed after the loop
  1122. * 3. Tell the SGE at which index we stopped processing descriptors
  1123. * 4. Bookkeeping; free TX buffers, ring doorbell if there are any
  1124. * outstanding TX buffers waiting, replenish RX buffers, potentially
  1125. * reenable upper layers if they were turned off due to lack of TX
  1126. * resources which are available again.
  1127. * 5. If we took an interrupt, but no valid respQ descriptors was found we
  1128. * let the slow_intr_handler run and do error handling.
  1129. */
  1130. static irqreturn_t t1_interrupt(int irq, void *cookie)
  1131. {
  1132. int work_done;
  1133. struct respQ_e *e;
  1134. struct adapter *adapter = cookie;
  1135. struct respQ *Q = &adapter->sge->respQ;
  1136. spin_lock(&adapter->async_lock);
  1137. e = &Q->entries[Q->cidx];
  1138. prefetch(e);
  1139. writel(F_PL_INTR_SGE_DATA, adapter->regs + A_PL_CAUSE);
  1140. if (likely(e->GenerationBit == Q->genbit))
  1141. work_done = process_responses(adapter, -1);
  1142. else
  1143. work_done = t1_slow_intr_handler(adapter);
  1144. /*
  1145. * The unconditional clearing of the PL_CAUSE above may have raced
  1146. * with DMA completion and the corresponding generation of a response
  1147. * to cause us to miss the resulting data interrupt. The next write
  1148. * is also unconditional to recover the missed interrupt and render
  1149. * this race harmless.
  1150. */
  1151. writel(Q->cidx, adapter->regs + A_SG_SLEEPING);
  1152. if (!work_done)
  1153. adapter->sge->stats.unhandled_irqs++;
  1154. spin_unlock(&adapter->async_lock);
  1155. return IRQ_RETVAL(work_done != 0);
  1156. }
  1157. irq_handler_t t1_select_intr_handler(adapter_t *adapter)
  1158. {
  1159. return adapter->params.sge.polling ? t1_interrupt_napi : t1_interrupt;
  1160. }
  1161. /*
  1162. * Enqueues the sk_buff onto the cmdQ[qid] and has hardware fetch it.
  1163. *
  1164. * The code figures out how many entries the sk_buff will require in the
  1165. * cmdQ and updates the cmdQ data structure with the state once the enqueue
  1166. * has complete. Then, it doesn't access the global structure anymore, but
  1167. * uses the corresponding fields on the stack. In conjuction with a spinlock
  1168. * around that code, we can make the function reentrant without holding the
  1169. * lock when we actually enqueue (which might be expensive, especially on
  1170. * architectures with IO MMUs).
  1171. *
  1172. * This runs with softirqs disabled.
  1173. */
  1174. static int t1_sge_tx(struct sk_buff *skb, struct adapter *adapter,
  1175. unsigned int qid, struct net_device *dev)
  1176. {
  1177. struct sge *sge = adapter->sge;
  1178. struct cmdQ *q = &sge->cmdQ[qid];
  1179. unsigned int credits, pidx, genbit, count;
  1180. spin_lock(&q->lock);
  1181. reclaim_completed_tx(sge, q);
  1182. pidx = q->pidx;
  1183. credits = q->size - q->in_use;
  1184. count = 1 + skb_shinfo(skb)->nr_frags;
  1185. { /* Ethernet packet */
  1186. if (unlikely(credits < count)) {
  1187. netif_stop_queue(dev);
  1188. set_bit(dev->if_port, &sge->stopped_tx_queues);
  1189. sge->stats.cmdQ_full[2]++;
  1190. spin_unlock(&q->lock);
  1191. if (!netif_queue_stopped(dev))
  1192. CH_ERR("%s: Tx ring full while queue awake!\n",
  1193. adapter->name);
  1194. return NETDEV_TX_BUSY;
  1195. }
  1196. if (unlikely(credits - count < q->stop_thres)) {
  1197. sge->stats.cmdQ_full[2]++;
  1198. netif_stop_queue(dev);
  1199. set_bit(dev->if_port, &sge->stopped_tx_queues);
  1200. }
  1201. }
  1202. q->in_use += count;
  1203. genbit = q->genbit;
  1204. q->pidx += count;
  1205. if (q->pidx >= q->size) {
  1206. q->pidx -= q->size;
  1207. q->genbit ^= 1;
  1208. }
  1209. spin_unlock(&q->lock);
  1210. write_tx_descs(adapter, skb, pidx, genbit, q);
  1211. /*
  1212. * We always ring the doorbell for cmdQ1. For cmdQ0, we only ring
  1213. * the doorbell if the Q is asleep. There is a natural race, where
  1214. * the hardware is going to sleep just after we checked, however,
  1215. * then the interrupt handler will detect the outstanding TX packet
  1216. * and ring the doorbell for us.
  1217. */
  1218. if (qid)
  1219. doorbell_pio(adapter, F_CMDQ1_ENABLE);
  1220. else {
  1221. clear_bit(CMDQ_STAT_LAST_PKT_DB, &q->status);
  1222. if (test_and_set_bit(CMDQ_STAT_RUNNING, &q->status) == 0) {
  1223. set_bit(CMDQ_STAT_LAST_PKT_DB, &q->status);
  1224. writel(F_CMDQ0_ENABLE, adapter->regs + A_SG_DOORBELL);
  1225. }
  1226. }
  1227. return NETDEV_TX_OK;
  1228. }
  1229. #define MK_ETH_TYPE_MSS(type, mss) (((mss) & 0x3FFF) | ((type) << 14))
  1230. /*
  1231. * eth_hdr_len - return the length of an Ethernet header
  1232. * @data: pointer to the start of the Ethernet header
  1233. *
  1234. * Returns the length of an Ethernet header, including optional VLAN tag.
  1235. */
  1236. static inline int eth_hdr_len(const void *data)
  1237. {
  1238. const struct ethhdr *e = data;
  1239. return e->h_proto == htons(ETH_P_8021Q) ? VLAN_ETH_HLEN : ETH_HLEN;
  1240. }
  1241. /*
  1242. * Adds the CPL header to the sk_buff and passes it to t1_sge_tx.
  1243. */
  1244. int t1_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1245. {
  1246. struct adapter *adapter = dev->priv;
  1247. struct sge_port_stats *st = &adapter->sge->port_stats[dev->if_port];
  1248. struct sge *sge = adapter->sge;
  1249. struct cpl_tx_pkt *cpl;
  1250. #ifdef NETIF_F_TSO
  1251. if (skb_is_gso(skb)) {
  1252. int eth_type;
  1253. struct cpl_tx_pkt_lso *hdr;
  1254. st->tso++;
  1255. eth_type = skb->nh.raw - skb->data == ETH_HLEN ?
  1256. CPL_ETH_II : CPL_ETH_II_VLAN;
  1257. hdr = (struct cpl_tx_pkt_lso *)skb_push(skb, sizeof(*hdr));
  1258. hdr->opcode = CPL_TX_PKT_LSO;
  1259. hdr->ip_csum_dis = hdr->l4_csum_dis = 0;
  1260. hdr->ip_hdr_words = skb->nh.iph->ihl;
  1261. hdr->tcp_hdr_words = skb->h.th->doff;
  1262. hdr->eth_type_mss = htons(MK_ETH_TYPE_MSS(eth_type,
  1263. skb_shinfo(skb)->gso_size));
  1264. hdr->len = htonl(skb->len - sizeof(*hdr));
  1265. cpl = (struct cpl_tx_pkt *)hdr;
  1266. sge->stats.tx_lso_pkts++;
  1267. } else
  1268. #endif
  1269. {
  1270. /*
  1271. * Packets shorter than ETH_HLEN can break the MAC, drop them
  1272. * early. Also, we may get oversized packets because some
  1273. * parts of the kernel don't handle our unusual hard_header_len
  1274. * right, drop those too.
  1275. */
  1276. if (unlikely(skb->len < ETH_HLEN ||
  1277. skb->len > dev->mtu + eth_hdr_len(skb->data))) {
  1278. dev_kfree_skb_any(skb);
  1279. return NETDEV_TX_OK;
  1280. }
  1281. /*
  1282. * We are using a non-standard hard_header_len and some kernel
  1283. * components, such as pktgen, do not handle it right.
  1284. * Complain when this happens but try to fix things up.
  1285. */
  1286. if (unlikely(skb_headroom(skb) <
  1287. dev->hard_header_len - ETH_HLEN)) {
  1288. struct sk_buff *orig_skb = skb;
  1289. if (net_ratelimit())
  1290. printk(KERN_ERR "%s: inadequate headroom in "
  1291. "Tx packet\n", dev->name);
  1292. skb = skb_realloc_headroom(skb, sizeof(*cpl));
  1293. dev_kfree_skb_any(orig_skb);
  1294. if (!skb)
  1295. return NETDEV_TX_OK;
  1296. }
  1297. if (!(adapter->flags & UDP_CSUM_CAPABLE) &&
  1298. skb->ip_summed == CHECKSUM_PARTIAL &&
  1299. skb->nh.iph->protocol == IPPROTO_UDP)
  1300. if (unlikely(skb_checksum_help(skb))) {
  1301. dev_kfree_skb_any(skb);
  1302. return NETDEV_TX_OK;
  1303. }
  1304. /* Hmmm, assuming to catch the gratious arp... and we'll use
  1305. * it to flush out stuck espi packets...
  1306. */
  1307. if (unlikely(!adapter->sge->espibug_skb)) {
  1308. if (skb->protocol == htons(ETH_P_ARP) &&
  1309. skb->nh.arph->ar_op == htons(ARPOP_REQUEST)) {
  1310. adapter->sge->espibug_skb = skb;
  1311. /* We want to re-use this skb later. We
  1312. * simply bump the reference count and it
  1313. * will not be freed...
  1314. */
  1315. skb = skb_get(skb);
  1316. }
  1317. }
  1318. cpl = (struct cpl_tx_pkt *)__skb_push(skb, sizeof(*cpl));
  1319. cpl->opcode = CPL_TX_PKT;
  1320. cpl->ip_csum_dis = 1; /* SW calculates IP csum */
  1321. cpl->l4_csum_dis = skb->ip_summed == CHECKSUM_PARTIAL ? 0 : 1;
  1322. /* the length field isn't used so don't bother setting it */
  1323. st->tx_cso += (skb->ip_summed == CHECKSUM_PARTIAL);
  1324. sge->stats.tx_do_cksum += (skb->ip_summed == CHECKSUM_PARTIAL);
  1325. sge->stats.tx_reg_pkts++;
  1326. }
  1327. cpl->iff = dev->if_port;
  1328. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  1329. if (adapter->vlan_grp && vlan_tx_tag_present(skb)) {
  1330. cpl->vlan_valid = 1;
  1331. cpl->vlan = htons(vlan_tx_tag_get(skb));
  1332. st->vlan_insert++;
  1333. } else
  1334. #endif
  1335. cpl->vlan_valid = 0;
  1336. dev->trans_start = jiffies;
  1337. return t1_sge_tx(skb, adapter, 0, dev);
  1338. }
  1339. /*
  1340. * Callback for the Tx buffer reclaim timer. Runs with softirqs disabled.
  1341. */
  1342. static void sge_tx_reclaim_cb(unsigned long data)
  1343. {
  1344. int i;
  1345. struct sge *sge = (struct sge *)data;
  1346. for (i = 0; i < SGE_CMDQ_N; ++i) {
  1347. struct cmdQ *q = &sge->cmdQ[i];
  1348. if (!spin_trylock(&q->lock))
  1349. continue;
  1350. reclaim_completed_tx(sge, q);
  1351. if (i == 0 && q->in_use) /* flush pending credits */
  1352. writel(F_CMDQ0_ENABLE,
  1353. sge->adapter->regs + A_SG_DOORBELL);
  1354. spin_unlock(&q->lock);
  1355. }
  1356. mod_timer(&sge->tx_reclaim_timer, jiffies + TX_RECLAIM_PERIOD);
  1357. }
  1358. /*
  1359. * Propagate changes of the SGE coalescing parameters to the HW.
  1360. */
  1361. int t1_sge_set_coalesce_params(struct sge *sge, struct sge_params *p)
  1362. {
  1363. sge->netdev->poll = t1_poll;
  1364. sge->fixed_intrtimer = p->rx_coalesce_usecs *
  1365. core_ticks_per_usec(sge->adapter);
  1366. writel(sge->fixed_intrtimer, sge->adapter->regs + A_SG_INTRTIMER);
  1367. return 0;
  1368. }
  1369. /*
  1370. * Allocates both RX and TX resources and configures the SGE. However,
  1371. * the hardware is not enabled yet.
  1372. */
  1373. int t1_sge_configure(struct sge *sge, struct sge_params *p)
  1374. {
  1375. if (alloc_rx_resources(sge, p))
  1376. return -ENOMEM;
  1377. if (alloc_tx_resources(sge, p)) {
  1378. free_rx_resources(sge);
  1379. return -ENOMEM;
  1380. }
  1381. configure_sge(sge, p);
  1382. /*
  1383. * Now that we have sized the free lists calculate the payload
  1384. * capacity of the large buffers. Other parts of the driver use
  1385. * this to set the max offload coalescing size so that RX packets
  1386. * do not overflow our large buffers.
  1387. */
  1388. p->large_buf_capacity = jumbo_payload_capacity(sge);
  1389. return 0;
  1390. }
  1391. /*
  1392. * Disables the DMA engine.
  1393. */
  1394. void t1_sge_stop(struct sge *sge)
  1395. {
  1396. writel(0, sge->adapter->regs + A_SG_CONTROL);
  1397. (void) readl(sge->adapter->regs + A_SG_CONTROL); /* flush */
  1398. if (is_T2(sge->adapter))
  1399. del_timer_sync(&sge->espibug_timer);
  1400. del_timer_sync(&sge->tx_reclaim_timer);
  1401. }
  1402. /*
  1403. * Enables the DMA engine.
  1404. */
  1405. void t1_sge_start(struct sge *sge)
  1406. {
  1407. refill_free_list(sge, &sge->freelQ[0]);
  1408. refill_free_list(sge, &sge->freelQ[1]);
  1409. writel(sge->sge_control, sge->adapter->regs + A_SG_CONTROL);
  1410. doorbell_pio(sge->adapter, F_FL0_ENABLE | F_FL1_ENABLE);
  1411. (void) readl(sge->adapter->regs + A_SG_CONTROL); /* flush */
  1412. mod_timer(&sge->tx_reclaim_timer, jiffies + TX_RECLAIM_PERIOD);
  1413. if (is_T2(sge->adapter))
  1414. mod_timer(&sge->espibug_timer, jiffies + sge->espibug_timeout);
  1415. }
  1416. /*
  1417. * Callback for the T2 ESPI 'stuck packet feature' workaorund
  1418. */
  1419. static void espibug_workaround(void *data)
  1420. {
  1421. struct adapter *adapter = (struct adapter *)data;
  1422. struct sge *sge = adapter->sge;
  1423. if (netif_running(adapter->port[0].dev)) {
  1424. struct sk_buff *skb = sge->espibug_skb;
  1425. u32 seop = t1_espi_get_mon(adapter, 0x930, 0);
  1426. if ((seop & 0xfff0fff) == 0xfff && skb) {
  1427. if (!skb->cb[0]) {
  1428. u8 ch_mac_addr[ETH_ALEN] =
  1429. {0x0, 0x7, 0x43, 0x0, 0x0, 0x0};
  1430. memcpy(skb->data + sizeof(struct cpl_tx_pkt),
  1431. ch_mac_addr, ETH_ALEN);
  1432. memcpy(skb->data + skb->len - 10, ch_mac_addr,
  1433. ETH_ALEN);
  1434. skb->cb[0] = 0xff;
  1435. }
  1436. /* bump the reference count to avoid freeing of the
  1437. * skb once the DMA has completed.
  1438. */
  1439. skb = skb_get(skb);
  1440. t1_sge_tx(skb, adapter, 0, adapter->port[0].dev);
  1441. }
  1442. }
  1443. mod_timer(&sge->espibug_timer, jiffies + sge->espibug_timeout);
  1444. }
  1445. /*
  1446. * Creates a t1_sge structure and returns suggested resource parameters.
  1447. */
  1448. struct sge * __devinit t1_sge_create(struct adapter *adapter,
  1449. struct sge_params *p)
  1450. {
  1451. struct sge *sge = kmalloc(sizeof(*sge), GFP_KERNEL);
  1452. if (!sge)
  1453. return NULL;
  1454. memset(sge, 0, sizeof(*sge));
  1455. sge->adapter = adapter;
  1456. sge->netdev = adapter->port[0].dev;
  1457. sge->rx_pkt_pad = t1_is_T1B(adapter) ? 0 : 2;
  1458. sge->jumbo_fl = t1_is_T1B(adapter) ? 1 : 0;
  1459. init_timer(&sge->tx_reclaim_timer);
  1460. sge->tx_reclaim_timer.data = (unsigned long)sge;
  1461. sge->tx_reclaim_timer.function = sge_tx_reclaim_cb;
  1462. if (is_T2(sge->adapter)) {
  1463. init_timer(&sge->espibug_timer);
  1464. sge->espibug_timer.function = (void *)&espibug_workaround;
  1465. sge->espibug_timer.data = (unsigned long)sge->adapter;
  1466. sge->espibug_timeout = 1;
  1467. }
  1468. p->cmdQ_size[0] = SGE_CMDQ0_E_N;
  1469. p->cmdQ_size[1] = SGE_CMDQ1_E_N;
  1470. p->freelQ_size[!sge->jumbo_fl] = SGE_FREEL_SIZE;
  1471. p->freelQ_size[sge->jumbo_fl] = SGE_JUMBO_FREEL_SIZE;
  1472. p->rx_coalesce_usecs = 50;
  1473. p->coalesce_enable = 0;
  1474. p->sample_interval_usecs = 0;
  1475. p->polling = 0;
  1476. return sge;
  1477. }