tilepro.c 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493
  1. /*
  2. * Copyright 2011 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/moduleparam.h>
  17. #include <linux/sched.h>
  18. #include <linux/kernel.h> /* printk() */
  19. #include <linux/slab.h> /* kmalloc() */
  20. #include <linux/errno.h> /* error codes */
  21. #include <linux/types.h> /* size_t */
  22. #include <linux/interrupt.h>
  23. #include <linux/in.h>
  24. #include <linux/netdevice.h> /* struct device, and other headers */
  25. #include <linux/etherdevice.h> /* eth_type_trans */
  26. #include <linux/skbuff.h>
  27. #include <linux/ioctl.h>
  28. #include <linux/cdev.h>
  29. #include <linux/hugetlb.h>
  30. #include <linux/in6.h>
  31. #include <linux/timer.h>
  32. #include <linux/io.h>
  33. #include <asm/checksum.h>
  34. #include <asm/homecache.h>
  35. #include <hv/drv_xgbe_intf.h>
  36. #include <hv/drv_xgbe_impl.h>
  37. #include <hv/hypervisor.h>
  38. #include <hv/netio_intf.h>
  39. /* For TSO */
  40. #include <linux/ip.h>
  41. #include <linux/tcp.h>
  42. /*
  43. * First, "tile_net_init_module()" initializes all four "devices" which
  44. * can be used by linux.
  45. *
  46. * Then, "ifconfig DEVICE up" calls "tile_net_open()", which analyzes
  47. * the network cpus, then uses "tile_net_open_aux()" to initialize
  48. * LIPP/LEPP, and then uses "tile_net_open_inner()" to register all
  49. * the tiles, provide buffers to LIPP, allow ingress to start, and
  50. * turn on hypervisor interrupt handling (and NAPI) on all tiles.
  51. *
  52. * If registration fails due to the link being down, then "retry_work"
  53. * is used to keep calling "tile_net_open_inner()" until it succeeds.
  54. *
  55. * If "ifconfig DEVICE down" is called, it uses "tile_net_stop()" to
  56. * stop egress, drain the LIPP buffers, unregister all the tiles, stop
  57. * LIPP/LEPP, and wipe the LEPP queue.
  58. *
  59. * We start out with the ingress interrupt enabled on each CPU. When
  60. * this interrupt fires, we disable it, and call "napi_schedule()".
  61. * This will cause "tile_net_poll()" to be called, which will pull
  62. * packets from the netio queue, filtering them out, or passing them
  63. * to "netif_receive_skb()". If our budget is exhausted, we will
  64. * return, knowing we will be called again later. Otherwise, we
  65. * reenable the ingress interrupt, and call "napi_complete()".
  66. *
  67. * HACK: Since disabling the ingress interrupt is not reliable, we
  68. * ignore the interrupt if the global "active" flag is false.
  69. *
  70. *
  71. * NOTE: The use of "native_driver" ensures that EPP exists, and that
  72. * we are using "LIPP" and "LEPP".
  73. *
  74. * NOTE: Failing to free completions for an arbitrarily long time
  75. * (which is defined to be illegal) does in fact cause bizarre
  76. * problems. The "egress_timer" helps prevent this from happening.
  77. */
  78. /* HACK: Allow use of "jumbo" packets. */
  79. /* This should be 1500 if "jumbo" is not set in LIPP. */
  80. /* This should be at most 10226 (10240 - 14) if "jumbo" is set in LIPP. */
  81. /* ISSUE: This has not been thoroughly tested (except at 1500). */
  82. #define TILE_NET_MTU 1500
  83. /* HACK: Define to support GSO. */
  84. /* ISSUE: This may actually hurt performance of the TCP blaster. */
  85. /* #define TILE_NET_GSO */
  86. /* Define this to collapse "duplicate" acks. */
  87. /* #define IGNORE_DUP_ACKS */
  88. /* HACK: Define this to verify incoming packets. */
  89. /* #define TILE_NET_VERIFY_INGRESS */
  90. /* Use 3000 to enable the Linux Traffic Control (QoS) layer, else 0. */
  91. #define TILE_NET_TX_QUEUE_LEN 0
  92. /* Define to dump packets (prints out the whole packet on tx and rx). */
  93. /* #define TILE_NET_DUMP_PACKETS */
  94. /* Define to enable debug spew (all PDEBUG's are enabled). */
  95. /* #define TILE_NET_DEBUG */
  96. /* Define to activate paranoia checks. */
  97. /* #define TILE_NET_PARANOIA */
  98. /* Default transmit lockup timeout period, in jiffies. */
  99. #define TILE_NET_TIMEOUT (5 * HZ)
  100. /* Default retry interval for bringing up the NetIO interface, in jiffies. */
  101. #define TILE_NET_RETRY_INTERVAL (5 * HZ)
  102. /* Number of ports (xgbe0, xgbe1, gbe0, gbe1). */
  103. #define TILE_NET_DEVS 4
  104. /* Paranoia. */
  105. #if NET_IP_ALIGN != LIPP_PACKET_PADDING
  106. #error "NET_IP_ALIGN must match LIPP_PACKET_PADDING."
  107. #endif
  108. /* Debug print. */
  109. #ifdef TILE_NET_DEBUG
  110. #define PDEBUG(fmt, args...) net_printk(fmt, ## args)
  111. #else
  112. #define PDEBUG(fmt, args...)
  113. #endif
  114. MODULE_AUTHOR("Tilera");
  115. MODULE_LICENSE("GPL");
  116. /*
  117. * Queue of incoming packets for a specific cpu and device.
  118. *
  119. * Includes a pointer to the "system" data, and the actual "user" data.
  120. */
  121. struct tile_netio_queue {
  122. netio_queue_impl_t *__system_part;
  123. netio_queue_user_impl_t __user_part;
  124. };
  125. /*
  126. * Statistics counters for a specific cpu and device.
  127. */
  128. struct tile_net_stats_t {
  129. u32 rx_packets;
  130. u32 rx_bytes;
  131. u32 tx_packets;
  132. u32 tx_bytes;
  133. };
  134. /*
  135. * Info for a specific cpu and device.
  136. *
  137. * ISSUE: There is a "dev" pointer in "napi" as well.
  138. */
  139. struct tile_net_cpu {
  140. /* The NAPI struct. */
  141. struct napi_struct napi;
  142. /* Packet queue. */
  143. struct tile_netio_queue queue;
  144. /* Statistics. */
  145. struct tile_net_stats_t stats;
  146. /* True iff NAPI is enabled. */
  147. bool napi_enabled;
  148. /* True if this tile has successfully registered with the IPP. */
  149. bool registered;
  150. /* True if the link was down last time we tried to register. */
  151. bool link_down;
  152. /* True if "egress_timer" is scheduled. */
  153. bool egress_timer_scheduled;
  154. /* Number of small sk_buffs which must still be provided. */
  155. unsigned int num_needed_small_buffers;
  156. /* Number of large sk_buffs which must still be provided. */
  157. unsigned int num_needed_large_buffers;
  158. /* A timer for handling egress completions. */
  159. struct timer_list egress_timer;
  160. };
  161. /*
  162. * Info for a specific device.
  163. */
  164. struct tile_net_priv {
  165. /* Our network device. */
  166. struct net_device *dev;
  167. /* Pages making up the egress queue. */
  168. struct page *eq_pages;
  169. /* Address of the actual egress queue. */
  170. lepp_queue_t *eq;
  171. /* Protects "eq". */
  172. spinlock_t eq_lock;
  173. /* The hypervisor handle for this interface. */
  174. int hv_devhdl;
  175. /* The intr bit mask that IDs this device. */
  176. u32 intr_id;
  177. /* True iff "tile_net_open_aux()" has succeeded. */
  178. bool partly_opened;
  179. /* True iff the device is "active". */
  180. bool active;
  181. /* Effective network cpus. */
  182. struct cpumask network_cpus_map;
  183. /* Number of network cpus. */
  184. int network_cpus_count;
  185. /* Credits per network cpu. */
  186. int network_cpus_credits;
  187. /* Network stats. */
  188. struct net_device_stats stats;
  189. /* For NetIO bringup retries. */
  190. struct delayed_work retry_work;
  191. /* Quick access to per cpu data. */
  192. struct tile_net_cpu *cpu[NR_CPUS];
  193. };
  194. /* Log2 of the number of small pages needed for the egress queue. */
  195. #define EQ_ORDER get_order(sizeof(lepp_queue_t))
  196. /* Size of the egress queue's pages. */
  197. #define EQ_SIZE (1 << (PAGE_SHIFT + EQ_ORDER))
  198. /*
  199. * The actual devices (xgbe0, xgbe1, gbe0, gbe1).
  200. */
  201. static struct net_device *tile_net_devs[TILE_NET_DEVS];
  202. /*
  203. * The "tile_net_cpu" structures for each device.
  204. */
  205. static DEFINE_PER_CPU(struct tile_net_cpu, hv_xgbe0);
  206. static DEFINE_PER_CPU(struct tile_net_cpu, hv_xgbe1);
  207. static DEFINE_PER_CPU(struct tile_net_cpu, hv_gbe0);
  208. static DEFINE_PER_CPU(struct tile_net_cpu, hv_gbe1);
  209. /*
  210. * True if "network_cpus" was specified.
  211. */
  212. static bool network_cpus_used;
  213. /*
  214. * The actual cpus in "network_cpus".
  215. */
  216. static struct cpumask network_cpus_map;
  217. #ifdef TILE_NET_DEBUG
  218. /*
  219. * printk with extra stuff.
  220. *
  221. * We print the CPU we're running in brackets.
  222. */
  223. static void net_printk(char *fmt, ...)
  224. {
  225. int i;
  226. int len;
  227. va_list args;
  228. static char buf[256];
  229. len = sprintf(buf, "tile_net[%2.2d]: ", smp_processor_id());
  230. va_start(args, fmt);
  231. i = vscnprintf(buf + len, sizeof(buf) - len - 1, fmt, args);
  232. va_end(args);
  233. buf[255] = '\0';
  234. pr_notice(buf);
  235. }
  236. #endif
  237. #ifdef TILE_NET_DUMP_PACKETS
  238. /*
  239. * Dump a packet.
  240. */
  241. static void dump_packet(unsigned char *data, unsigned long length, char *s)
  242. {
  243. int my_cpu = smp_processor_id();
  244. unsigned long i;
  245. char buf[128];
  246. static unsigned int count;
  247. pr_info("dump_packet(data %p, length 0x%lx s %s count 0x%x)\n",
  248. data, length, s, count++);
  249. pr_info("\n");
  250. for (i = 0; i < length; i++) {
  251. if ((i & 0xf) == 0)
  252. sprintf(buf, "[%02d] %8.8lx:", my_cpu, i);
  253. sprintf(buf + strlen(buf), " %2.2x", data[i]);
  254. if ((i & 0xf) == 0xf || i == length - 1) {
  255. strcat(buf, "\n");
  256. pr_info("%s", buf);
  257. }
  258. }
  259. }
  260. #endif
  261. /*
  262. * Provide support for the __netio_fastio1() swint
  263. * (see <hv/drv_xgbe_intf.h> for how it is used).
  264. *
  265. * The fastio swint2 call may clobber all the caller-saved registers.
  266. * It rarely clobbers memory, but we allow for the possibility in
  267. * the signature just to be on the safe side.
  268. *
  269. * Also, gcc doesn't seem to allow an input operand to be
  270. * clobbered, so we fake it with dummy outputs.
  271. *
  272. * This function can't be static because of the way it is declared
  273. * in the netio header.
  274. */
  275. inline int __netio_fastio1(u32 fastio_index, u32 arg0)
  276. {
  277. long result, clobber_r1, clobber_r10;
  278. asm volatile("swint2"
  279. : "=R00" (result),
  280. "=R01" (clobber_r1), "=R10" (clobber_r10)
  281. : "R10" (fastio_index), "R01" (arg0)
  282. : "memory", "r2", "r3", "r4",
  283. "r5", "r6", "r7", "r8", "r9",
  284. "r11", "r12", "r13", "r14",
  285. "r15", "r16", "r17", "r18", "r19",
  286. "r20", "r21", "r22", "r23", "r24",
  287. "r25", "r26", "r27", "r28", "r29");
  288. return result;
  289. }
  290. static void tile_net_return_credit(struct tile_net_cpu *info)
  291. {
  292. struct tile_netio_queue *queue = &info->queue;
  293. netio_queue_user_impl_t *qup = &queue->__user_part;
  294. /* Return four credits after every fourth packet. */
  295. if (--qup->__receive_credit_remaining == 0) {
  296. u32 interval = qup->__receive_credit_interval;
  297. qup->__receive_credit_remaining = interval;
  298. __netio_fastio_return_credits(qup->__fastio_index, interval);
  299. }
  300. }
  301. /*
  302. * Provide a linux buffer to LIPP.
  303. */
  304. static void tile_net_provide_linux_buffer(struct tile_net_cpu *info,
  305. void *va, bool small)
  306. {
  307. struct tile_netio_queue *queue = &info->queue;
  308. /* Convert "va" and "small" to "linux_buffer_t". */
  309. unsigned int buffer = ((unsigned int)(__pa(va) >> 7) << 1) + small;
  310. __netio_fastio_free_buffer(queue->__user_part.__fastio_index, buffer);
  311. }
  312. /*
  313. * Provide a linux buffer for LIPP.
  314. *
  315. * Note that the ACTUAL allocation for each buffer is a "struct sk_buff",
  316. * plus a chunk of memory that includes not only the requested bytes, but
  317. * also NET_SKB_PAD bytes of initial padding, and a "struct skb_shared_info".
  318. *
  319. * Note that "struct skb_shared_info" is 88 bytes with 64K pages and
  320. * 268 bytes with 4K pages (since the frags[] array needs 18 entries).
  321. *
  322. * Without jumbo packets, the maximum packet size will be 1536 bytes,
  323. * and we use 2 bytes (NET_IP_ALIGN) of padding. ISSUE: If we told
  324. * the hardware to clip at 1518 bytes instead of 1536 bytes, then we
  325. * could save an entire cache line, but in practice, we don't need it.
  326. *
  327. * Since CPAs are 38 bits, and we can only encode the high 31 bits in
  328. * a "linux_buffer_t", the low 7 bits must be zero, and thus, we must
  329. * align the actual "va" mod 128.
  330. *
  331. * We assume that the underlying "head" will be aligned mod 64. Note
  332. * that in practice, we have seen "head" NOT aligned mod 128 even when
  333. * using 2048 byte allocations, which is surprising.
  334. *
  335. * If "head" WAS always aligned mod 128, we could change LIPP to
  336. * assume that the low SIX bits are zero, and the 7th bit is one, that
  337. * is, align the actual "va" mod 128 plus 64, which would be "free".
  338. *
  339. * For now, the actual "head" pointer points at NET_SKB_PAD bytes of
  340. * padding, plus 28 or 92 bytes of extra padding, plus the sk_buff
  341. * pointer, plus the NET_IP_ALIGN padding, plus 126 or 1536 bytes for
  342. * the actual packet, plus 62 bytes of empty padding, plus some
  343. * padding and the "struct skb_shared_info".
  344. *
  345. * With 64K pages, a large buffer thus needs 32+92+4+2+1536+62+88
  346. * bytes, or 1816 bytes, which fits comfortably into 2048 bytes.
  347. *
  348. * With 64K pages, a small buffer thus needs 32+92+4+2+126+88
  349. * bytes, or 344 bytes, which means we are wasting 64+ bytes, and
  350. * could presumably increase the size of small buffers.
  351. *
  352. * With 4K pages, a large buffer thus needs 32+92+4+2+1536+62+268
  353. * bytes, or 1996 bytes, which fits comfortably into 2048 bytes.
  354. *
  355. * With 4K pages, a small buffer thus needs 32+92+4+2+126+268
  356. * bytes, or 524 bytes, which is annoyingly wasteful.
  357. *
  358. * Maybe we should increase LIPP_SMALL_PACKET_SIZE to 192?
  359. *
  360. * ISSUE: Maybe we should increase "NET_SKB_PAD" to 64?
  361. */
  362. static bool tile_net_provide_needed_buffer(struct tile_net_cpu *info,
  363. bool small)
  364. {
  365. #if TILE_NET_MTU <= 1536
  366. /* Without "jumbo", 2 + 1536 should be sufficient. */
  367. unsigned int large_size = NET_IP_ALIGN + 1536;
  368. #else
  369. /* ISSUE: This has not been tested. */
  370. unsigned int large_size = NET_IP_ALIGN + TILE_NET_MTU + 100;
  371. #endif
  372. /* Avoid "false sharing" with last cache line. */
  373. /* ISSUE: This is already done by "netdev_alloc_skb()". */
  374. unsigned int len =
  375. (((small ? LIPP_SMALL_PACKET_SIZE : large_size) +
  376. CHIP_L2_LINE_SIZE() - 1) & -CHIP_L2_LINE_SIZE());
  377. unsigned int padding = 128 - NET_SKB_PAD;
  378. unsigned int align;
  379. struct sk_buff *skb;
  380. void *va;
  381. struct sk_buff **skb_ptr;
  382. /* Request 96 extra bytes for alignment purposes. */
  383. skb = netdev_alloc_skb(info->napi.dev, len + padding);
  384. if (skb == NULL)
  385. return false;
  386. /* Skip 32 or 96 bytes to align "data" mod 128. */
  387. align = -(long)skb->data & (128 - 1);
  388. BUG_ON(align > padding);
  389. skb_reserve(skb, align);
  390. /* This address is given to IPP. */
  391. va = skb->data;
  392. /* Buffers must not span a huge page. */
  393. BUG_ON(((((long)va & ~HPAGE_MASK) + len) & HPAGE_MASK) != 0);
  394. #ifdef TILE_NET_PARANOIA
  395. #if CHIP_HAS_CBOX_HOME_MAP()
  396. if (hash_default) {
  397. HV_PTE pte = *virt_to_pte(current->mm, (unsigned long)va);
  398. if (hv_pte_get_mode(pte) != HV_PTE_MODE_CACHE_HASH_L3)
  399. panic("Non-HFH ingress buffer! VA=%p Mode=%d PTE=%llx",
  400. va, hv_pte_get_mode(pte), hv_pte_val(pte));
  401. }
  402. #endif
  403. #endif
  404. /* Invalidate the packet buffer. */
  405. if (!hash_default)
  406. __inv_buffer(va, len);
  407. /* Skip two bytes to satisfy LIPP assumptions. */
  408. /* Note that this aligns IP on a 16 byte boundary. */
  409. /* ISSUE: Do this when the packet arrives? */
  410. skb_reserve(skb, NET_IP_ALIGN);
  411. /* Save a back-pointer to 'skb'. */
  412. skb_ptr = va - sizeof(*skb_ptr);
  413. *skb_ptr = skb;
  414. /* Make sure "skb_ptr" has been flushed. */
  415. __insn_mf();
  416. /* Provide the new buffer. */
  417. tile_net_provide_linux_buffer(info, va, small);
  418. return true;
  419. }
  420. /*
  421. * Provide linux buffers for LIPP.
  422. */
  423. static void tile_net_provide_needed_buffers(struct tile_net_cpu *info)
  424. {
  425. while (info->num_needed_small_buffers != 0) {
  426. if (!tile_net_provide_needed_buffer(info, true))
  427. goto oops;
  428. info->num_needed_small_buffers--;
  429. }
  430. while (info->num_needed_large_buffers != 0) {
  431. if (!tile_net_provide_needed_buffer(info, false))
  432. goto oops;
  433. info->num_needed_large_buffers--;
  434. }
  435. return;
  436. oops:
  437. /* Add a description to the page allocation failure dump. */
  438. pr_notice("Could not provide a linux buffer to LIPP.\n");
  439. }
  440. /*
  441. * Grab some LEPP completions, and store them in "comps", of size
  442. * "comps_size", and return the number of completions which were
  443. * stored, so the caller can free them.
  444. */
  445. static unsigned int tile_net_lepp_grab_comps(lepp_queue_t *eq,
  446. struct sk_buff *comps[],
  447. unsigned int comps_size,
  448. unsigned int min_size)
  449. {
  450. unsigned int n = 0;
  451. unsigned int comp_head = eq->comp_head;
  452. unsigned int comp_busy = eq->comp_busy;
  453. while (comp_head != comp_busy && n < comps_size) {
  454. comps[n++] = eq->comps[comp_head];
  455. LEPP_QINC(comp_head);
  456. }
  457. if (n < min_size)
  458. return 0;
  459. eq->comp_head = comp_head;
  460. return n;
  461. }
  462. /*
  463. * Free some comps, and return true iff there are still some pending.
  464. */
  465. static bool tile_net_lepp_free_comps(struct net_device *dev, bool all)
  466. {
  467. struct tile_net_priv *priv = netdev_priv(dev);
  468. lepp_queue_t *eq = priv->eq;
  469. struct sk_buff *olds[64];
  470. unsigned int wanted = 64;
  471. unsigned int i, n;
  472. bool pending;
  473. spin_lock(&priv->eq_lock);
  474. if (all)
  475. eq->comp_busy = eq->comp_tail;
  476. n = tile_net_lepp_grab_comps(eq, olds, wanted, 0);
  477. pending = (eq->comp_head != eq->comp_tail);
  478. spin_unlock(&priv->eq_lock);
  479. for (i = 0; i < n; i++)
  480. kfree_skb(olds[i]);
  481. return pending;
  482. }
  483. /*
  484. * Make sure the egress timer is scheduled.
  485. *
  486. * Note that we use "schedule if not scheduled" logic instead of the more
  487. * obvious "reschedule" logic, because "reschedule" is fairly expensive.
  488. */
  489. static void tile_net_schedule_egress_timer(struct tile_net_cpu *info)
  490. {
  491. if (!info->egress_timer_scheduled) {
  492. mod_timer_pinned(&info->egress_timer, jiffies + 1);
  493. info->egress_timer_scheduled = true;
  494. }
  495. }
  496. /*
  497. * The "function" for "info->egress_timer".
  498. *
  499. * This timer will reschedule itself as long as there are any pending
  500. * completions expected (on behalf of any tile).
  501. *
  502. * ISSUE: Realistically, will the timer ever stop scheduling itself?
  503. *
  504. * ISSUE: This timer is almost never actually needed, so just use a global
  505. * timer that can run on any tile.
  506. *
  507. * ISSUE: Maybe instead track number of expected completions, and free
  508. * only that many, resetting to zero if "pending" is ever false.
  509. */
  510. static void tile_net_handle_egress_timer(unsigned long arg)
  511. {
  512. struct tile_net_cpu *info = (struct tile_net_cpu *)arg;
  513. struct net_device *dev = info->napi.dev;
  514. /* The timer is no longer scheduled. */
  515. info->egress_timer_scheduled = false;
  516. /* Free comps, and reschedule timer if more are pending. */
  517. if (tile_net_lepp_free_comps(dev, false))
  518. tile_net_schedule_egress_timer(info);
  519. }
  520. #ifdef IGNORE_DUP_ACKS
  521. /*
  522. * Help detect "duplicate" ACKs. These are sequential packets (for a
  523. * given flow) which are exactly 66 bytes long, sharing everything but
  524. * ID=2@0x12, Hsum=2@0x18, Ack=4@0x2a, WinSize=2@0x30, Csum=2@0x32,
  525. * Tstamps=10@0x38. The ID's are +1, the Hsum's are -1, the Ack's are
  526. * +N, and the Tstamps are usually identical.
  527. *
  528. * NOTE: Apparently truly duplicate acks (with identical "ack" values),
  529. * should not be collapsed, as they are used for some kind of flow control.
  530. */
  531. static bool is_dup_ack(char *s1, char *s2, unsigned int len)
  532. {
  533. int i;
  534. unsigned long long ignorable = 0;
  535. /* Identification. */
  536. ignorable |= (1ULL << 0x12);
  537. ignorable |= (1ULL << 0x13);
  538. /* Header checksum. */
  539. ignorable |= (1ULL << 0x18);
  540. ignorable |= (1ULL << 0x19);
  541. /* ACK. */
  542. ignorable |= (1ULL << 0x2a);
  543. ignorable |= (1ULL << 0x2b);
  544. ignorable |= (1ULL << 0x2c);
  545. ignorable |= (1ULL << 0x2d);
  546. /* WinSize. */
  547. ignorable |= (1ULL << 0x30);
  548. ignorable |= (1ULL << 0x31);
  549. /* Checksum. */
  550. ignorable |= (1ULL << 0x32);
  551. ignorable |= (1ULL << 0x33);
  552. for (i = 0; i < len; i++, ignorable >>= 1) {
  553. if ((ignorable & 1) || (s1[i] == s2[i]))
  554. continue;
  555. #ifdef TILE_NET_DEBUG
  556. /* HACK: Mention non-timestamp diffs. */
  557. if (i < 0x38 && i != 0x2f &&
  558. net_ratelimit())
  559. pr_info("Diff at 0x%x\n", i);
  560. #endif
  561. return false;
  562. }
  563. #ifdef TILE_NET_NO_SUPPRESS_DUP_ACKS
  564. /* HACK: Do not suppress truly duplicate ACKs. */
  565. /* ISSUE: Is this actually necessary or helpful? */
  566. if (s1[0x2a] == s2[0x2a] &&
  567. s1[0x2b] == s2[0x2b] &&
  568. s1[0x2c] == s2[0x2c] &&
  569. s1[0x2d] == s2[0x2d]) {
  570. return false;
  571. }
  572. #endif
  573. return true;
  574. }
  575. #endif
  576. static void tile_net_discard_aux(struct tile_net_cpu *info, int index)
  577. {
  578. struct tile_netio_queue *queue = &info->queue;
  579. netio_queue_impl_t *qsp = queue->__system_part;
  580. netio_queue_user_impl_t *qup = &queue->__user_part;
  581. int index2_aux = index + sizeof(netio_pkt_t);
  582. int index2 =
  583. ((index2_aux ==
  584. qsp->__packet_receive_queue.__last_packet_plus_one) ?
  585. 0 : index2_aux);
  586. netio_pkt_t *pkt = (netio_pkt_t *)((unsigned long) &qsp[1] + index);
  587. /* Extract the "linux_buffer_t". */
  588. unsigned int buffer = pkt->__packet.word;
  589. /* Convert "linux_buffer_t" to "va". */
  590. void *va = __va((phys_addr_t)(buffer >> 1) << 7);
  591. /* Acquire the associated "skb". */
  592. struct sk_buff **skb_ptr = va - sizeof(*skb_ptr);
  593. struct sk_buff *skb = *skb_ptr;
  594. kfree_skb(skb);
  595. /* Consume this packet. */
  596. qup->__packet_receive_read = index2;
  597. }
  598. /*
  599. * Like "tile_net_poll()", but just discard packets.
  600. */
  601. static void tile_net_discard_packets(struct net_device *dev)
  602. {
  603. struct tile_net_priv *priv = netdev_priv(dev);
  604. int my_cpu = smp_processor_id();
  605. struct tile_net_cpu *info = priv->cpu[my_cpu];
  606. struct tile_netio_queue *queue = &info->queue;
  607. netio_queue_impl_t *qsp = queue->__system_part;
  608. netio_queue_user_impl_t *qup = &queue->__user_part;
  609. while (qup->__packet_receive_read !=
  610. qsp->__packet_receive_queue.__packet_write) {
  611. int index = qup->__packet_receive_read;
  612. tile_net_discard_aux(info, index);
  613. }
  614. }
  615. /*
  616. * Handle the next packet. Return true if "processed", false if "filtered".
  617. */
  618. static bool tile_net_poll_aux(struct tile_net_cpu *info, int index)
  619. {
  620. struct net_device *dev = info->napi.dev;
  621. struct tile_netio_queue *queue = &info->queue;
  622. netio_queue_impl_t *qsp = queue->__system_part;
  623. netio_queue_user_impl_t *qup = &queue->__user_part;
  624. struct tile_net_stats_t *stats = &info->stats;
  625. int filter;
  626. int index2_aux = index + sizeof(netio_pkt_t);
  627. int index2 =
  628. ((index2_aux ==
  629. qsp->__packet_receive_queue.__last_packet_plus_one) ?
  630. 0 : index2_aux);
  631. netio_pkt_t *pkt = (netio_pkt_t *)((unsigned long) &qsp[1] + index);
  632. netio_pkt_metadata_t *metadata = NETIO_PKT_METADATA(pkt);
  633. /* Extract the packet size. FIXME: Shouldn't the second line */
  634. /* get subtracted? Mostly moot, since it should be "zero". */
  635. unsigned long len =
  636. (NETIO_PKT_CUSTOM_LENGTH(pkt) +
  637. NET_IP_ALIGN - NETIO_PACKET_PADDING);
  638. /* Extract the "linux_buffer_t". */
  639. unsigned int buffer = pkt->__packet.word;
  640. /* Extract "small" (vs "large"). */
  641. bool small = ((buffer & 1) != 0);
  642. /* Convert "linux_buffer_t" to "va". */
  643. void *va = __va((phys_addr_t)(buffer >> 1) << 7);
  644. /* Extract the packet data pointer. */
  645. /* Compare to "NETIO_PKT_CUSTOM_DATA(pkt)". */
  646. unsigned char *buf = va + NET_IP_ALIGN;
  647. /* Invalidate the packet buffer. */
  648. if (!hash_default)
  649. __inv_buffer(buf, len);
  650. /* ISSUE: Is this needed? */
  651. dev->last_rx = jiffies;
  652. #ifdef TILE_NET_DUMP_PACKETS
  653. dump_packet(buf, len, "rx");
  654. #endif /* TILE_NET_DUMP_PACKETS */
  655. #ifdef TILE_NET_VERIFY_INGRESS
  656. if (!NETIO_PKT_L4_CSUM_CORRECT_M(metadata, pkt) &&
  657. NETIO_PKT_L4_CSUM_CALCULATED_M(metadata, pkt)) {
  658. /* Bug 6624: Includes UDP packets with a "zero" checksum. */
  659. pr_warning("Bad L4 checksum on %d byte packet.\n", len);
  660. }
  661. if (!NETIO_PKT_L3_CSUM_CORRECT_M(metadata, pkt) &&
  662. NETIO_PKT_L3_CSUM_CALCULATED_M(metadata, pkt)) {
  663. dump_packet(buf, len, "rx");
  664. panic("Bad L3 checksum.");
  665. }
  666. switch (NETIO_PKT_STATUS_M(metadata, pkt)) {
  667. case NETIO_PKT_STATUS_OVERSIZE:
  668. if (len >= 64) {
  669. dump_packet(buf, len, "rx");
  670. panic("Unexpected OVERSIZE.");
  671. }
  672. break;
  673. case NETIO_PKT_STATUS_BAD:
  674. pr_warning("Unexpected BAD %ld byte packet.\n", len);
  675. }
  676. #endif
  677. filter = 0;
  678. /* ISSUE: Filter TCP packets with "bad" checksums? */
  679. if (!(dev->flags & IFF_UP)) {
  680. /* Filter packets received before we're up. */
  681. filter = 1;
  682. } else if (NETIO_PKT_STATUS_M(metadata, pkt) == NETIO_PKT_STATUS_BAD) {
  683. /* Filter "truncated" packets. */
  684. filter = 1;
  685. } else if (!(dev->flags & IFF_PROMISC)) {
  686. /* FIXME: Implement HW multicast filter. */
  687. if (!is_multicast_ether_addr(buf)) {
  688. /* Filter packets not for our address. */
  689. const u8 *mine = dev->dev_addr;
  690. filter = compare_ether_addr(mine, buf);
  691. }
  692. }
  693. if (filter) {
  694. /* ISSUE: Update "drop" statistics? */
  695. tile_net_provide_linux_buffer(info, va, small);
  696. } else {
  697. /* Acquire the associated "skb". */
  698. struct sk_buff **skb_ptr = va - sizeof(*skb_ptr);
  699. struct sk_buff *skb = *skb_ptr;
  700. /* Paranoia. */
  701. if (skb->data != buf)
  702. panic("Corrupt linux buffer from LIPP! "
  703. "VA=%p, skb=%p, skb->data=%p\n",
  704. va, skb, skb->data);
  705. /* Encode the actual packet length. */
  706. skb_put(skb, len);
  707. /* NOTE: This call also sets "skb->dev = dev". */
  708. skb->protocol = eth_type_trans(skb, dev);
  709. /* Avoid recomputing "good" TCP/UDP checksums. */
  710. if (NETIO_PKT_L4_CSUM_CORRECT_M(metadata, pkt))
  711. skb->ip_summed = CHECKSUM_UNNECESSARY;
  712. netif_receive_skb(skb);
  713. stats->rx_packets++;
  714. stats->rx_bytes += len;
  715. }
  716. /* ISSUE: It would be nice to defer this until the packet has */
  717. /* actually been processed. */
  718. tile_net_return_credit(info);
  719. /* Consume this packet. */
  720. qup->__packet_receive_read = index2;
  721. return !filter;
  722. }
  723. /*
  724. * Handle some packets for the given device on the current CPU.
  725. *
  726. * If "tile_net_stop()" is called on some other tile while this
  727. * function is running, we will return, hopefully before that
  728. * other tile asks us to call "napi_disable()".
  729. *
  730. * The "rotting packet" race condition occurs if a packet arrives
  731. * during the extremely narrow window between the queue appearing to
  732. * be empty, and the ingress interrupt being re-enabled. This happens
  733. * a LOT under heavy network load.
  734. */
  735. static int tile_net_poll(struct napi_struct *napi, int budget)
  736. {
  737. struct net_device *dev = napi->dev;
  738. struct tile_net_priv *priv = netdev_priv(dev);
  739. int my_cpu = smp_processor_id();
  740. struct tile_net_cpu *info = priv->cpu[my_cpu];
  741. struct tile_netio_queue *queue = &info->queue;
  742. netio_queue_impl_t *qsp = queue->__system_part;
  743. netio_queue_user_impl_t *qup = &queue->__user_part;
  744. unsigned int work = 0;
  745. while (priv->active) {
  746. int index = qup->__packet_receive_read;
  747. if (index == qsp->__packet_receive_queue.__packet_write)
  748. break;
  749. if (tile_net_poll_aux(info, index)) {
  750. if (++work >= budget)
  751. goto done;
  752. }
  753. }
  754. napi_complete(&info->napi);
  755. if (!priv->active)
  756. goto done;
  757. /* Re-enable the ingress interrupt. */
  758. enable_percpu_irq(priv->intr_id, 0);
  759. /* HACK: Avoid the "rotting packet" problem (see above). */
  760. if (qup->__packet_receive_read !=
  761. qsp->__packet_receive_queue.__packet_write) {
  762. /* ISSUE: Sometimes this returns zero, presumably */
  763. /* because an interrupt was handled for this tile. */
  764. (void)napi_reschedule(&info->napi);
  765. }
  766. done:
  767. if (priv->active)
  768. tile_net_provide_needed_buffers(info);
  769. return work;
  770. }
  771. /*
  772. * Handle an ingress interrupt for the given device on the current cpu.
  773. *
  774. * ISSUE: Sometimes this gets called after "disable_percpu_irq()" has
  775. * been called! This is probably due to "pending hypervisor downcalls".
  776. *
  777. * ISSUE: Is there any race condition between the "napi_schedule()" here
  778. * and the "napi_complete()" call above?
  779. */
  780. static irqreturn_t tile_net_handle_ingress_interrupt(int irq, void *dev_ptr)
  781. {
  782. struct net_device *dev = (struct net_device *)dev_ptr;
  783. struct tile_net_priv *priv = netdev_priv(dev);
  784. int my_cpu = smp_processor_id();
  785. struct tile_net_cpu *info = priv->cpu[my_cpu];
  786. /* Disable the ingress interrupt. */
  787. disable_percpu_irq(priv->intr_id);
  788. /* Ignore unwanted interrupts. */
  789. if (!priv->active)
  790. return IRQ_HANDLED;
  791. /* ISSUE: Sometimes "info->napi_enabled" is false here. */
  792. napi_schedule(&info->napi);
  793. return IRQ_HANDLED;
  794. }
  795. /*
  796. * One time initialization per interface.
  797. */
  798. static int tile_net_open_aux(struct net_device *dev)
  799. {
  800. struct tile_net_priv *priv = netdev_priv(dev);
  801. int ret;
  802. int dummy;
  803. unsigned int epp_lotar;
  804. /*
  805. * Find out where EPP memory should be homed.
  806. */
  807. ret = hv_dev_pread(priv->hv_devhdl, 0,
  808. (HV_VirtAddr)&epp_lotar, sizeof(epp_lotar),
  809. NETIO_EPP_SHM_OFF);
  810. if (ret < 0) {
  811. pr_err("could not read epp_shm_queue lotar.\n");
  812. return -EIO;
  813. }
  814. /*
  815. * Home the page on the EPP.
  816. */
  817. {
  818. int epp_home = hv_lotar_to_cpu(epp_lotar);
  819. homecache_change_page_home(priv->eq_pages, EQ_ORDER, epp_home);
  820. }
  821. /*
  822. * Register the EPP shared memory queue.
  823. */
  824. {
  825. netio_ipp_address_t ea = {
  826. .va = 0,
  827. .pa = __pa(priv->eq),
  828. .pte = hv_pte(0),
  829. .size = EQ_SIZE,
  830. };
  831. ea.pte = hv_pte_set_lotar(ea.pte, epp_lotar);
  832. ea.pte = hv_pte_set_mode(ea.pte, HV_PTE_MODE_CACHE_TILE_L3);
  833. ret = hv_dev_pwrite(priv->hv_devhdl, 0,
  834. (HV_VirtAddr)&ea,
  835. sizeof(ea),
  836. NETIO_EPP_SHM_OFF);
  837. if (ret < 0)
  838. return -EIO;
  839. }
  840. /*
  841. * Start LIPP/LEPP.
  842. */
  843. if (hv_dev_pwrite(priv->hv_devhdl, 0, (HV_VirtAddr)&dummy,
  844. sizeof(dummy), NETIO_IPP_START_SHIM_OFF) < 0) {
  845. pr_warning("Failed to start LIPP/LEPP.\n");
  846. return -EIO;
  847. }
  848. return 0;
  849. }
  850. /*
  851. * Register with hypervisor on the current CPU.
  852. *
  853. * Strangely, this function does important things even if it "fails",
  854. * which is especially common if the link is not up yet. Hopefully
  855. * these things are all "harmless" if done twice!
  856. */
  857. static void tile_net_register(void *dev_ptr)
  858. {
  859. struct net_device *dev = (struct net_device *)dev_ptr;
  860. struct tile_net_priv *priv = netdev_priv(dev);
  861. int my_cpu = smp_processor_id();
  862. struct tile_net_cpu *info;
  863. struct tile_netio_queue *queue;
  864. /* Only network cpus can receive packets. */
  865. int queue_id =
  866. cpumask_test_cpu(my_cpu, &priv->network_cpus_map) ? 0 : 255;
  867. netio_input_config_t config = {
  868. .flags = 0,
  869. .num_receive_packets = priv->network_cpus_credits,
  870. .queue_id = queue_id
  871. };
  872. int ret = 0;
  873. netio_queue_impl_t *queuep;
  874. PDEBUG("tile_net_register(queue_id %d)\n", queue_id);
  875. if (!strcmp(dev->name, "xgbe0"))
  876. info = &__get_cpu_var(hv_xgbe0);
  877. else if (!strcmp(dev->name, "xgbe1"))
  878. info = &__get_cpu_var(hv_xgbe1);
  879. else if (!strcmp(dev->name, "gbe0"))
  880. info = &__get_cpu_var(hv_gbe0);
  881. else if (!strcmp(dev->name, "gbe1"))
  882. info = &__get_cpu_var(hv_gbe1);
  883. else
  884. BUG();
  885. /* Initialize the egress timer. */
  886. init_timer(&info->egress_timer);
  887. info->egress_timer.data = (long)info;
  888. info->egress_timer.function = tile_net_handle_egress_timer;
  889. u64_stats_init(&info->stats.syncp);
  890. priv->cpu[my_cpu] = info;
  891. /*
  892. * Register ourselves with LIPP. This does a lot of stuff,
  893. * including invoking the LIPP registration code.
  894. */
  895. ret = hv_dev_pwrite(priv->hv_devhdl, 0,
  896. (HV_VirtAddr)&config,
  897. sizeof(netio_input_config_t),
  898. NETIO_IPP_INPUT_REGISTER_OFF);
  899. PDEBUG("hv_dev_pwrite(NETIO_IPP_INPUT_REGISTER_OFF) returned %d\n",
  900. ret);
  901. if (ret < 0) {
  902. if (ret != NETIO_LINK_DOWN) {
  903. printk(KERN_DEBUG "hv_dev_pwrite "
  904. "NETIO_IPP_INPUT_REGISTER_OFF failure %d\n",
  905. ret);
  906. }
  907. info->link_down = (ret == NETIO_LINK_DOWN);
  908. return;
  909. }
  910. /*
  911. * Get the pointer to our queue's system part.
  912. */
  913. ret = hv_dev_pread(priv->hv_devhdl, 0,
  914. (HV_VirtAddr)&queuep,
  915. sizeof(netio_queue_impl_t *),
  916. NETIO_IPP_INPUT_REGISTER_OFF);
  917. PDEBUG("hv_dev_pread(NETIO_IPP_INPUT_REGISTER_OFF) returned %d\n",
  918. ret);
  919. PDEBUG("queuep %p\n", queuep);
  920. if (ret <= 0) {
  921. /* ISSUE: Shouldn't this be a fatal error? */
  922. pr_err("hv_dev_pread NETIO_IPP_INPUT_REGISTER_OFF failure\n");
  923. return;
  924. }
  925. queue = &info->queue;
  926. queue->__system_part = queuep;
  927. memset(&queue->__user_part, 0, sizeof(netio_queue_user_impl_t));
  928. /* This is traditionally "config.num_receive_packets / 2". */
  929. queue->__user_part.__receive_credit_interval = 4;
  930. queue->__user_part.__receive_credit_remaining =
  931. queue->__user_part.__receive_credit_interval;
  932. /*
  933. * Get a fastio index from the hypervisor.
  934. * ISSUE: Shouldn't this check the result?
  935. */
  936. ret = hv_dev_pread(priv->hv_devhdl, 0,
  937. (HV_VirtAddr)&queue->__user_part.__fastio_index,
  938. sizeof(queue->__user_part.__fastio_index),
  939. NETIO_IPP_GET_FASTIO_OFF);
  940. PDEBUG("hv_dev_pread(NETIO_IPP_GET_FASTIO_OFF) returned %d\n", ret);
  941. /* Now we are registered. */
  942. info->registered = true;
  943. }
  944. /*
  945. * Deregister with hypervisor on the current CPU.
  946. *
  947. * This simply discards all our credits, so no more packets will be
  948. * delivered to this tile. There may still be packets in our queue.
  949. *
  950. * Also, disable the ingress interrupt.
  951. */
  952. static void tile_net_deregister(void *dev_ptr)
  953. {
  954. struct net_device *dev = (struct net_device *)dev_ptr;
  955. struct tile_net_priv *priv = netdev_priv(dev);
  956. int my_cpu = smp_processor_id();
  957. struct tile_net_cpu *info = priv->cpu[my_cpu];
  958. /* Disable the ingress interrupt. */
  959. disable_percpu_irq(priv->intr_id);
  960. /* Do nothing else if not registered. */
  961. if (info == NULL || !info->registered)
  962. return;
  963. {
  964. struct tile_netio_queue *queue = &info->queue;
  965. netio_queue_user_impl_t *qup = &queue->__user_part;
  966. /* Discard all our credits. */
  967. __netio_fastio_return_credits(qup->__fastio_index, -1);
  968. }
  969. }
  970. /*
  971. * Unregister with hypervisor on the current CPU.
  972. *
  973. * Also, disable the ingress interrupt.
  974. */
  975. static void tile_net_unregister(void *dev_ptr)
  976. {
  977. struct net_device *dev = (struct net_device *)dev_ptr;
  978. struct tile_net_priv *priv = netdev_priv(dev);
  979. int my_cpu = smp_processor_id();
  980. struct tile_net_cpu *info = priv->cpu[my_cpu];
  981. int ret;
  982. int dummy = 0;
  983. /* Disable the ingress interrupt. */
  984. disable_percpu_irq(priv->intr_id);
  985. /* Do nothing else if not registered. */
  986. if (info == NULL || !info->registered)
  987. return;
  988. /* Unregister ourselves with LIPP/LEPP. */
  989. ret = hv_dev_pwrite(priv->hv_devhdl, 0, (HV_VirtAddr)&dummy,
  990. sizeof(dummy), NETIO_IPP_INPUT_UNREGISTER_OFF);
  991. if (ret < 0)
  992. panic("Failed to unregister with LIPP/LEPP!\n");
  993. /* Discard all packets still in our NetIO queue. */
  994. tile_net_discard_packets(dev);
  995. /* Reset state. */
  996. info->num_needed_small_buffers = 0;
  997. info->num_needed_large_buffers = 0;
  998. /* Cancel egress timer. */
  999. del_timer(&info->egress_timer);
  1000. info->egress_timer_scheduled = false;
  1001. }
  1002. /*
  1003. * Helper function for "tile_net_stop()".
  1004. *
  1005. * Also used to handle registration failure in "tile_net_open_inner()",
  1006. * when the various extra steps in "tile_net_stop()" are not necessary.
  1007. */
  1008. static void tile_net_stop_aux(struct net_device *dev)
  1009. {
  1010. struct tile_net_priv *priv = netdev_priv(dev);
  1011. int i;
  1012. int dummy = 0;
  1013. /*
  1014. * Unregister all tiles, so LIPP will stop delivering packets.
  1015. * Also, delete all the "napi" objects (sequentially, to protect
  1016. * "dev->napi_list").
  1017. */
  1018. on_each_cpu(tile_net_unregister, (void *)dev, 1);
  1019. for_each_online_cpu(i) {
  1020. struct tile_net_cpu *info = priv->cpu[i];
  1021. if (info != NULL && info->registered) {
  1022. netif_napi_del(&info->napi);
  1023. info->registered = false;
  1024. }
  1025. }
  1026. /* Stop LIPP/LEPP. */
  1027. if (hv_dev_pwrite(priv->hv_devhdl, 0, (HV_VirtAddr)&dummy,
  1028. sizeof(dummy), NETIO_IPP_STOP_SHIM_OFF) < 0)
  1029. panic("Failed to stop LIPP/LEPP!\n");
  1030. priv->partly_opened = false;
  1031. }
  1032. /*
  1033. * Disable NAPI for the given device on the current cpu.
  1034. */
  1035. static void tile_net_stop_disable(void *dev_ptr)
  1036. {
  1037. struct net_device *dev = (struct net_device *)dev_ptr;
  1038. struct tile_net_priv *priv = netdev_priv(dev);
  1039. int my_cpu = smp_processor_id();
  1040. struct tile_net_cpu *info = priv->cpu[my_cpu];
  1041. /* Disable NAPI if needed. */
  1042. if (info != NULL && info->napi_enabled) {
  1043. napi_disable(&info->napi);
  1044. info->napi_enabled = false;
  1045. }
  1046. }
  1047. /*
  1048. * Enable NAPI and the ingress interrupt for the given device
  1049. * on the current cpu.
  1050. *
  1051. * ISSUE: Only do this for "network cpus"?
  1052. */
  1053. static void tile_net_open_enable(void *dev_ptr)
  1054. {
  1055. struct net_device *dev = (struct net_device *)dev_ptr;
  1056. struct tile_net_priv *priv = netdev_priv(dev);
  1057. int my_cpu = smp_processor_id();
  1058. struct tile_net_cpu *info = priv->cpu[my_cpu];
  1059. /* Enable NAPI. */
  1060. napi_enable(&info->napi);
  1061. info->napi_enabled = true;
  1062. /* Enable the ingress interrupt. */
  1063. enable_percpu_irq(priv->intr_id, 0);
  1064. }
  1065. /*
  1066. * tile_net_open_inner does most of the work of bringing up the interface.
  1067. * It's called from tile_net_open(), and also from tile_net_retry_open().
  1068. * The return value is 0 if the interface was brought up, < 0 if
  1069. * tile_net_open() should return the return value as an error, and > 0 if
  1070. * tile_net_open() should return success and schedule a work item to
  1071. * periodically retry the bringup.
  1072. */
  1073. static int tile_net_open_inner(struct net_device *dev)
  1074. {
  1075. struct tile_net_priv *priv = netdev_priv(dev);
  1076. int my_cpu = smp_processor_id();
  1077. struct tile_net_cpu *info;
  1078. struct tile_netio_queue *queue;
  1079. int result = 0;
  1080. int i;
  1081. int dummy = 0;
  1082. /*
  1083. * First try to register just on the local CPU, and handle any
  1084. * semi-expected "link down" failure specially. Note that we
  1085. * do NOT call "tile_net_stop_aux()", unlike below.
  1086. */
  1087. tile_net_register(dev);
  1088. info = priv->cpu[my_cpu];
  1089. if (!info->registered) {
  1090. if (info->link_down)
  1091. return 1;
  1092. return -EAGAIN;
  1093. }
  1094. /*
  1095. * Now register everywhere else. If any registration fails,
  1096. * even for "link down" (which might not be possible), we
  1097. * clean up using "tile_net_stop_aux()". Also, add all the
  1098. * "napi" objects (sequentially, to protect "dev->napi_list").
  1099. * ISSUE: Only use "netif_napi_add()" for "network cpus"?
  1100. */
  1101. smp_call_function(tile_net_register, (void *)dev, 1);
  1102. for_each_online_cpu(i) {
  1103. struct tile_net_cpu *info = priv->cpu[i];
  1104. if (info->registered)
  1105. netif_napi_add(dev, &info->napi, tile_net_poll, 64);
  1106. else
  1107. result = -EAGAIN;
  1108. }
  1109. if (result != 0) {
  1110. tile_net_stop_aux(dev);
  1111. return result;
  1112. }
  1113. queue = &info->queue;
  1114. if (priv->intr_id == 0) {
  1115. unsigned int irq;
  1116. /*
  1117. * Acquire the irq allocated by the hypervisor. Every
  1118. * queue gets the same irq. The "__intr_id" field is
  1119. * "1 << irq", so we use "__ffs()" to extract "irq".
  1120. */
  1121. priv->intr_id = queue->__system_part->__intr_id;
  1122. BUG_ON(priv->intr_id == 0);
  1123. irq = __ffs(priv->intr_id);
  1124. /*
  1125. * Register the ingress interrupt handler for this
  1126. * device, permanently.
  1127. *
  1128. * We used to call "free_irq()" in "tile_net_stop()",
  1129. * and then re-register the handler here every time,
  1130. * but that caused DNP errors in "handle_IRQ_event()"
  1131. * because "desc->action" was NULL. See bug 9143.
  1132. */
  1133. tile_irq_activate(irq, TILE_IRQ_PERCPU);
  1134. BUG_ON(request_irq(irq, tile_net_handle_ingress_interrupt,
  1135. 0, dev->name, (void *)dev) != 0);
  1136. }
  1137. {
  1138. /* Allocate initial buffers. */
  1139. int max_buffers =
  1140. priv->network_cpus_count * priv->network_cpus_credits;
  1141. info->num_needed_small_buffers =
  1142. min(LIPP_SMALL_BUFFERS, max_buffers);
  1143. info->num_needed_large_buffers =
  1144. min(LIPP_LARGE_BUFFERS, max_buffers);
  1145. tile_net_provide_needed_buffers(info);
  1146. if (info->num_needed_small_buffers != 0 ||
  1147. info->num_needed_large_buffers != 0)
  1148. panic("Insufficient memory for buffer stack!");
  1149. }
  1150. /* We are about to be active. */
  1151. priv->active = true;
  1152. /* Make sure "active" is visible to all tiles. */
  1153. mb();
  1154. /* On each tile, enable NAPI and the ingress interrupt. */
  1155. on_each_cpu(tile_net_open_enable, (void *)dev, 1);
  1156. /* Start LIPP/LEPP and activate "ingress" at the shim. */
  1157. if (hv_dev_pwrite(priv->hv_devhdl, 0, (HV_VirtAddr)&dummy,
  1158. sizeof(dummy), NETIO_IPP_INPUT_INIT_OFF) < 0)
  1159. panic("Failed to activate the LIPP Shim!\n");
  1160. /* Start our transmit queue. */
  1161. netif_start_queue(dev);
  1162. return 0;
  1163. }
  1164. /*
  1165. * Called periodically to retry bringing up the NetIO interface,
  1166. * if it doesn't come up cleanly during tile_net_open().
  1167. */
  1168. static void tile_net_open_retry(struct work_struct *w)
  1169. {
  1170. struct delayed_work *dw =
  1171. container_of(w, struct delayed_work, work);
  1172. struct tile_net_priv *priv =
  1173. container_of(dw, struct tile_net_priv, retry_work);
  1174. /*
  1175. * Try to bring the NetIO interface up. If it fails, reschedule
  1176. * ourselves to try again later; otherwise, tell Linux we now have
  1177. * a working link. ISSUE: What if the return value is negative?
  1178. */
  1179. if (tile_net_open_inner(priv->dev) != 0)
  1180. schedule_delayed_work(&priv->retry_work,
  1181. TILE_NET_RETRY_INTERVAL);
  1182. else
  1183. netif_carrier_on(priv->dev);
  1184. }
  1185. /*
  1186. * Called when a network interface is made active.
  1187. *
  1188. * Returns 0 on success, negative value on failure.
  1189. *
  1190. * The open entry point is called when a network interface is made
  1191. * active by the system (IFF_UP). At this point all resources needed
  1192. * for transmit and receive operations are allocated, the interrupt
  1193. * handler is registered with the OS (if needed), the watchdog timer
  1194. * is started, and the stack is notified that the interface is ready.
  1195. *
  1196. * If the actual link is not available yet, then we tell Linux that
  1197. * we have no carrier, and we keep checking until the link comes up.
  1198. */
  1199. static int tile_net_open(struct net_device *dev)
  1200. {
  1201. int ret = 0;
  1202. struct tile_net_priv *priv = netdev_priv(dev);
  1203. /*
  1204. * We rely on priv->partly_opened to tell us if this is the
  1205. * first time this interface is being brought up. If it is
  1206. * set, the IPP was already initialized and should not be
  1207. * initialized again.
  1208. */
  1209. if (!priv->partly_opened) {
  1210. int count;
  1211. int credits;
  1212. /* Initialize LIPP/LEPP, and start the Shim. */
  1213. ret = tile_net_open_aux(dev);
  1214. if (ret < 0) {
  1215. pr_err("tile_net_open_aux failed: %d\n", ret);
  1216. return ret;
  1217. }
  1218. /* Analyze the network cpus. */
  1219. if (network_cpus_used)
  1220. cpumask_copy(&priv->network_cpus_map,
  1221. &network_cpus_map);
  1222. else
  1223. cpumask_copy(&priv->network_cpus_map, cpu_online_mask);
  1224. count = cpumask_weight(&priv->network_cpus_map);
  1225. /* Limit credits to available buffers, and apply min. */
  1226. credits = max(16, (LIPP_LARGE_BUFFERS / count) & ~1);
  1227. /* Apply "GBE" max limit. */
  1228. /* ISSUE: Use higher limit for XGBE? */
  1229. credits = min(NETIO_MAX_RECEIVE_PKTS, credits);
  1230. priv->network_cpus_count = count;
  1231. priv->network_cpus_credits = credits;
  1232. #ifdef TILE_NET_DEBUG
  1233. pr_info("Using %d network cpus, with %d credits each\n",
  1234. priv->network_cpus_count, priv->network_cpus_credits);
  1235. #endif
  1236. priv->partly_opened = true;
  1237. } else {
  1238. /* FIXME: Is this possible? */
  1239. /* printk("Already partly opened.\n"); */
  1240. }
  1241. /*
  1242. * Attempt to bring up the link.
  1243. */
  1244. ret = tile_net_open_inner(dev);
  1245. if (ret <= 0) {
  1246. if (ret == 0)
  1247. netif_carrier_on(dev);
  1248. return ret;
  1249. }
  1250. /*
  1251. * We were unable to bring up the NetIO interface, but we want to
  1252. * try again in a little bit. Tell Linux that we have no carrier
  1253. * so it doesn't try to use the interface before the link comes up
  1254. * and then remember to try again later.
  1255. */
  1256. netif_carrier_off(dev);
  1257. schedule_delayed_work(&priv->retry_work, TILE_NET_RETRY_INTERVAL);
  1258. return 0;
  1259. }
  1260. static int tile_net_drain_lipp_buffers(struct tile_net_priv *priv)
  1261. {
  1262. int n = 0;
  1263. /* Drain all the LIPP buffers. */
  1264. while (true) {
  1265. unsigned int buffer;
  1266. /* NOTE: This should never fail. */
  1267. if (hv_dev_pread(priv->hv_devhdl, 0, (HV_VirtAddr)&buffer,
  1268. sizeof(buffer), NETIO_IPP_DRAIN_OFF) < 0)
  1269. break;
  1270. /* Stop when done. */
  1271. if (buffer == 0)
  1272. break;
  1273. {
  1274. /* Convert "linux_buffer_t" to "va". */
  1275. void *va = __va((phys_addr_t)(buffer >> 1) << 7);
  1276. /* Acquire the associated "skb". */
  1277. struct sk_buff **skb_ptr = va - sizeof(*skb_ptr);
  1278. struct sk_buff *skb = *skb_ptr;
  1279. kfree_skb(skb);
  1280. }
  1281. n++;
  1282. }
  1283. return n;
  1284. }
  1285. /*
  1286. * Disables a network interface.
  1287. *
  1288. * Returns 0, this is not allowed to fail.
  1289. *
  1290. * The close entry point is called when an interface is de-activated
  1291. * by the OS. The hardware is still under the drivers control, but
  1292. * needs to be disabled. A global MAC reset is issued to stop the
  1293. * hardware, and all transmit and receive resources are freed.
  1294. *
  1295. * ISSUE: How closely does "netif_running(dev)" mirror "priv->active"?
  1296. *
  1297. * Before we are called by "__dev_close()", "netif_running()" will
  1298. * have been cleared, so no NEW calls to "tile_net_poll()" will be
  1299. * made by "netpoll_poll_dev()".
  1300. *
  1301. * Often, this can cause some tiles to still have packets in their
  1302. * queues, so we must call "tile_net_discard_packets()" later.
  1303. *
  1304. * Note that some other tile may still be INSIDE "tile_net_poll()",
  1305. * and in fact, many will be, if there is heavy network load.
  1306. *
  1307. * Calling "on_each_cpu(tile_net_stop_disable, (void *)dev, 1)" when
  1308. * any tile is still "napi_schedule()"'d will induce a horrible crash
  1309. * when "msleep()" is called. This includes tiles which are inside
  1310. * "tile_net_poll()" which have not yet called "napi_complete()".
  1311. *
  1312. * So, we must first try to wait long enough for other tiles to finish
  1313. * with any current "tile_net_poll()" call, and, hopefully, to clear
  1314. * the "scheduled" flag. ISSUE: It is unclear what happens to tiles
  1315. * which have called "napi_schedule()" but which had not yet tried to
  1316. * call "tile_net_poll()", or which exhausted their budget inside
  1317. * "tile_net_poll()" just before this function was called.
  1318. */
  1319. static int tile_net_stop(struct net_device *dev)
  1320. {
  1321. struct tile_net_priv *priv = netdev_priv(dev);
  1322. PDEBUG("tile_net_stop()\n");
  1323. /* Start discarding packets. */
  1324. priv->active = false;
  1325. /* Make sure "active" is visible to all tiles. */
  1326. mb();
  1327. /*
  1328. * On each tile, make sure no NEW packets get delivered, and
  1329. * disable the ingress interrupt.
  1330. *
  1331. * Note that the ingress interrupt can fire AFTER this,
  1332. * presumably due to packets which were recently delivered,
  1333. * but it will have no effect.
  1334. */
  1335. on_each_cpu(tile_net_deregister, (void *)dev, 1);
  1336. /* Optimistically drain LIPP buffers. */
  1337. (void)tile_net_drain_lipp_buffers(priv);
  1338. /* ISSUE: Only needed if not yet fully open. */
  1339. cancel_delayed_work_sync(&priv->retry_work);
  1340. /* Can't transmit any more. */
  1341. netif_stop_queue(dev);
  1342. /* Disable NAPI on each tile. */
  1343. on_each_cpu(tile_net_stop_disable, (void *)dev, 1);
  1344. /*
  1345. * Drain any remaining LIPP buffers. NOTE: This "printk()"
  1346. * has never been observed, but in theory it could happen.
  1347. */
  1348. if (tile_net_drain_lipp_buffers(priv) != 0)
  1349. printk("Had to drain some extra LIPP buffers!\n");
  1350. /* Stop LIPP/LEPP. */
  1351. tile_net_stop_aux(dev);
  1352. /*
  1353. * ISSUE: It appears that, in practice anyway, by the time we
  1354. * get here, there are no pending completions, but just in case,
  1355. * we free (all of) them anyway.
  1356. */
  1357. while (tile_net_lepp_free_comps(dev, true))
  1358. /* loop */;
  1359. /* Wipe the EPP queue, and wait till the stores hit the EPP. */
  1360. memset(priv->eq, 0, sizeof(lepp_queue_t));
  1361. mb();
  1362. return 0;
  1363. }
  1364. /*
  1365. * Prepare the "frags" info for the resulting LEPP command.
  1366. *
  1367. * If needed, flush the memory used by the frags.
  1368. */
  1369. static unsigned int tile_net_tx_frags(lepp_frag_t *frags,
  1370. struct sk_buff *skb,
  1371. void *b_data, unsigned int b_len)
  1372. {
  1373. unsigned int i, n = 0;
  1374. struct skb_shared_info *sh = skb_shinfo(skb);
  1375. phys_addr_t cpa;
  1376. if (b_len != 0) {
  1377. if (!hash_default)
  1378. finv_buffer_remote(b_data, b_len, 0);
  1379. cpa = __pa(b_data);
  1380. frags[n].cpa_lo = cpa;
  1381. frags[n].cpa_hi = cpa >> 32;
  1382. frags[n].length = b_len;
  1383. frags[n].hash_for_home = hash_default;
  1384. n++;
  1385. }
  1386. for (i = 0; i < sh->nr_frags; i++) {
  1387. skb_frag_t *f = &sh->frags[i];
  1388. unsigned long pfn = page_to_pfn(skb_frag_page(f));
  1389. /* FIXME: Compute "hash_for_home" properly. */
  1390. /* ISSUE: The hypervisor checks CHIP_HAS_REV1_DMA_PACKETS(). */
  1391. int hash_for_home = hash_default;
  1392. /* FIXME: Hmmm. */
  1393. if (!hash_default) {
  1394. void *va = pfn_to_kaddr(pfn) + f->page_offset;
  1395. BUG_ON(PageHighMem(skb_frag_page(f)));
  1396. finv_buffer_remote(va, skb_frag_size(f), 0);
  1397. }
  1398. cpa = ((phys_addr_t)pfn << PAGE_SHIFT) + f->page_offset;
  1399. frags[n].cpa_lo = cpa;
  1400. frags[n].cpa_hi = cpa >> 32;
  1401. frags[n].length = skb_frag_size(f);
  1402. frags[n].hash_for_home = hash_for_home;
  1403. n++;
  1404. }
  1405. return n;
  1406. }
  1407. /*
  1408. * This function takes "skb", consisting of a header template and a
  1409. * payload, and hands it to LEPP, to emit as one or more segments,
  1410. * each consisting of a possibly modified header, plus a piece of the
  1411. * payload, via a process known as "tcp segmentation offload".
  1412. *
  1413. * Usually, "data" will contain the header template, of size "sh_len",
  1414. * and "sh->frags" will contain "skb->data_len" bytes of payload, and
  1415. * there will be "sh->gso_segs" segments.
  1416. *
  1417. * Sometimes, if "sendfile()" requires copying, we will be called with
  1418. * "data" containing the header and payload, with "frags" being empty.
  1419. *
  1420. * Sometimes, for example when using NFS over TCP, a single segment can
  1421. * span 3 fragments, which must be handled carefully in LEPP.
  1422. *
  1423. * See "emulate_large_send_offload()" for some reference code, which
  1424. * does not handle checksumming.
  1425. *
  1426. * ISSUE: How do we make sure that high memory DMA does not migrate?
  1427. */
  1428. static int tile_net_tx_tso(struct sk_buff *skb, struct net_device *dev)
  1429. {
  1430. struct tile_net_priv *priv = netdev_priv(dev);
  1431. int my_cpu = smp_processor_id();
  1432. struct tile_net_cpu *info = priv->cpu[my_cpu];
  1433. struct tile_net_stats_t *stats = &info->stats;
  1434. struct skb_shared_info *sh = skb_shinfo(skb);
  1435. unsigned char *data = skb->data;
  1436. /* The ip header follows the ethernet header. */
  1437. struct iphdr *ih = ip_hdr(skb);
  1438. unsigned int ih_len = ih->ihl * 4;
  1439. /* Note that "nh == ih", by definition. */
  1440. unsigned char *nh = skb_network_header(skb);
  1441. unsigned int eh_len = nh - data;
  1442. /* The tcp header follows the ip header. */
  1443. struct tcphdr *th = (struct tcphdr *)(nh + ih_len);
  1444. unsigned int th_len = th->doff * 4;
  1445. /* The total number of header bytes. */
  1446. /* NOTE: This may be less than skb_headlen(skb). */
  1447. unsigned int sh_len = eh_len + ih_len + th_len;
  1448. /* The number of payload bytes at "skb->data + sh_len". */
  1449. /* This is non-zero for sendfile() without HIGHDMA. */
  1450. unsigned int b_len = skb_headlen(skb) - sh_len;
  1451. /* The total number of payload bytes. */
  1452. unsigned int d_len = b_len + skb->data_len;
  1453. /* The maximum payload size. */
  1454. unsigned int p_len = sh->gso_size;
  1455. /* The total number of segments. */
  1456. unsigned int num_segs = sh->gso_segs;
  1457. /* The temporary copy of the command. */
  1458. u32 cmd_body[(LEPP_MAX_CMD_SIZE + 3) / 4];
  1459. lepp_tso_cmd_t *cmd = (lepp_tso_cmd_t *)cmd_body;
  1460. /* Analyze the "frags". */
  1461. unsigned int num_frags =
  1462. tile_net_tx_frags(cmd->frags, skb, data + sh_len, b_len);
  1463. /* The size of the command, including frags and header. */
  1464. size_t cmd_size = LEPP_TSO_CMD_SIZE(num_frags, sh_len);
  1465. /* The command header. */
  1466. lepp_tso_cmd_t cmd_init = {
  1467. .tso = true,
  1468. .header_size = sh_len,
  1469. .ip_offset = eh_len,
  1470. .tcp_offset = eh_len + ih_len,
  1471. .payload_size = p_len,
  1472. .num_frags = num_frags,
  1473. };
  1474. unsigned long irqflags;
  1475. lepp_queue_t *eq = priv->eq;
  1476. struct sk_buff *olds[8];
  1477. unsigned int wanted = 8;
  1478. unsigned int i, nolds = 0;
  1479. unsigned int cmd_head, cmd_tail, cmd_next;
  1480. unsigned int comp_tail;
  1481. /* Paranoia. */
  1482. BUG_ON(skb->protocol != htons(ETH_P_IP));
  1483. BUG_ON(ih->protocol != IPPROTO_TCP);
  1484. BUG_ON(skb->ip_summed != CHECKSUM_PARTIAL);
  1485. BUG_ON(num_frags > LEPP_MAX_FRAGS);
  1486. /*--BUG_ON(num_segs != (d_len + (p_len - 1)) / p_len); */
  1487. BUG_ON(num_segs <= 1);
  1488. /* Finish preparing the command. */
  1489. /* Copy the command header. */
  1490. *cmd = cmd_init;
  1491. /* Copy the "header". */
  1492. memcpy(&cmd->frags[num_frags], data, sh_len);
  1493. /* Prefetch and wait, to minimize time spent holding the spinlock. */
  1494. prefetch_L1(&eq->comp_tail);
  1495. prefetch_L1(&eq->cmd_tail);
  1496. mb();
  1497. /* Enqueue the command. */
  1498. spin_lock_irqsave(&priv->eq_lock, irqflags);
  1499. /* Handle completions if needed to make room. */
  1500. /* NOTE: Return NETDEV_TX_BUSY if there is still no room. */
  1501. if (lepp_num_free_comp_slots(eq) == 0) {
  1502. nolds = tile_net_lepp_grab_comps(eq, olds, wanted, 0);
  1503. if (nolds == 0) {
  1504. busy:
  1505. spin_unlock_irqrestore(&priv->eq_lock, irqflags);
  1506. return NETDEV_TX_BUSY;
  1507. }
  1508. }
  1509. cmd_head = eq->cmd_head;
  1510. cmd_tail = eq->cmd_tail;
  1511. /* Prepare to advance, detecting full queue. */
  1512. /* NOTE: Return NETDEV_TX_BUSY if the queue is full. */
  1513. cmd_next = cmd_tail + cmd_size;
  1514. if (cmd_tail < cmd_head && cmd_next >= cmd_head)
  1515. goto busy;
  1516. if (cmd_next > LEPP_CMD_LIMIT) {
  1517. cmd_next = 0;
  1518. if (cmd_next == cmd_head)
  1519. goto busy;
  1520. }
  1521. /* Copy the command. */
  1522. memcpy(&eq->cmds[cmd_tail], cmd, cmd_size);
  1523. /* Advance. */
  1524. cmd_tail = cmd_next;
  1525. /* Record "skb" for eventual freeing. */
  1526. comp_tail = eq->comp_tail;
  1527. eq->comps[comp_tail] = skb;
  1528. LEPP_QINC(comp_tail);
  1529. eq->comp_tail = comp_tail;
  1530. /* Flush before allowing LEPP to handle the command. */
  1531. /* ISSUE: Is this the optimal location for the flush? */
  1532. __insn_mf();
  1533. eq->cmd_tail = cmd_tail;
  1534. /* NOTE: Using "4" here is more efficient than "0" or "2", */
  1535. /* and, strangely, more efficient than pre-checking the number */
  1536. /* of available completions, and comparing it to 4. */
  1537. if (nolds == 0)
  1538. nolds = tile_net_lepp_grab_comps(eq, olds, wanted, 4);
  1539. spin_unlock_irqrestore(&priv->eq_lock, irqflags);
  1540. /* Handle completions. */
  1541. for (i = 0; i < nolds; i++)
  1542. kfree_skb(olds[i]);
  1543. /* Update stats. */
  1544. stats->tx_packets += num_segs;
  1545. stats->tx_bytes += (num_segs * sh_len) + d_len;
  1546. /* Make sure the egress timer is scheduled. */
  1547. tile_net_schedule_egress_timer(info);
  1548. return NETDEV_TX_OK;
  1549. }
  1550. /*
  1551. * Transmit a packet (called by the kernel via "hard_start_xmit" hook).
  1552. */
  1553. static int tile_net_tx(struct sk_buff *skb, struct net_device *dev)
  1554. {
  1555. struct tile_net_priv *priv = netdev_priv(dev);
  1556. int my_cpu = smp_processor_id();
  1557. struct tile_net_cpu *info = priv->cpu[my_cpu];
  1558. struct tile_net_stats_t *stats = &info->stats;
  1559. unsigned long irqflags;
  1560. struct skb_shared_info *sh = skb_shinfo(skb);
  1561. unsigned int len = skb->len;
  1562. unsigned char *data = skb->data;
  1563. unsigned int csum_start = skb_checksum_start_offset(skb);
  1564. lepp_frag_t frags[LEPP_MAX_FRAGS];
  1565. unsigned int num_frags;
  1566. lepp_queue_t *eq = priv->eq;
  1567. struct sk_buff *olds[8];
  1568. unsigned int wanted = 8;
  1569. unsigned int i, nolds = 0;
  1570. unsigned int cmd_size = sizeof(lepp_cmd_t);
  1571. unsigned int cmd_head, cmd_tail, cmd_next;
  1572. unsigned int comp_tail;
  1573. lepp_cmd_t cmds[LEPP_MAX_FRAGS];
  1574. /*
  1575. * This is paranoia, since we think that if the link doesn't come
  1576. * up, telling Linux we have no carrier will keep it from trying
  1577. * to transmit. If it does, though, we can't execute this routine,
  1578. * since data structures we depend on aren't set up yet.
  1579. */
  1580. if (!info->registered)
  1581. return NETDEV_TX_BUSY;
  1582. /* Save the timestamp. */
  1583. dev->trans_start = jiffies;
  1584. #ifdef TILE_NET_PARANOIA
  1585. #if CHIP_HAS_CBOX_HOME_MAP()
  1586. if (hash_default) {
  1587. HV_PTE pte = *virt_to_pte(current->mm, (unsigned long)data);
  1588. if (hv_pte_get_mode(pte) != HV_PTE_MODE_CACHE_HASH_L3)
  1589. panic("Non-HFH egress buffer! VA=%p Mode=%d PTE=%llx",
  1590. data, hv_pte_get_mode(pte), hv_pte_val(pte));
  1591. }
  1592. #endif
  1593. #endif
  1594. #ifdef TILE_NET_DUMP_PACKETS
  1595. /* ISSUE: Does not dump the "frags". */
  1596. dump_packet(data, skb_headlen(skb), "tx");
  1597. #endif /* TILE_NET_DUMP_PACKETS */
  1598. if (sh->gso_size != 0)
  1599. return tile_net_tx_tso(skb, dev);
  1600. /* Prepare the commands. */
  1601. num_frags = tile_net_tx_frags(frags, skb, data, skb_headlen(skb));
  1602. for (i = 0; i < num_frags; i++) {
  1603. bool final = (i == num_frags - 1);
  1604. lepp_cmd_t cmd = {
  1605. .cpa_lo = frags[i].cpa_lo,
  1606. .cpa_hi = frags[i].cpa_hi,
  1607. .length = frags[i].length,
  1608. .hash_for_home = frags[i].hash_for_home,
  1609. .send_completion = final,
  1610. .end_of_packet = final
  1611. };
  1612. if (i == 0 && skb->ip_summed == CHECKSUM_PARTIAL) {
  1613. cmd.compute_checksum = 1;
  1614. cmd.checksum_data.bits.start_byte = csum_start;
  1615. cmd.checksum_data.bits.count = len - csum_start;
  1616. cmd.checksum_data.bits.destination_byte =
  1617. csum_start + skb->csum_offset;
  1618. }
  1619. cmds[i] = cmd;
  1620. }
  1621. /* Prefetch and wait, to minimize time spent holding the spinlock. */
  1622. prefetch_L1(&eq->comp_tail);
  1623. prefetch_L1(&eq->cmd_tail);
  1624. mb();
  1625. /* Enqueue the commands. */
  1626. spin_lock_irqsave(&priv->eq_lock, irqflags);
  1627. /* Handle completions if needed to make room. */
  1628. /* NOTE: Return NETDEV_TX_BUSY if there is still no room. */
  1629. if (lepp_num_free_comp_slots(eq) == 0) {
  1630. nolds = tile_net_lepp_grab_comps(eq, olds, wanted, 0);
  1631. if (nolds == 0) {
  1632. busy:
  1633. spin_unlock_irqrestore(&priv->eq_lock, irqflags);
  1634. return NETDEV_TX_BUSY;
  1635. }
  1636. }
  1637. cmd_head = eq->cmd_head;
  1638. cmd_tail = eq->cmd_tail;
  1639. /* Copy the commands, or fail. */
  1640. /* NOTE: Return NETDEV_TX_BUSY if the queue is full. */
  1641. for (i = 0; i < num_frags; i++) {
  1642. /* Prepare to advance, detecting full queue. */
  1643. cmd_next = cmd_tail + cmd_size;
  1644. if (cmd_tail < cmd_head && cmd_next >= cmd_head)
  1645. goto busy;
  1646. if (cmd_next > LEPP_CMD_LIMIT) {
  1647. cmd_next = 0;
  1648. if (cmd_next == cmd_head)
  1649. goto busy;
  1650. }
  1651. /* Copy the command. */
  1652. *(lepp_cmd_t *)&eq->cmds[cmd_tail] = cmds[i];
  1653. /* Advance. */
  1654. cmd_tail = cmd_next;
  1655. }
  1656. /* Record "skb" for eventual freeing. */
  1657. comp_tail = eq->comp_tail;
  1658. eq->comps[comp_tail] = skb;
  1659. LEPP_QINC(comp_tail);
  1660. eq->comp_tail = comp_tail;
  1661. /* Flush before allowing LEPP to handle the command. */
  1662. /* ISSUE: Is this the optimal location for the flush? */
  1663. __insn_mf();
  1664. eq->cmd_tail = cmd_tail;
  1665. /* NOTE: Using "4" here is more efficient than "0" or "2", */
  1666. /* and, strangely, more efficient than pre-checking the number */
  1667. /* of available completions, and comparing it to 4. */
  1668. if (nolds == 0)
  1669. nolds = tile_net_lepp_grab_comps(eq, olds, wanted, 4);
  1670. spin_unlock_irqrestore(&priv->eq_lock, irqflags);
  1671. /* Handle completions. */
  1672. for (i = 0; i < nolds; i++)
  1673. kfree_skb(olds[i]);
  1674. /* HACK: Track "expanded" size for short packets (e.g. 42 < 60). */
  1675. stats->tx_packets++;
  1676. stats->tx_bytes += ((len >= ETH_ZLEN) ? len : ETH_ZLEN);
  1677. /* Make sure the egress timer is scheduled. */
  1678. tile_net_schedule_egress_timer(info);
  1679. return NETDEV_TX_OK;
  1680. }
  1681. /*
  1682. * Deal with a transmit timeout.
  1683. */
  1684. static void tile_net_tx_timeout(struct net_device *dev)
  1685. {
  1686. PDEBUG("tile_net_tx_timeout()\n");
  1687. PDEBUG("Transmit timeout at %ld, latency %ld\n", jiffies,
  1688. jiffies - dev->trans_start);
  1689. /* XXX: ISSUE: This doesn't seem useful for us. */
  1690. netif_wake_queue(dev);
  1691. }
  1692. /*
  1693. * Ioctl commands.
  1694. */
  1695. static int tile_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  1696. {
  1697. return -EOPNOTSUPP;
  1698. }
  1699. /*
  1700. * Get System Network Statistics.
  1701. *
  1702. * Returns the address of the device statistics structure.
  1703. */
  1704. static struct net_device_stats *tile_net_get_stats(struct net_device *dev)
  1705. {
  1706. struct tile_net_priv *priv = netdev_priv(dev);
  1707. u32 rx_packets = 0;
  1708. u32 tx_packets = 0;
  1709. u32 rx_bytes = 0;
  1710. u32 tx_bytes = 0;
  1711. int i;
  1712. for_each_online_cpu(i) {
  1713. if (priv->cpu[i]) {
  1714. rx_packets += priv->cpu[i]->stats.rx_packets;
  1715. rx_bytes += priv->cpu[i]->stats.rx_bytes;
  1716. tx_packets += priv->cpu[i]->stats.tx_packets;
  1717. tx_bytes += priv->cpu[i]->stats.tx_bytes;
  1718. }
  1719. }
  1720. priv->stats.rx_packets = rx_packets;
  1721. priv->stats.rx_bytes = rx_bytes;
  1722. priv->stats.tx_packets = tx_packets;
  1723. priv->stats.tx_bytes = tx_bytes;
  1724. return &priv->stats;
  1725. }
  1726. /*
  1727. * Change the "mtu".
  1728. *
  1729. * The "change_mtu" method is usually not needed.
  1730. * If you need it, it must be like this.
  1731. */
  1732. static int tile_net_change_mtu(struct net_device *dev, int new_mtu)
  1733. {
  1734. PDEBUG("tile_net_change_mtu()\n");
  1735. /* Check ranges. */
  1736. if ((new_mtu < 68) || (new_mtu > 1500))
  1737. return -EINVAL;
  1738. /* Accept the value. */
  1739. dev->mtu = new_mtu;
  1740. return 0;
  1741. }
  1742. /*
  1743. * Change the Ethernet Address of the NIC.
  1744. *
  1745. * The hypervisor driver does not support changing MAC address. However,
  1746. * the IPP does not do anything with the MAC address, so the address which
  1747. * gets used on outgoing packets, and which is accepted on incoming packets,
  1748. * is completely up to the NetIO program or kernel driver which is actually
  1749. * handling them.
  1750. *
  1751. * Returns 0 on success, negative on failure.
  1752. */
  1753. static int tile_net_set_mac_address(struct net_device *dev, void *p)
  1754. {
  1755. struct sockaddr *addr = p;
  1756. if (!is_valid_ether_addr(addr->sa_data))
  1757. return -EADDRNOTAVAIL;
  1758. /* ISSUE: Note that "dev_addr" is now a pointer. */
  1759. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  1760. dev->addr_assign_type &= ~NET_ADDR_RANDOM;
  1761. return 0;
  1762. }
  1763. /*
  1764. * Obtain the MAC address from the hypervisor.
  1765. * This must be done before opening the device.
  1766. */
  1767. static int tile_net_get_mac(struct net_device *dev)
  1768. {
  1769. struct tile_net_priv *priv = netdev_priv(dev);
  1770. char hv_dev_name[32];
  1771. int len;
  1772. __netio_getset_offset_t offset = { .word = NETIO_IPP_PARAM_OFF };
  1773. int ret;
  1774. /* For example, "xgbe0". */
  1775. strcpy(hv_dev_name, dev->name);
  1776. len = strlen(hv_dev_name);
  1777. /* For example, "xgbe/0". */
  1778. hv_dev_name[len] = hv_dev_name[len - 1];
  1779. hv_dev_name[len - 1] = '/';
  1780. len++;
  1781. /* For example, "xgbe/0/native_hash". */
  1782. strcpy(hv_dev_name + len, hash_default ? "/native_hash" : "/native");
  1783. /* Get the hypervisor handle for this device. */
  1784. priv->hv_devhdl = hv_dev_open((HV_VirtAddr)hv_dev_name, 0);
  1785. PDEBUG("hv_dev_open(%s) returned %d %p\n",
  1786. hv_dev_name, priv->hv_devhdl, &priv->hv_devhdl);
  1787. if (priv->hv_devhdl < 0) {
  1788. if (priv->hv_devhdl == HV_ENODEV)
  1789. printk(KERN_DEBUG "Ignoring unconfigured device %s\n",
  1790. hv_dev_name);
  1791. else
  1792. printk(KERN_DEBUG "hv_dev_open(%s) returned %d\n",
  1793. hv_dev_name, priv->hv_devhdl);
  1794. return -1;
  1795. }
  1796. /*
  1797. * Read the hardware address from the hypervisor.
  1798. * ISSUE: Note that "dev_addr" is now a pointer.
  1799. */
  1800. offset.bits.class = NETIO_PARAM;
  1801. offset.bits.addr = NETIO_PARAM_MAC;
  1802. ret = hv_dev_pread(priv->hv_devhdl, 0,
  1803. (HV_VirtAddr)dev->dev_addr, dev->addr_len,
  1804. offset.word);
  1805. PDEBUG("hv_dev_pread(NETIO_PARAM_MAC) returned %d\n", ret);
  1806. if (ret <= 0) {
  1807. printk(KERN_DEBUG "hv_dev_pread(NETIO_PARAM_MAC) %s failed\n",
  1808. dev->name);
  1809. /*
  1810. * Since the device is configured by the hypervisor but we
  1811. * can't get its MAC address, we are most likely running
  1812. * the simulator, so let's generate a random MAC address.
  1813. */
  1814. eth_hw_addr_random(dev);
  1815. }
  1816. return 0;
  1817. }
  1818. #ifdef CONFIG_NET_POLL_CONTROLLER
  1819. /*
  1820. * Polling 'interrupt' - used by things like netconsole to send skbs
  1821. * without having to re-enable interrupts. It's not called while
  1822. * the interrupt routine is executing.
  1823. */
  1824. static void tile_net_netpoll(struct net_device *dev)
  1825. {
  1826. struct tile_net_priv *priv = netdev_priv(dev);
  1827. disable_percpu_irq(priv->intr_id);
  1828. tile_net_handle_ingress_interrupt(priv->intr_id, dev);
  1829. enable_percpu_irq(priv->intr_id, 0);
  1830. }
  1831. #endif
  1832. static const struct net_device_ops tile_net_ops = {
  1833. .ndo_open = tile_net_open,
  1834. .ndo_stop = tile_net_stop,
  1835. .ndo_start_xmit = tile_net_tx,
  1836. .ndo_do_ioctl = tile_net_ioctl,
  1837. .ndo_get_stats = tile_net_get_stats,
  1838. .ndo_change_mtu = tile_net_change_mtu,
  1839. .ndo_tx_timeout = tile_net_tx_timeout,
  1840. .ndo_set_mac_address = tile_net_set_mac_address,
  1841. #ifdef CONFIG_NET_POLL_CONTROLLER
  1842. .ndo_poll_controller = tile_net_netpoll,
  1843. #endif
  1844. };
  1845. /*
  1846. * The setup function.
  1847. *
  1848. * This uses ether_setup() to assign various fields in dev, including
  1849. * setting IFF_BROADCAST and IFF_MULTICAST, then sets some extra fields.
  1850. */
  1851. static void tile_net_setup(struct net_device *dev)
  1852. {
  1853. PDEBUG("tile_net_setup()\n");
  1854. ether_setup(dev);
  1855. dev->netdev_ops = &tile_net_ops;
  1856. dev->watchdog_timeo = TILE_NET_TIMEOUT;
  1857. /* We want lockless xmit. */
  1858. dev->features |= NETIF_F_LLTX;
  1859. /* We support hardware tx checksums. */
  1860. dev->features |= NETIF_F_HW_CSUM;
  1861. /* We support scatter/gather. */
  1862. dev->features |= NETIF_F_SG;
  1863. /* We support TSO. */
  1864. dev->features |= NETIF_F_TSO;
  1865. #ifdef TILE_NET_GSO
  1866. /* We support GSO. */
  1867. dev->features |= NETIF_F_GSO;
  1868. #endif
  1869. if (hash_default)
  1870. dev->features |= NETIF_F_HIGHDMA;
  1871. /* ISSUE: We should support NETIF_F_UFO. */
  1872. dev->tx_queue_len = TILE_NET_TX_QUEUE_LEN;
  1873. dev->mtu = TILE_NET_MTU;
  1874. }
  1875. /*
  1876. * Allocate the device structure, register the device, and obtain the
  1877. * MAC address from the hypervisor.
  1878. */
  1879. static struct net_device *tile_net_dev_init(const char *name)
  1880. {
  1881. int ret;
  1882. struct net_device *dev;
  1883. struct tile_net_priv *priv;
  1884. /*
  1885. * Allocate the device structure. This allocates "priv", calls
  1886. * tile_net_setup(), and saves "name". Normally, "name" is a
  1887. * template, instantiated by register_netdev(), but not for us.
  1888. */
  1889. dev = alloc_netdev(sizeof(*priv), name, tile_net_setup);
  1890. if (!dev) {
  1891. pr_err("alloc_netdev(%s) failed\n", name);
  1892. return NULL;
  1893. }
  1894. priv = netdev_priv(dev);
  1895. /* Initialize "priv". */
  1896. memset(priv, 0, sizeof(*priv));
  1897. /* Save "dev" for "tile_net_open_retry()". */
  1898. priv->dev = dev;
  1899. INIT_DELAYED_WORK(&priv->retry_work, tile_net_open_retry);
  1900. spin_lock_init(&priv->eq_lock);
  1901. /* Allocate "eq". */
  1902. priv->eq_pages = alloc_pages(GFP_KERNEL | __GFP_ZERO, EQ_ORDER);
  1903. if (!priv->eq_pages) {
  1904. free_netdev(dev);
  1905. return NULL;
  1906. }
  1907. priv->eq = page_address(priv->eq_pages);
  1908. /* Register the network device. */
  1909. ret = register_netdev(dev);
  1910. if (ret) {
  1911. pr_err("register_netdev %s failed %d\n", dev->name, ret);
  1912. __free_pages(priv->eq_pages, EQ_ORDER);
  1913. free_netdev(dev);
  1914. return NULL;
  1915. }
  1916. /* Get the MAC address. */
  1917. ret = tile_net_get_mac(dev);
  1918. if (ret < 0) {
  1919. unregister_netdev(dev);
  1920. __free_pages(priv->eq_pages, EQ_ORDER);
  1921. free_netdev(dev);
  1922. return NULL;
  1923. }
  1924. return dev;
  1925. }
  1926. /*
  1927. * Module cleanup.
  1928. *
  1929. * FIXME: If compiled as a module, this module cannot be "unloaded",
  1930. * because the "ingress interrupt handler" is registered permanently.
  1931. */
  1932. static void tile_net_cleanup(void)
  1933. {
  1934. int i;
  1935. for (i = 0; i < TILE_NET_DEVS; i++) {
  1936. if (tile_net_devs[i]) {
  1937. struct net_device *dev = tile_net_devs[i];
  1938. struct tile_net_priv *priv = netdev_priv(dev);
  1939. unregister_netdev(dev);
  1940. finv_buffer_remote(priv->eq, EQ_SIZE, 0);
  1941. __free_pages(priv->eq_pages, EQ_ORDER);
  1942. free_netdev(dev);
  1943. }
  1944. }
  1945. }
  1946. /*
  1947. * Module initialization.
  1948. */
  1949. static int tile_net_init_module(void)
  1950. {
  1951. pr_info("Tilera Network Driver\n");
  1952. tile_net_devs[0] = tile_net_dev_init("xgbe0");
  1953. tile_net_devs[1] = tile_net_dev_init("xgbe1");
  1954. tile_net_devs[2] = tile_net_dev_init("gbe0");
  1955. tile_net_devs[3] = tile_net_dev_init("gbe1");
  1956. return 0;
  1957. }
  1958. module_init(tile_net_init_module);
  1959. module_exit(tile_net_cleanup);
  1960. #ifndef MODULE
  1961. /*
  1962. * The "network_cpus" boot argument specifies the cpus that are dedicated
  1963. * to handle ingress packets.
  1964. *
  1965. * The parameter should be in the form "network_cpus=m-n[,x-y]", where
  1966. * m, n, x, y are integer numbers that represent the cpus that can be
  1967. * neither a dedicated cpu nor a dataplane cpu.
  1968. */
  1969. static int __init network_cpus_setup(char *str)
  1970. {
  1971. int rc = cpulist_parse_crop(str, &network_cpus_map);
  1972. if (rc != 0) {
  1973. pr_warning("network_cpus=%s: malformed cpu list\n",
  1974. str);
  1975. } else {
  1976. /* Remove dedicated cpus. */
  1977. cpumask_and(&network_cpus_map, &network_cpus_map,
  1978. cpu_possible_mask);
  1979. if (cpumask_empty(&network_cpus_map)) {
  1980. pr_warning("Ignoring network_cpus='%s'.\n",
  1981. str);
  1982. } else {
  1983. char buf[1024];
  1984. cpulist_scnprintf(buf, sizeof(buf), &network_cpus_map);
  1985. pr_info("Linux network CPUs: %s\n", buf);
  1986. network_cpus_used = true;
  1987. }
  1988. }
  1989. return 0;
  1990. }
  1991. __setup("network_cpus=", network_cpus_setup);
  1992. #endif