tilepro.c 66 KB

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