sge.c 48 KB

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