usbnet.c 110 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128
  1. /*
  2. * USB Networking Links
  3. * Copyright (C) 2000-2005 by David Brownell
  4. * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz>
  5. * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
  6. * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
  7. * Copyright (c) 2002-2003 TiVo Inc.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. /*
  24. * This is a generic "USB networking" framework that works with several
  25. * kinds of full and high speed networking devices:
  26. *
  27. * + USB host-to-host "network cables", used for IP-over-USB links.
  28. * These are often used for Laplink style connectivity products.
  29. * - AnchorChip 2720
  30. * - Belkin, eTEK (interops with Win32 drivers)
  31. * - GeneSys GL620USB-A
  32. * - NetChip 1080 (interoperates with NetChip Win32 drivers)
  33. * - Prolific PL-2301/2302 (replaces "plusb" driver)
  34. * - KC Technology KC2190
  35. *
  36. * + Smart USB devices can support such links directly, using Internet
  37. * standard protocols instead of proprietary host-to-device links.
  38. * - Linux PDAs like iPaq, Yopy, and Zaurus
  39. * - The BLOB boot loader (for diskless booting)
  40. * - Linux "gadgets", perhaps using PXA-2xx or Net2280 controllers
  41. * - Devices using EPSON's sample USB firmware
  42. * - CDC-Ethernet class devices, such as many cable modems
  43. *
  44. * + Adapters to networks such as Ethernet.
  45. * - AX8817X based USB 2.0 products
  46. *
  47. * Links to these devices can be bridged using Linux Ethernet bridging.
  48. * With minor exceptions, these all use similar USB framing for network
  49. * traffic, but need different protocols for control traffic.
  50. *
  51. * USB devices can implement their side of this protocol at the cost
  52. * of two bulk endpoints; it's not restricted to "cable" applications.
  53. * See the SA1110, Zaurus, or EPSON device/client support in this driver;
  54. * slave/target drivers such as "usb-eth" (on most SA-1100 PDAs) or
  55. * "g_ether" (in the Linux "gadget" framework) implement that behavior
  56. * within devices.
  57. *
  58. *
  59. * CHANGELOG:
  60. *
  61. * 13-sep-2000 experimental, new
  62. * 10-oct-2000 usb_device_id table created.
  63. * 28-oct-2000 misc fixes; mostly, discard more TTL-mangled rx packets.
  64. * 01-nov-2000 usb_device_id table and probing api update by
  65. * Adam J. Richter <adam@yggdrasil.com>.
  66. * 18-dec-2000 (db) tx watchdog, "net1080" renaming to "usbnet", device_info
  67. * and prolific support, isolate net1080-specific bits, cleanup.
  68. * fix unlink_urbs oops in D3 PM resume code path.
  69. *
  70. * 02-feb-2001 (db) fix tx skb sharing, packet length, match_flags, ...
  71. * 08-feb-2001 stubbed in "linuxdev", maybe the SA-1100 folk can use it;
  72. * AnchorChips 2720 support (from spec) for testing;
  73. * fix bit-ordering problem with ethernet multicast addr
  74. * 19-feb-2001 Support for clearing halt conditions. SA1100 UDC support
  75. * updates. Oleg Drokin (green@iXcelerator.com)
  76. * 25-mar-2001 More SA-1100 updates, including workaround for ip problem
  77. * expecting cleared skb->cb and framing change to match latest
  78. * handhelds.org version (Oleg). Enable device IDs from the
  79. * Win32 Belkin driver; other cleanups (db).
  80. * 16-jul-2001 Bugfixes for uhci oops-on-unplug, Belkin support, various
  81. * cleanups for problems not yet seen in the field. (db)
  82. * 17-oct-2001 Handle "Advance USBNET" product, like Belkin/eTEK devices,
  83. * from Ioannis Mavroukakis <i.mavroukakis@btinternet.com>;
  84. * rx unlinks somehow weren't async; minor cleanup.
  85. * 03-nov-2001 Merged GeneSys driver; original code from Jiun-Jie Huang
  86. * <huangjj@genesyslogic.com.tw>, updated by Stanislav Brabec
  87. * <utx@penguin.cz>. Made framing options (NetChip/GeneSys)
  88. * tie mostly to (sub)driver info. Workaround some PL-2302
  89. * chips that seem to reject SET_INTERFACE requests.
  90. *
  91. * 06-apr-2002 Added ethtool support, based on a patch from Brad Hards.
  92. * Level of diagnostics is more configurable; they use device
  93. * location (usb_device->devpath) instead of address (2.5).
  94. * For tx_fixup, memflags can't be NOIO.
  95. * 07-may-2002 Generalize/cleanup keventd support, handling rx stalls (mostly
  96. * for USB 2.0 TTs) and memory shortages (potential) too. (db)
  97. * Use "locally assigned" IEEE802 address space. (Brad Hards)
  98. * 18-oct-2002 Support for Zaurus (Pavel Machek), related cleanup (db).
  99. * 14-dec-2002 Remove Zaurus-private crc32 code (Pavel); 2.5 oops fix,
  100. * cleanups and stubbed PXA-250 support (db), fix for framing
  101. * issues on Z, net1080, and gl620a (Toby Milne)
  102. *
  103. * 31-mar-2003 Use endpoint descriptors: high speed support, simpler sa1100
  104. * vs pxa25x, and CDC Ethernet. Throttle down log floods on
  105. * disconnect; other cleanups. (db) Flush net1080 fifos
  106. * after several sequential framing errors. (Johannes Erdfelt)
  107. * 22-aug-2003 AX8817X support (Dave Hollis).
  108. * 14-jun-2004 Trivial patch for AX8817X based Buffalo LUA-U2-KTX in Japan
  109. * (Neil Bortnak)
  110. * 03-nov-2004 Trivial patch for KC2190 (KC-190) chip. (Jonathan McDowell)
  111. *
  112. * 01-feb-2005 AX88772 support (Phil Chang & Dave Hollis)
  113. *-------------------------------------------------------------------------*/
  114. // #define DEBUG // error path messages, extra info
  115. // #define VERBOSE // more; success messages
  116. #include <linux/config.h>
  117. #ifdef CONFIG_USB_DEBUG
  118. # define DEBUG
  119. #endif
  120. #include <linux/module.h>
  121. #include <linux/kmod.h>
  122. #include <linux/sched.h>
  123. #include <linux/init.h>
  124. #include <linux/netdevice.h>
  125. #include <linux/etherdevice.h>
  126. #include <linux/ethtool.h>
  127. #include <linux/workqueue.h>
  128. #include <linux/mii.h>
  129. #include <linux/usb.h>
  130. #include <linux/mm.h>
  131. #include <linux/dma-mapping.h>
  132. #include <asm/unaligned.h>
  133. #include "usbnet.h"
  134. #define DRIVER_VERSION "22-Aug-2005"
  135. /*-------------------------------------------------------------------------*/
  136. /*
  137. * Nineteen USB 1.1 max size bulk transactions per frame (ms), max.
  138. * Several dozen bytes of IPv4 data can fit in two such transactions.
  139. * One maximum size Ethernet packet takes twenty four of them.
  140. * For high speed, each frame comfortably fits almost 36 max size
  141. * Ethernet packets (so queues should be bigger).
  142. *
  143. * REVISIT qlens should be members of 'struct usbnet'; the goal is to
  144. * let the USB host controller be busy for 5msec or more before an irq
  145. * is required, under load. Jumbograms change the equation.
  146. */
  147. #define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
  148. #define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
  149. /* packets are always ethernet, sometimes wrapped in other framing */
  150. #define MIN_PACKET sizeof(struct ethhdr)
  151. // reawaken network queue this soon after stopping; else watchdog barks
  152. #define TX_TIMEOUT_JIFFIES (5*HZ)
  153. // throttle rx/tx briefly after some faults, so khubd might disconnect()
  154. // us (it polls at HZ/4 usually) before we report too many false errors.
  155. #define THROTTLE_JIFFIES (HZ/8)
  156. // for vendor-specific control operations
  157. #define CONTROL_TIMEOUT_MS USB_CTRL_GET_TIMEOUT
  158. // between wakeups
  159. #define UNLINK_TIMEOUT_MS 3
  160. /*-------------------------------------------------------------------------*/
  161. // randomly generated ethernet address
  162. static u8 node_id [ETH_ALEN];
  163. static const char driver_name [] = "usbnet";
  164. /* use ethtool to change the level for any given device */
  165. static int msg_level = -1;
  166. module_param (msg_level, int, 0);
  167. MODULE_PARM_DESC (msg_level, "Override default message level");
  168. /*-------------------------------------------------------------------------*/
  169. static void usbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *);
  170. static u32 usbnet_get_link (struct net_device *);
  171. static u32 usbnet_get_msglevel (struct net_device *);
  172. static void usbnet_set_msglevel (struct net_device *, u32);
  173. static void defer_kevent (struct usbnet *, int);
  174. /* mostly for PDA style devices, which are always connected if present */
  175. static int always_connected (struct usbnet *dev)
  176. {
  177. return 0;
  178. }
  179. /* handles CDC Ethernet and many other network "bulk data" interfaces */
  180. static int
  181. get_endpoints (struct usbnet *dev, struct usb_interface *intf)
  182. {
  183. int tmp;
  184. struct usb_host_interface *alt = NULL;
  185. struct usb_host_endpoint *in = NULL, *out = NULL;
  186. struct usb_host_endpoint *status = NULL;
  187. for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
  188. unsigned ep;
  189. in = out = status = NULL;
  190. alt = intf->altsetting + tmp;
  191. /* take the first altsetting with in-bulk + out-bulk;
  192. * remember any status endpoint, just in case;
  193. * ignore other endpoints and altsetttings.
  194. */
  195. for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
  196. struct usb_host_endpoint *e;
  197. int intr = 0;
  198. e = alt->endpoint + ep;
  199. switch (e->desc.bmAttributes) {
  200. case USB_ENDPOINT_XFER_INT:
  201. if (!(e->desc.bEndpointAddress & USB_DIR_IN))
  202. continue;
  203. intr = 1;
  204. /* FALLTHROUGH */
  205. case USB_ENDPOINT_XFER_BULK:
  206. break;
  207. default:
  208. continue;
  209. }
  210. if (e->desc.bEndpointAddress & USB_DIR_IN) {
  211. if (!intr && !in)
  212. in = e;
  213. else if (intr && !status)
  214. status = e;
  215. } else {
  216. if (!out)
  217. out = e;
  218. }
  219. }
  220. if (in && out)
  221. break;
  222. }
  223. if (!alt || !in || !out)
  224. return -EINVAL;
  225. if (alt->desc.bAlternateSetting != 0
  226. || !(dev->driver_info->flags & FLAG_NO_SETINT)) {
  227. tmp = usb_set_interface (dev->udev, alt->desc.bInterfaceNumber,
  228. alt->desc.bAlternateSetting);
  229. if (tmp < 0)
  230. return tmp;
  231. }
  232. dev->in = usb_rcvbulkpipe (dev->udev,
  233. in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
  234. dev->out = usb_sndbulkpipe (dev->udev,
  235. out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
  236. dev->status = status;
  237. return 0;
  238. }
  239. static void intr_complete (struct urb *urb, struct pt_regs *regs);
  240. static int init_status (struct usbnet *dev, struct usb_interface *intf)
  241. {
  242. char *buf = NULL;
  243. unsigned pipe = 0;
  244. unsigned maxp;
  245. unsigned period;
  246. if (!dev->driver_info->status)
  247. return 0;
  248. pipe = usb_rcvintpipe (dev->udev,
  249. dev->status->desc.bEndpointAddress
  250. & USB_ENDPOINT_NUMBER_MASK);
  251. maxp = usb_maxpacket (dev->udev, pipe, 0);
  252. /* avoid 1 msec chatter: min 8 msec poll rate */
  253. period = max ((int) dev->status->desc.bInterval,
  254. (dev->udev->speed == USB_SPEED_HIGH) ? 7 : 3);
  255. buf = kmalloc (maxp, SLAB_KERNEL);
  256. if (buf) {
  257. dev->interrupt = usb_alloc_urb (0, SLAB_KERNEL);
  258. if (!dev->interrupt) {
  259. kfree (buf);
  260. return -ENOMEM;
  261. } else {
  262. usb_fill_int_urb(dev->interrupt, dev->udev, pipe,
  263. buf, maxp, intr_complete, dev, period);
  264. dev_dbg(&intf->dev,
  265. "status ep%din, %d bytes period %d\n",
  266. usb_pipeendpoint(pipe), maxp, period);
  267. }
  268. }
  269. return 0;
  270. }
  271. static void skb_return (struct usbnet *dev, struct sk_buff *skb)
  272. {
  273. int status;
  274. skb->dev = dev->net;
  275. skb->protocol = eth_type_trans (skb, dev->net);
  276. dev->stats.rx_packets++;
  277. dev->stats.rx_bytes += skb->len;
  278. if (netif_msg_rx_status (dev))
  279. devdbg (dev, "< rx, len %zu, type 0x%x",
  280. skb->len + sizeof (struct ethhdr), skb->protocol);
  281. memset (skb->cb, 0, sizeof (struct skb_data));
  282. status = netif_rx (skb);
  283. if (status != NET_RX_SUCCESS && netif_msg_rx_err (dev))
  284. devdbg (dev, "netif_rx status %d", status);
  285. }
  286. #ifdef CONFIG_USB_ALI_M5632
  287. #define HAVE_HARDWARE
  288. /*-------------------------------------------------------------------------
  289. *
  290. * ALi M5632 driver ... does high speed
  291. *
  292. *-------------------------------------------------------------------------*/
  293. static const struct driver_info ali_m5632_info = {
  294. .description = "ALi M5632",
  295. };
  296. #endif
  297. #ifdef CONFIG_USB_AN2720
  298. #define HAVE_HARDWARE
  299. /*-------------------------------------------------------------------------
  300. *
  301. * AnchorChips 2720 driver ... http://www.cypress.com
  302. *
  303. * This doesn't seem to have a way to detect whether the peer is
  304. * connected, or need any reset handshaking. It's got pretty big
  305. * internal buffers (handles most of a frame's worth of data).
  306. * Chip data sheets don't describe any vendor control messages.
  307. *
  308. *-------------------------------------------------------------------------*/
  309. static const struct driver_info an2720_info = {
  310. .description = "AnchorChips/Cypress 2720",
  311. // no reset available!
  312. // no check_connect available!
  313. .in = 2, .out = 2, // direction distinguishes these
  314. };
  315. #endif /* CONFIG_USB_AN2720 */
  316. #ifdef CONFIG_USB_AX8817X
  317. /* ASIX AX8817X based USB 2.0 Ethernet Devices */
  318. #define HAVE_HARDWARE
  319. #define NEED_MII
  320. #include <linux/crc32.h>
  321. #define AX_CMD_SET_SW_MII 0x06
  322. #define AX_CMD_READ_MII_REG 0x07
  323. #define AX_CMD_WRITE_MII_REG 0x08
  324. #define AX_CMD_SET_HW_MII 0x0a
  325. #define AX_CMD_READ_EEPROM 0x0b
  326. #define AX_CMD_WRITE_EEPROM 0x0c
  327. #define AX_CMD_WRITE_ENABLE 0x0d
  328. #define AX_CMD_WRITE_DISABLE 0x0e
  329. #define AX_CMD_WRITE_RX_CTL 0x10
  330. #define AX_CMD_READ_IPG012 0x11
  331. #define AX_CMD_WRITE_IPG0 0x12
  332. #define AX_CMD_WRITE_IPG1 0x13
  333. #define AX_CMD_WRITE_IPG2 0x14
  334. #define AX_CMD_WRITE_MULTI_FILTER 0x16
  335. #define AX_CMD_READ_NODE_ID 0x17
  336. #define AX_CMD_READ_PHY_ID 0x19
  337. #define AX_CMD_READ_MEDIUM_STATUS 0x1a
  338. #define AX_CMD_WRITE_MEDIUM_MODE 0x1b
  339. #define AX_CMD_READ_MONITOR_MODE 0x1c
  340. #define AX_CMD_WRITE_MONITOR_MODE 0x1d
  341. #define AX_CMD_WRITE_GPIOS 0x1f
  342. #define AX_CMD_SW_RESET 0x20
  343. #define AX_CMD_SW_PHY_STATUS 0x21
  344. #define AX_CMD_SW_PHY_SELECT 0x22
  345. #define AX88772_CMD_READ_NODE_ID 0x13
  346. #define AX_MONITOR_MODE 0x01
  347. #define AX_MONITOR_LINK 0x02
  348. #define AX_MONITOR_MAGIC 0x04
  349. #define AX_MONITOR_HSFS 0x10
  350. /* AX88172 Medium Status Register values */
  351. #define AX_MEDIUM_FULL_DUPLEX 0x02
  352. #define AX_MEDIUM_TX_ABORT_ALLOW 0x04
  353. #define AX_MEDIUM_FLOW_CONTROL_EN 0x10
  354. #define AX_MCAST_FILTER_SIZE 8
  355. #define AX_MAX_MCAST 64
  356. #define AX_EEPROM_LEN 0x40
  357. #define AX_SWRESET_CLEAR 0x00
  358. #define AX_SWRESET_RR 0x01
  359. #define AX_SWRESET_RT 0x02
  360. #define AX_SWRESET_PRTE 0x04
  361. #define AX_SWRESET_PRL 0x08
  362. #define AX_SWRESET_BZ 0x10
  363. #define AX_SWRESET_IPRL 0x20
  364. #define AX_SWRESET_IPPD 0x40
  365. #define AX88772_IPG0_DEFAULT 0x15
  366. #define AX88772_IPG1_DEFAULT 0x0c
  367. #define AX88772_IPG2_DEFAULT 0x12
  368. #define AX88772_MEDIUM_FULL_DUPLEX 0x0002
  369. #define AX88772_MEDIUM_RESERVED 0x0004
  370. #define AX88772_MEDIUM_RX_FC_ENABLE 0x0010
  371. #define AX88772_MEDIUM_TX_FC_ENABLE 0x0020
  372. #define AX88772_MEDIUM_PAUSE_FORMAT 0x0080
  373. #define AX88772_MEDIUM_RX_ENABLE 0x0100
  374. #define AX88772_MEDIUM_100MB 0x0200
  375. #define AX88772_MEDIUM_DEFAULT \
  376. (AX88772_MEDIUM_FULL_DUPLEX | AX88772_MEDIUM_RX_FC_ENABLE | \
  377. AX88772_MEDIUM_TX_FC_ENABLE | AX88772_MEDIUM_100MB | \
  378. AX88772_MEDIUM_RESERVED | AX88772_MEDIUM_RX_ENABLE )
  379. #define AX_EEPROM_MAGIC 0xdeadbeef
  380. /* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
  381. struct ax8817x_data {
  382. u8 multi_filter[AX_MCAST_FILTER_SIZE];
  383. };
  384. struct ax88172_int_data {
  385. u16 res1;
  386. u8 link;
  387. u16 res2;
  388. u8 status;
  389. u16 res3;
  390. } __attribute__ ((packed));
  391. static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
  392. u16 size, void *data)
  393. {
  394. return usb_control_msg(
  395. dev->udev,
  396. usb_rcvctrlpipe(dev->udev, 0),
  397. cmd,
  398. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  399. value,
  400. index,
  401. data,
  402. size,
  403. CONTROL_TIMEOUT_MS);
  404. }
  405. static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
  406. u16 size, void *data)
  407. {
  408. return usb_control_msg(
  409. dev->udev,
  410. usb_sndctrlpipe(dev->udev, 0),
  411. cmd,
  412. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  413. value,
  414. index,
  415. data,
  416. size,
  417. CONTROL_TIMEOUT_MS);
  418. }
  419. static void ax8817x_async_cmd_callback(struct urb *urb, struct pt_regs *regs)
  420. {
  421. struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
  422. if (urb->status < 0)
  423. printk(KERN_DEBUG "ax8817x_async_cmd_callback() failed with %d",
  424. urb->status);
  425. kfree(req);
  426. usb_free_urb(urb);
  427. }
  428. static void ax8817x_status(struct usbnet *dev, struct urb *urb)
  429. {
  430. struct ax88172_int_data *event;
  431. int link;
  432. if (urb->actual_length < 8)
  433. return;
  434. event = urb->transfer_buffer;
  435. link = event->link & 0x01;
  436. if (netif_carrier_ok(dev->net) != link) {
  437. if (link) {
  438. netif_carrier_on(dev->net);
  439. defer_kevent (dev, EVENT_LINK_RESET );
  440. } else
  441. netif_carrier_off(dev->net);
  442. devdbg(dev, "ax8817x - Link Status is: %d", link);
  443. }
  444. }
  445. static void ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
  446. u16 size, void *data)
  447. {
  448. struct usb_ctrlrequest *req;
  449. int status;
  450. struct urb *urb;
  451. if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) {
  452. devdbg(dev, "Error allocating URB in write_cmd_async!");
  453. return;
  454. }
  455. if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) {
  456. deverr(dev, "Failed to allocate memory for control request");
  457. usb_free_urb(urb);
  458. return;
  459. }
  460. req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
  461. req->bRequest = cmd;
  462. req->wValue = cpu_to_le16(value);
  463. req->wIndex = cpu_to_le16(index);
  464. req->wLength = cpu_to_le16(size);
  465. usb_fill_control_urb(urb, dev->udev,
  466. usb_sndctrlpipe(dev->udev, 0),
  467. (void *)req, data, size,
  468. ax8817x_async_cmd_callback, req);
  469. if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
  470. deverr(dev, "Error submitting the control message: status=%d", status);
  471. kfree(req);
  472. usb_free_urb(urb);
  473. }
  474. }
  475. static void ax8817x_set_multicast(struct net_device *net)
  476. {
  477. struct usbnet *dev = netdev_priv(net);
  478. struct ax8817x_data *data = (struct ax8817x_data *)&dev->data;
  479. u8 rx_ctl = 0x8c;
  480. if (net->flags & IFF_PROMISC) {
  481. rx_ctl |= 0x01;
  482. } else if (net->flags & IFF_ALLMULTI
  483. || net->mc_count > AX_MAX_MCAST) {
  484. rx_ctl |= 0x02;
  485. } else if (net->mc_count == 0) {
  486. /* just broadcast and directed */
  487. } else {
  488. /* We use the 20 byte dev->data
  489. * for our 8 byte filter buffer
  490. * to avoid allocating memory that
  491. * is tricky to free later */
  492. struct dev_mc_list *mc_list = net->mc_list;
  493. u32 crc_bits;
  494. int i;
  495. memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
  496. /* Build the multicast hash filter. */
  497. for (i = 0; i < net->mc_count; i++) {
  498. crc_bits =
  499. ether_crc(ETH_ALEN,
  500. mc_list->dmi_addr) >> 26;
  501. data->multi_filter[crc_bits >> 3] |=
  502. 1 << (crc_bits & 7);
  503. mc_list = mc_list->next;
  504. }
  505. ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
  506. AX_MCAST_FILTER_SIZE, data->multi_filter);
  507. rx_ctl |= 0x10;
  508. }
  509. ax8817x_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
  510. }
  511. static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc)
  512. {
  513. struct usbnet *dev = netdev_priv(netdev);
  514. u16 res;
  515. u8 buf[1];
  516. ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
  517. ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
  518. ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
  519. return res & 0xffff;
  520. }
  521. static void ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
  522. {
  523. struct usbnet *dev = netdev_priv(netdev);
  524. u16 res = val;
  525. u8 buf[1];
  526. ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
  527. ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
  528. ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
  529. }
  530. static int ax88172_link_reset(struct usbnet *dev)
  531. {
  532. u16 lpa;
  533. u8 mode;
  534. mode = AX_MEDIUM_TX_ABORT_ALLOW | AX_MEDIUM_FLOW_CONTROL_EN;
  535. lpa = ax8817x_mdio_read(dev->net, dev->mii.phy_id, MII_LPA);
  536. if (lpa & LPA_DUPLEX)
  537. mode |= AX_MEDIUM_FULL_DUPLEX;
  538. ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
  539. return 0;
  540. }
  541. static void ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
  542. {
  543. struct usbnet *dev = netdev_priv(net);
  544. u8 opt;
  545. if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
  546. wolinfo->supported = 0;
  547. wolinfo->wolopts = 0;
  548. return;
  549. }
  550. wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
  551. wolinfo->wolopts = 0;
  552. if (opt & AX_MONITOR_MODE) {
  553. if (opt & AX_MONITOR_LINK)
  554. wolinfo->wolopts |= WAKE_PHY;
  555. if (opt & AX_MONITOR_MAGIC)
  556. wolinfo->wolopts |= WAKE_MAGIC;
  557. }
  558. }
  559. static int ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
  560. {
  561. struct usbnet *dev = netdev_priv(net);
  562. u8 opt = 0;
  563. u8 buf[1];
  564. if (wolinfo->wolopts & WAKE_PHY)
  565. opt |= AX_MONITOR_LINK;
  566. if (wolinfo->wolopts & WAKE_MAGIC)
  567. opt |= AX_MONITOR_MAGIC;
  568. if (opt != 0)
  569. opt |= AX_MONITOR_MODE;
  570. if (ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
  571. opt, 0, 0, &buf) < 0)
  572. return -EINVAL;
  573. return 0;
  574. }
  575. static int ax8817x_get_eeprom_len(struct net_device *net)
  576. {
  577. return AX_EEPROM_LEN;
  578. }
  579. static int ax8817x_get_eeprom(struct net_device *net,
  580. struct ethtool_eeprom *eeprom, u8 *data)
  581. {
  582. struct usbnet *dev = netdev_priv(net);
  583. u16 *ebuf = (u16 *)data;
  584. int i;
  585. /* Crude hack to ensure that we don't overwrite memory
  586. * if an odd length is supplied
  587. */
  588. if (eeprom->len % 2)
  589. return -EINVAL;
  590. eeprom->magic = AX_EEPROM_MAGIC;
  591. /* ax8817x returns 2 bytes from eeprom on read */
  592. for (i=0; i < eeprom->len / 2; i++) {
  593. if (ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM,
  594. eeprom->offset + i, 0, 2, &ebuf[i]) < 0)
  595. return -EINVAL;
  596. }
  597. return 0;
  598. }
  599. static void ax8817x_get_drvinfo (struct net_device *net,
  600. struct ethtool_drvinfo *info)
  601. {
  602. /* Inherit standard device info */
  603. usbnet_get_drvinfo(net, info);
  604. info->eedump_len = 0x3e;
  605. }
  606. static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
  607. {
  608. struct usbnet *dev = netdev_priv(net);
  609. return mii_ethtool_gset(&dev->mii,cmd);
  610. }
  611. static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
  612. {
  613. struct usbnet *dev = netdev_priv(net);
  614. return mii_ethtool_sset(&dev->mii,cmd);
  615. }
  616. /* We need to override some ethtool_ops so we require our
  617. own structure so we don't interfere with other usbnet
  618. devices that may be connected at the same time. */
  619. static struct ethtool_ops ax8817x_ethtool_ops = {
  620. .get_drvinfo = ax8817x_get_drvinfo,
  621. .get_link = ethtool_op_get_link,
  622. .get_msglevel = usbnet_get_msglevel,
  623. .set_msglevel = usbnet_set_msglevel,
  624. .get_wol = ax8817x_get_wol,
  625. .set_wol = ax8817x_set_wol,
  626. .get_eeprom_len = ax8817x_get_eeprom_len,
  627. .get_eeprom = ax8817x_get_eeprom,
  628. .get_settings = ax8817x_get_settings,
  629. .set_settings = ax8817x_set_settings,
  630. };
  631. static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf)
  632. {
  633. int ret = 0;
  634. void *buf;
  635. int i;
  636. unsigned long gpio_bits = dev->driver_info->data;
  637. get_endpoints(dev,intf);
  638. buf = kmalloc(ETH_ALEN, GFP_KERNEL);
  639. if(!buf) {
  640. ret = -ENOMEM;
  641. goto out1;
  642. }
  643. /* Toggle the GPIOs in a manufacturer/model specific way */
  644. for (i = 2; i >= 0; i--) {
  645. if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS,
  646. (gpio_bits >> (i * 8)) & 0xff, 0, 0,
  647. buf)) < 0)
  648. goto out2;
  649. msleep(5);
  650. }
  651. if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x80, 0, 0, buf)) < 0) {
  652. dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret);
  653. goto out2;
  654. }
  655. /* Get the MAC address */
  656. memset(buf, 0, ETH_ALEN);
  657. if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, 6, buf)) < 0) {
  658. dbg("read AX_CMD_READ_NODE_ID failed: %d", ret);
  659. goto out2;
  660. }
  661. memcpy(dev->net->dev_addr, buf, ETH_ALEN);
  662. /* Get the PHY id */
  663. if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) {
  664. dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret);
  665. goto out2;
  666. } else if (ret < 2) {
  667. /* this should always return 2 bytes */
  668. dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", ret);
  669. ret = -EIO;
  670. goto out2;
  671. }
  672. /* Initialize MII structure */
  673. dev->mii.dev = dev->net;
  674. dev->mii.mdio_read = ax8817x_mdio_read;
  675. dev->mii.mdio_write = ax8817x_mdio_write;
  676. dev->mii.phy_id_mask = 0x3f;
  677. dev->mii.reg_num_mask = 0x1f;
  678. dev->mii.phy_id = *((u8 *)buf + 1);
  679. dev->net->set_multicast_list = ax8817x_set_multicast;
  680. dev->net->ethtool_ops = &ax8817x_ethtool_ops;
  681. ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
  682. ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
  683. ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  684. mii_nway_restart(&dev->mii);
  685. if (dev->driver_info->flags & FLAG_FRAMING_AX) {
  686. /* REVISIT: adjust hard_header_len too */
  687. dev->hard_mtu = 2048;
  688. }
  689. return 0;
  690. out2:
  691. kfree(buf);
  692. out1:
  693. return ret;
  694. }
  695. static struct ethtool_ops ax88772_ethtool_ops = {
  696. .get_drvinfo = ax8817x_get_drvinfo,
  697. .get_link = ethtool_op_get_link,
  698. .get_msglevel = usbnet_get_msglevel,
  699. .set_msglevel = usbnet_set_msglevel,
  700. .get_wol = ax8817x_get_wol,
  701. .set_wol = ax8817x_set_wol,
  702. .get_eeprom_len = ax8817x_get_eeprom_len,
  703. .get_eeprom = ax8817x_get_eeprom,
  704. .get_settings = ax8817x_get_settings,
  705. .set_settings = ax8817x_set_settings,
  706. };
  707. static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
  708. {
  709. int ret;
  710. void *buf;
  711. get_endpoints(dev,intf);
  712. buf = kmalloc(6, GFP_KERNEL);
  713. if(!buf) {
  714. dbg ("Cannot allocate memory for buffer");
  715. ret = -ENOMEM;
  716. goto out1;
  717. }
  718. if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS,
  719. 0x00B0, 0, 0, buf)) < 0)
  720. goto out2;
  721. msleep(5);
  722. if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 0x0001, 0, 0, buf)) < 0) {
  723. dbg("Select PHY #1 failed: %d", ret);
  724. goto out2;
  725. }
  726. if ((ret =
  727. ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPPD, 0, 0, buf)) < 0) {
  728. dbg("Failed to power down internal PHY: %d", ret);
  729. goto out2;
  730. }
  731. msleep(150);
  732. if ((ret =
  733. ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_CLEAR, 0, 0, buf)) < 0) {
  734. dbg("Failed to perform software reset: %d", ret);
  735. goto out2;
  736. }
  737. msleep(150);
  738. if ((ret =
  739. ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL | AX_SWRESET_PRL, 0, 0, buf)) < 0) {
  740. dbg("Failed to set Internal/External PHY reset control: %d", ret);
  741. goto out2;
  742. }
  743. msleep(150);
  744. if ((ret =
  745. ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0000, 0, 0,
  746. buf)) < 0) {
  747. dbg("Failed to reset RX_CTL: %d", ret);
  748. goto out2;
  749. }
  750. /* Get the MAC address */
  751. memset(buf, 0, ETH_ALEN);
  752. if ((ret = ax8817x_read_cmd(dev, AX88772_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf)) < 0) {
  753. dbg("Failed to read MAC address: %d", ret);
  754. goto out2;
  755. }
  756. memcpy(dev->net->dev_addr, buf, ETH_ALEN);
  757. if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, buf)) < 0) {
  758. dbg("Enabling software MII failed: %d", ret);
  759. goto out2;
  760. }
  761. if (((ret =
  762. ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, 0x0010, 2, 2, buf)) < 0)
  763. || (*((u16 *)buf) != 0x003b)) {
  764. dbg("Read PHY register 2 must be 0x3b00: %d", ret);
  765. goto out2;
  766. }
  767. /* Initialize MII structure */
  768. dev->mii.dev = dev->net;
  769. dev->mii.mdio_read = ax8817x_mdio_read;
  770. dev->mii.mdio_write = ax8817x_mdio_write;
  771. dev->mii.phy_id_mask = 0xff;
  772. dev->mii.reg_num_mask = 0xff;
  773. /* Get the PHY id */
  774. if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) {
  775. dbg("Error reading PHY ID: %02x", ret);
  776. goto out2;
  777. } else if (ret < 2) {
  778. /* this should always return 2 bytes */
  779. dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x",
  780. ret);
  781. ret = -EIO;
  782. goto out2;
  783. }
  784. dev->mii.phy_id = *((u8 *)buf + 1);
  785. if ((ret =
  786. ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_PRL, 0, 0, buf)) < 0) {
  787. dbg("Set external PHY reset pin level: %d", ret);
  788. goto out2;
  789. }
  790. msleep(150);
  791. if ((ret =
  792. ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL | AX_SWRESET_PRL, 0, 0, buf)) < 0) {
  793. dbg("Set Internal/External PHY reset control: %d", ret);
  794. goto out2;
  795. }
  796. msleep(150);
  797. dev->net->set_multicast_list = ax8817x_set_multicast;
  798. dev->net->ethtool_ops = &ax88772_ethtool_ops;
  799. ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
  800. ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
  801. ADVERTISE_ALL | ADVERTISE_CSMA);
  802. mii_nway_restart(&dev->mii);
  803. if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, AX88772_MEDIUM_DEFAULT, 0, 0, buf)) < 0) {
  804. dbg("Write medium mode register: %d", ret);
  805. goto out2;
  806. }
  807. if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_IPG0, AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,AX88772_IPG2_DEFAULT, 0, buf)) < 0) {
  808. dbg("Write IPG,IPG1,IPG2 failed: %d", ret);
  809. goto out2;
  810. }
  811. if ((ret =
  812. ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf)) < 0) {
  813. dbg("Failed to set hardware MII: %02x", ret);
  814. goto out2;
  815. }
  816. /* Set RX_CTL to default values with 2k buffer, and enable cactus */
  817. if ((ret =
  818. ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0088, 0, 0,
  819. buf)) < 0) {
  820. dbg("Reset RX_CTL failed: %d", ret);
  821. goto out2;
  822. }
  823. kfree(buf);
  824. return 0;
  825. out2:
  826. kfree(buf);
  827. out1:
  828. return ret;
  829. }
  830. static int ax88772_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
  831. {
  832. u32 *header;
  833. char *packet;
  834. struct sk_buff *ax_skb;
  835. u16 size;
  836. header = (u32 *) skb->data;
  837. le32_to_cpus(header);
  838. packet = (char *)(header + 1);
  839. skb_pull(skb, 4);
  840. while (skb->len > 0) {
  841. if ((short)(*header & 0x0000ffff) !=
  842. ~((short)((*header & 0xffff0000) >> 16))) {
  843. devdbg(dev,"header length data is error");
  844. }
  845. /* get the packet length */
  846. size = (u16) (*header & 0x0000ffff);
  847. if ((skb->len) - ((size + 1) & 0xfffe) == 0)
  848. return 2;
  849. if (size > ETH_FRAME_LEN) {
  850. devdbg(dev,"invalid rx length %d", size);
  851. return 0;
  852. }
  853. ax_skb = skb_clone(skb, GFP_ATOMIC);
  854. if (ax_skb) {
  855. ax_skb->len = size;
  856. ax_skb->data = packet;
  857. ax_skb->tail = packet + size;
  858. skb_return(dev, ax_skb);
  859. } else {
  860. return 0;
  861. }
  862. skb_pull(skb, (size + 1) & 0xfffe);
  863. if (skb->len == 0)
  864. break;
  865. header = (u32 *) skb->data;
  866. le32_to_cpus(header);
  867. packet = (char *)(header + 1);
  868. skb_pull(skb, 4);
  869. }
  870. if (skb->len < 0) {
  871. devdbg(dev,"invalid rx length %d", skb->len);
  872. return 0;
  873. }
  874. return 1;
  875. }
  876. static struct sk_buff *ax88772_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
  877. unsigned flags)
  878. {
  879. int padlen;
  880. int headroom = skb_headroom(skb);
  881. int tailroom = skb_tailroom(skb);
  882. u32 *packet_len;
  883. u32 *padbytes_ptr;
  884. padlen = ((skb->len + 4) % 512) ? 0 : 4;
  885. if ((!skb_cloned(skb))
  886. && ((headroom + tailroom) >= (4 + padlen))) {
  887. if ((headroom < 4) || (tailroom < padlen)) {
  888. skb->data = memmove(skb->head + 4, skb->data, skb->len);
  889. skb->tail = skb->data + skb->len;
  890. }
  891. } else {
  892. struct sk_buff *skb2;
  893. skb2 = skb_copy_expand(skb, 4, padlen, flags);
  894. dev_kfree_skb_any(skb);
  895. skb = skb2;
  896. if (!skb)
  897. return NULL;
  898. }
  899. packet_len = (u32 *) skb_push(skb, 4);
  900. packet_len = (u32 *) skb->data;
  901. *packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4);
  902. if ((skb->len % 512) == 0) {
  903. padbytes_ptr = (u32 *) skb->tail;
  904. *padbytes_ptr = 0xffff0000;
  905. skb_put(skb, padlen);
  906. }
  907. return skb;
  908. }
  909. static int ax88772_link_reset(struct usbnet *dev)
  910. {
  911. u16 lpa;
  912. u16 mode;
  913. mode = AX88772_MEDIUM_DEFAULT;
  914. lpa = ax8817x_mdio_read(dev->net, dev->mii.phy_id, MII_LPA);
  915. if ((lpa & LPA_DUPLEX) == 0)
  916. mode &= ~AX88772_MEDIUM_FULL_DUPLEX;
  917. if ((lpa & LPA_100) == 0)
  918. mode &= ~AX88772_MEDIUM_100MB;
  919. ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
  920. return 0;
  921. }
  922. static const struct driver_info ax8817x_info = {
  923. .description = "ASIX AX8817x USB 2.0 Ethernet",
  924. .bind = ax8817x_bind,
  925. .status = ax8817x_status,
  926. .link_reset = ax88172_link_reset,
  927. .reset = ax88172_link_reset,
  928. .flags = FLAG_ETHER,
  929. .data = 0x00130103,
  930. };
  931. static const struct driver_info dlink_dub_e100_info = {
  932. .description = "DLink DUB-E100 USB Ethernet",
  933. .bind = ax8817x_bind,
  934. .status = ax8817x_status,
  935. .link_reset = ax88172_link_reset,
  936. .reset = ax88172_link_reset,
  937. .flags = FLAG_ETHER,
  938. .data = 0x009f9d9f,
  939. };
  940. static const struct driver_info netgear_fa120_info = {
  941. .description = "Netgear FA-120 USB Ethernet",
  942. .bind = ax8817x_bind,
  943. .status = ax8817x_status,
  944. .link_reset = ax88172_link_reset,
  945. .reset = ax88172_link_reset,
  946. .flags = FLAG_ETHER,
  947. .data = 0x00130103,
  948. };
  949. static const struct driver_info hawking_uf200_info = {
  950. .description = "Hawking UF200 USB Ethernet",
  951. .bind = ax8817x_bind,
  952. .status = ax8817x_status,
  953. .link_reset = ax88172_link_reset,
  954. .reset = ax88172_link_reset,
  955. .flags = FLAG_ETHER,
  956. .data = 0x001f1d1f,
  957. };
  958. static const struct driver_info ax88772_info = {
  959. .description = "ASIX AX88772 USB 2.0 Ethernet",
  960. .bind = ax88772_bind,
  961. .status = ax8817x_status,
  962. .link_reset = ax88772_link_reset,
  963. .reset = ax88772_link_reset,
  964. .flags = FLAG_ETHER | FLAG_FRAMING_AX,
  965. .rx_fixup = ax88772_rx_fixup,
  966. .tx_fixup = ax88772_tx_fixup,
  967. .data = 0x00130103,
  968. };
  969. #endif /* CONFIG_USB_AX8817X */
  970. #ifdef CONFIG_USB_BELKIN
  971. #define HAVE_HARDWARE
  972. /*-------------------------------------------------------------------------
  973. *
  974. * Belkin F5U104 ... two NetChip 2280 devices + Atmel microcontroller
  975. *
  976. * ... also two eTEK designs, including one sold as "Advance USBNET"
  977. *
  978. *-------------------------------------------------------------------------*/
  979. static const struct driver_info belkin_info = {
  980. .description = "Belkin, eTEK, or compatible",
  981. };
  982. #endif /* CONFIG_USB_BELKIN */
  983. /*-------------------------------------------------------------------------
  984. *
  985. * Communications Device Class declarations.
  986. * Used by CDC Ethernet, and some CDC variants
  987. *
  988. *-------------------------------------------------------------------------*/
  989. #ifdef CONFIG_USB_CDCETHER
  990. #define NEED_GENERIC_CDC
  991. #endif
  992. #ifdef CONFIG_USB_ZAURUS
  993. /* Ethernet variant uses funky framing, broken ethernet addressing */
  994. #define NEED_GENERIC_CDC
  995. #endif
  996. #ifdef CONFIG_USB_RNDIS
  997. /* ACM variant uses even funkier framing, complex control RPC scheme */
  998. #define NEED_GENERIC_CDC
  999. #endif
  1000. #ifdef NEED_GENERIC_CDC
  1001. #include <linux/usb_cdc.h>
  1002. struct cdc_state {
  1003. struct usb_cdc_header_desc *header;
  1004. struct usb_cdc_union_desc *u;
  1005. struct usb_cdc_ether_desc *ether;
  1006. struct usb_interface *control;
  1007. struct usb_interface *data;
  1008. };
  1009. static struct usb_driver usbnet_driver;
  1010. /*
  1011. * probes control interface, claims data interface, collects the bulk
  1012. * endpoints, activates data interface (if needed), maybe sets MTU.
  1013. * all pure cdc, except for certain firmware workarounds.
  1014. */
  1015. static int generic_cdc_bind (struct usbnet *dev, struct usb_interface *intf)
  1016. {
  1017. u8 *buf = intf->cur_altsetting->extra;
  1018. int len = intf->cur_altsetting->extralen;
  1019. struct usb_interface_descriptor *d;
  1020. struct cdc_state *info = (void *) &dev->data;
  1021. int status;
  1022. int rndis;
  1023. if (sizeof dev->data < sizeof *info)
  1024. return -EDOM;
  1025. /* expect strict spec conformance for the descriptors, but
  1026. * cope with firmware which stores them in the wrong place
  1027. */
  1028. if (len == 0 && dev->udev->actconfig->extralen) {
  1029. /* Motorola SB4100 (and others: Brad Hards says it's
  1030. * from a Broadcom design) put CDC descriptors here
  1031. */
  1032. buf = dev->udev->actconfig->extra;
  1033. len = dev->udev->actconfig->extralen;
  1034. if (len)
  1035. dev_dbg (&intf->dev,
  1036. "CDC descriptors on config\n");
  1037. }
  1038. /* this assumes that if there's a non-RNDIS vendor variant
  1039. * of cdc-acm, it'll fail RNDIS requests cleanly.
  1040. */
  1041. rndis = (intf->cur_altsetting->desc.bInterfaceProtocol == 0xff);
  1042. memset (info, 0, sizeof *info);
  1043. info->control = intf;
  1044. while (len > 3) {
  1045. if (buf [1] != USB_DT_CS_INTERFACE)
  1046. goto next_desc;
  1047. /* use bDescriptorSubType to identify the CDC descriptors.
  1048. * We expect devices with CDC header and union descriptors.
  1049. * For CDC Ethernet we need the ethernet descriptor.
  1050. * For RNDIS, ignore two (pointless) CDC modem descriptors
  1051. * in favor of a complicated OID-based RPC scheme doing what
  1052. * CDC Ethernet achieves with a simple descriptor.
  1053. */
  1054. switch (buf [2]) {
  1055. case USB_CDC_HEADER_TYPE:
  1056. if (info->header) {
  1057. dev_dbg (&intf->dev, "extra CDC header\n");
  1058. goto bad_desc;
  1059. }
  1060. info->header = (void *) buf;
  1061. if (info->header->bLength != sizeof *info->header) {
  1062. dev_dbg (&intf->dev, "CDC header len %u\n",
  1063. info->header->bLength);
  1064. goto bad_desc;
  1065. }
  1066. break;
  1067. case USB_CDC_UNION_TYPE:
  1068. if (info->u) {
  1069. dev_dbg (&intf->dev, "extra CDC union\n");
  1070. goto bad_desc;
  1071. }
  1072. info->u = (void *) buf;
  1073. if (info->u->bLength != sizeof *info->u) {
  1074. dev_dbg (&intf->dev, "CDC union len %u\n",
  1075. info->u->bLength);
  1076. goto bad_desc;
  1077. }
  1078. /* we need a master/control interface (what we're
  1079. * probed with) and a slave/data interface; union
  1080. * descriptors sort this all out.
  1081. */
  1082. info->control = usb_ifnum_to_if(dev->udev,
  1083. info->u->bMasterInterface0);
  1084. info->data = usb_ifnum_to_if(dev->udev,
  1085. info->u->bSlaveInterface0);
  1086. if (!info->control || !info->data) {
  1087. dev_dbg (&intf->dev,
  1088. "master #%u/%p slave #%u/%p\n",
  1089. info->u->bMasterInterface0,
  1090. info->control,
  1091. info->u->bSlaveInterface0,
  1092. info->data);
  1093. goto bad_desc;
  1094. }
  1095. if (info->control != intf) {
  1096. dev_dbg (&intf->dev, "bogus CDC Union\n");
  1097. /* Ambit USB Cable Modem (and maybe others)
  1098. * interchanges master and slave interface.
  1099. */
  1100. if (info->data == intf) {
  1101. info->data = info->control;
  1102. info->control = intf;
  1103. } else
  1104. goto bad_desc;
  1105. }
  1106. /* a data interface altsetting does the real i/o */
  1107. d = &info->data->cur_altsetting->desc;
  1108. if (d->bInterfaceClass != USB_CLASS_CDC_DATA) {
  1109. dev_dbg (&intf->dev, "slave class %u\n",
  1110. d->bInterfaceClass);
  1111. goto bad_desc;
  1112. }
  1113. break;
  1114. case USB_CDC_ETHERNET_TYPE:
  1115. if (info->ether) {
  1116. dev_dbg (&intf->dev, "extra CDC ether\n");
  1117. goto bad_desc;
  1118. }
  1119. info->ether = (void *) buf;
  1120. if (info->ether->bLength != sizeof *info->ether) {
  1121. dev_dbg (&intf->dev, "CDC ether len %u\n",
  1122. info->ether->bLength);
  1123. goto bad_desc;
  1124. }
  1125. dev->hard_mtu = le16_to_cpu(
  1126. info->ether->wMaxSegmentSize);
  1127. /* because of Zaurus, we may be ignoring the host
  1128. * side link address we were given.
  1129. */
  1130. break;
  1131. }
  1132. next_desc:
  1133. len -= buf [0]; /* bLength */
  1134. buf += buf [0];
  1135. }
  1136. if (!info->header || !info->u || (!rndis && !info->ether)) {
  1137. dev_dbg (&intf->dev, "missing cdc %s%s%sdescriptor\n",
  1138. info->header ? "" : "header ",
  1139. info->u ? "" : "union ",
  1140. info->ether ? "" : "ether ");
  1141. goto bad_desc;
  1142. }
  1143. /* claim data interface and set it up ... with side effects.
  1144. * network traffic can't flow until an altsetting is enabled.
  1145. */
  1146. status = usb_driver_claim_interface (&usbnet_driver, info->data, dev);
  1147. if (status < 0)
  1148. return status;
  1149. status = get_endpoints (dev, info->data);
  1150. if (status < 0) {
  1151. /* ensure immediate exit from usbnet_disconnect */
  1152. usb_set_intfdata(info->data, NULL);
  1153. usb_driver_release_interface (&usbnet_driver, info->data);
  1154. return status;
  1155. }
  1156. /* status endpoint: optional for CDC Ethernet, not RNDIS (or ACM) */
  1157. dev->status = NULL;
  1158. if (info->control->cur_altsetting->desc.bNumEndpoints == 1) {
  1159. struct usb_endpoint_descriptor *desc;
  1160. dev->status = &info->control->cur_altsetting->endpoint [0];
  1161. desc = &dev->status->desc;
  1162. if (desc->bmAttributes != USB_ENDPOINT_XFER_INT
  1163. || !(desc->bEndpointAddress & USB_DIR_IN)
  1164. || (le16_to_cpu(desc->wMaxPacketSize)
  1165. < sizeof (struct usb_cdc_notification))
  1166. || !desc->bInterval) {
  1167. dev_dbg (&intf->dev, "bad notification endpoint\n");
  1168. dev->status = NULL;
  1169. }
  1170. }
  1171. if (rndis && !dev->status) {
  1172. dev_dbg (&intf->dev, "missing RNDIS status endpoint\n");
  1173. usb_set_intfdata(info->data, NULL);
  1174. usb_driver_release_interface (&usbnet_driver, info->data);
  1175. return -ENODEV;
  1176. }
  1177. return 0;
  1178. bad_desc:
  1179. dev_info (&dev->udev->dev, "bad CDC descriptors\n");
  1180. return -ENODEV;
  1181. }
  1182. static void cdc_unbind (struct usbnet *dev, struct usb_interface *intf)
  1183. {
  1184. struct cdc_state *info = (void *) &dev->data;
  1185. /* disconnect master --> disconnect slave */
  1186. if (intf == info->control && info->data) {
  1187. /* ensure immediate exit from usbnet_disconnect */
  1188. usb_set_intfdata(info->data, NULL);
  1189. usb_driver_release_interface (&usbnet_driver, info->data);
  1190. info->data = NULL;
  1191. }
  1192. /* and vice versa (just in case) */
  1193. else if (intf == info->data && info->control) {
  1194. /* ensure immediate exit from usbnet_disconnect */
  1195. usb_set_intfdata(info->control, NULL);
  1196. usb_driver_release_interface (&usbnet_driver, info->control);
  1197. info->control = NULL;
  1198. }
  1199. }
  1200. #endif /* NEED_GENERIC_CDC */
  1201. #ifdef CONFIG_USB_CDCETHER
  1202. #define HAVE_HARDWARE
  1203. /*-------------------------------------------------------------------------
  1204. *
  1205. * Communications Device Class, Ethernet Control model
  1206. *
  1207. * Takes two interfaces. The DATA interface is inactive till an altsetting
  1208. * is selected. Configuration data includes class descriptors.
  1209. *
  1210. * This should interop with whatever the 2.4 "CDCEther.c" driver
  1211. * (by Brad Hards) talked with.
  1212. *
  1213. *-------------------------------------------------------------------------*/
  1214. #include <linux/ctype.h>
  1215. static void dumpspeed (struct usbnet *dev, __le32 *speeds)
  1216. {
  1217. if (netif_msg_timer (dev))
  1218. devinfo (dev, "link speeds: %u kbps up, %u kbps down",
  1219. __le32_to_cpu(speeds[0]) / 1000,
  1220. __le32_to_cpu(speeds[1]) / 1000);
  1221. }
  1222. static void cdc_status (struct usbnet *dev, struct urb *urb)
  1223. {
  1224. struct usb_cdc_notification *event;
  1225. if (urb->actual_length < sizeof *event)
  1226. return;
  1227. /* SPEED_CHANGE can get split into two 8-byte packets */
  1228. if (test_and_clear_bit (EVENT_STS_SPLIT, &dev->flags)) {
  1229. dumpspeed (dev, (__le32 *) urb->transfer_buffer);
  1230. return;
  1231. }
  1232. event = urb->transfer_buffer;
  1233. switch (event->bNotificationType) {
  1234. case USB_CDC_NOTIFY_NETWORK_CONNECTION:
  1235. if (netif_msg_timer (dev))
  1236. devdbg (dev, "CDC: carrier %s",
  1237. event->wValue ? "on" : "off");
  1238. if (event->wValue)
  1239. netif_carrier_on(dev->net);
  1240. else
  1241. netif_carrier_off(dev->net);
  1242. break;
  1243. case USB_CDC_NOTIFY_SPEED_CHANGE: /* tx/rx rates */
  1244. if (netif_msg_timer (dev))
  1245. devdbg (dev, "CDC: speed change (len %d)",
  1246. urb->actual_length);
  1247. if (urb->actual_length != (sizeof *event + 8))
  1248. set_bit (EVENT_STS_SPLIT, &dev->flags);
  1249. else
  1250. dumpspeed (dev, (__le32 *) &event[1]);
  1251. break;
  1252. // case USB_CDC_NOTIFY_RESPONSE_AVAILABLE: /* RNDIS; or unsolicited */
  1253. default:
  1254. deverr (dev, "CDC: unexpected notification %02x!",
  1255. event->bNotificationType);
  1256. break;
  1257. }
  1258. }
  1259. static u8 nibble (unsigned char c)
  1260. {
  1261. if (likely (isdigit (c)))
  1262. return c - '0';
  1263. c = toupper (c);
  1264. if (likely (isxdigit (c)))
  1265. return 10 + c - 'A';
  1266. return 0;
  1267. }
  1268. static inline int
  1269. get_ethernet_addr (struct usbnet *dev, struct usb_cdc_ether_desc *e)
  1270. {
  1271. int tmp, i;
  1272. unsigned char buf [13];
  1273. tmp = usb_string (dev->udev, e->iMACAddress, buf, sizeof buf);
  1274. if (tmp != 12) {
  1275. dev_dbg (&dev->udev->dev,
  1276. "bad MAC string %d fetch, %d\n", e->iMACAddress, tmp);
  1277. if (tmp >= 0)
  1278. tmp = -EINVAL;
  1279. return tmp;
  1280. }
  1281. for (i = tmp = 0; i < 6; i++, tmp += 2)
  1282. dev->net->dev_addr [i] =
  1283. (nibble (buf [tmp]) << 4) + nibble (buf [tmp + 1]);
  1284. return 0;
  1285. }
  1286. static int cdc_bind (struct usbnet *dev, struct usb_interface *intf)
  1287. {
  1288. int status;
  1289. struct cdc_state *info = (void *) &dev->data;
  1290. status = generic_cdc_bind (dev, intf);
  1291. if (status < 0)
  1292. return status;
  1293. status = get_ethernet_addr (dev, info->ether);
  1294. if (status < 0) {
  1295. usb_set_intfdata(info->data, NULL);
  1296. usb_driver_release_interface (&usbnet_driver, info->data);
  1297. return status;
  1298. }
  1299. /* FIXME cdc-ether has some multicast code too, though it complains
  1300. * in routine cases. info->ether describes the multicast support.
  1301. */
  1302. return 0;
  1303. }
  1304. static const struct driver_info cdc_info = {
  1305. .description = "CDC Ethernet Device",
  1306. .flags = FLAG_ETHER,
  1307. // .check_connect = cdc_check_connect,
  1308. .bind = cdc_bind,
  1309. .unbind = cdc_unbind,
  1310. .status = cdc_status,
  1311. };
  1312. #endif /* CONFIG_USB_CDCETHER */
  1313. #ifdef CONFIG_USB_EPSON2888
  1314. #define HAVE_HARDWARE
  1315. /*-------------------------------------------------------------------------
  1316. *
  1317. * EPSON USB clients
  1318. *
  1319. * This is the same idea as Linux PDAs (below) except the firmware in the
  1320. * device might not be Tux-powered. Epson provides reference firmware that
  1321. * implements this interface. Product developers can reuse or modify that
  1322. * code, such as by using their own product and vendor codes.
  1323. *
  1324. * Support was from Juro Bystricky <bystricky.juro@erd.epson.com>
  1325. *
  1326. *-------------------------------------------------------------------------*/
  1327. static const struct driver_info epson2888_info = {
  1328. .description = "Epson USB Device",
  1329. .check_connect = always_connected,
  1330. .in = 4, .out = 3,
  1331. };
  1332. #endif /* CONFIG_USB_EPSON2888 */
  1333. #ifdef CONFIG_USB_GENESYS
  1334. #define HAVE_HARDWARE
  1335. /*-------------------------------------------------------------------------
  1336. *
  1337. * GeneSys GL620USB-A (www.genesyslogic.com.tw)
  1338. *
  1339. * ... should partially interop with the Win32 driver for this hardware
  1340. * The GeneSys docs imply there's some NDIS issue motivating this framing.
  1341. *
  1342. * Some info from GeneSys:
  1343. * - GL620USB-A is full duplex; GL620USB is only half duplex for bulk.
  1344. * (Some cables, like the BAFO-100c, use the half duplex version.)
  1345. * - For the full duplex model, the low bit of the version code says
  1346. * which side is which ("left/right").
  1347. * - For the half duplex type, a control/interrupt handshake settles
  1348. * the transfer direction. (That's disabled here, partially coded.)
  1349. * A control URB would block until other side writes an interrupt.
  1350. *
  1351. * Original code from Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
  1352. * and merged into "usbnet" by Stanislav Brabec <utx@penguin.cz>.
  1353. *
  1354. *-------------------------------------------------------------------------*/
  1355. // control msg write command
  1356. #define GENELINK_CONNECT_WRITE 0xF0
  1357. // interrupt pipe index
  1358. #define GENELINK_INTERRUPT_PIPE 0x03
  1359. // interrupt read buffer size
  1360. #define INTERRUPT_BUFSIZE 0x08
  1361. // interrupt pipe interval value
  1362. #define GENELINK_INTERRUPT_INTERVAL 0x10
  1363. // max transmit packet number per transmit
  1364. #define GL_MAX_TRANSMIT_PACKETS 32
  1365. // max packet length
  1366. #define GL_MAX_PACKET_LEN 1514
  1367. // max receive buffer size
  1368. #define GL_RCV_BUF_SIZE \
  1369. (((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4)
  1370. struct gl_packet {
  1371. u32 packet_length;
  1372. char packet_data [1];
  1373. };
  1374. struct gl_header {
  1375. u32 packet_count;
  1376. struct gl_packet packets;
  1377. };
  1378. #ifdef GENELINK_ACK
  1379. // FIXME: this code is incomplete, not debugged; it doesn't
  1380. // handle interrupts correctly. interrupts should be generic
  1381. // code like all other device I/O, anyway.
  1382. struct gl_priv {
  1383. struct urb *irq_urb;
  1384. char irq_buf [INTERRUPT_BUFSIZE];
  1385. };
  1386. static inline int gl_control_write (struct usbnet *dev, u8 request, u16 value)
  1387. {
  1388. int retval;
  1389. retval = usb_control_msg (dev->udev,
  1390. usb_sndctrlpipe (dev->udev, 0),
  1391. request,
  1392. USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  1393. value,
  1394. 0, // index
  1395. 0, // data buffer
  1396. 0, // size
  1397. CONTROL_TIMEOUT_MS);
  1398. return retval;
  1399. }
  1400. static void gl_interrupt_complete (struct urb *urb, struct pt_regs *regs)
  1401. {
  1402. int status = urb->status;
  1403. switch (status) {
  1404. case 0:
  1405. /* success */
  1406. break;
  1407. case -ECONNRESET:
  1408. case -ENOENT:
  1409. case -ESHUTDOWN:
  1410. /* this urb is terminated, clean up */
  1411. dbg("%s - urb shutting down with status: %d",
  1412. __FUNCTION__, status);
  1413. return;
  1414. default:
  1415. dbg("%s - nonzero urb status received: %d",
  1416. __FUNCTION__, urb->status);
  1417. }
  1418. status = usb_submit_urb (urb, GFP_ATOMIC);
  1419. if (status)
  1420. err ("%s - usb_submit_urb failed with result %d",
  1421. __FUNCTION__, status);
  1422. }
  1423. static int gl_interrupt_read (struct usbnet *dev)
  1424. {
  1425. struct gl_priv *priv = dev->priv_data;
  1426. int retval;
  1427. // issue usb interrupt read
  1428. if (priv && priv->irq_urb) {
  1429. // submit urb
  1430. if ((retval = usb_submit_urb (priv->irq_urb, GFP_KERNEL)) != 0)
  1431. dbg ("gl_interrupt_read: submit fail - %X...", retval);
  1432. else
  1433. dbg ("gl_interrupt_read: submit success...");
  1434. }
  1435. return 0;
  1436. }
  1437. // check whether another side is connected
  1438. static int genelink_check_connect (struct usbnet *dev)
  1439. {
  1440. int retval;
  1441. dbg ("genelink_check_connect...");
  1442. // detect whether another side is connected
  1443. if ((retval = gl_control_write (dev, GENELINK_CONNECT_WRITE, 0)) != 0) {
  1444. dbg ("%s: genelink_check_connect write fail - %X",
  1445. dev->net->name, retval);
  1446. return retval;
  1447. }
  1448. // usb interrupt read to ack another side
  1449. if ((retval = gl_interrupt_read (dev)) != 0) {
  1450. dbg ("%s: genelink_check_connect read fail - %X",
  1451. dev->net->name, retval);
  1452. return retval;
  1453. }
  1454. dbg ("%s: genelink_check_connect read success", dev->net->name);
  1455. return 0;
  1456. }
  1457. // allocate and initialize the private data for genelink
  1458. static int genelink_init (struct usbnet *dev)
  1459. {
  1460. struct gl_priv *priv;
  1461. // allocate the private data structure
  1462. if ((priv = kmalloc (sizeof *priv, GFP_KERNEL)) == 0) {
  1463. dbg ("%s: cannot allocate private data per device",
  1464. dev->net->name);
  1465. return -ENOMEM;
  1466. }
  1467. // allocate irq urb
  1468. if ((priv->irq_urb = usb_alloc_urb (0, GFP_KERNEL)) == 0) {
  1469. dbg ("%s: cannot allocate private irq urb per device",
  1470. dev->net->name);
  1471. kfree (priv);
  1472. return -ENOMEM;
  1473. }
  1474. // fill irq urb
  1475. usb_fill_int_urb (priv->irq_urb, dev->udev,
  1476. usb_rcvintpipe (dev->udev, GENELINK_INTERRUPT_PIPE),
  1477. priv->irq_buf, INTERRUPT_BUFSIZE,
  1478. gl_interrupt_complete, 0,
  1479. GENELINK_INTERRUPT_INTERVAL);
  1480. // set private data pointer
  1481. dev->priv_data = priv;
  1482. return 0;
  1483. }
  1484. // release the private data
  1485. static int genelink_free (struct usbnet *dev)
  1486. {
  1487. struct gl_priv *priv = dev->priv_data;
  1488. if (!priv)
  1489. return 0;
  1490. // FIXME: can't cancel here; it's synchronous, and
  1491. // should have happened earlier in any case (interrupt
  1492. // handling needs to be generic)
  1493. // cancel irq urb first
  1494. usb_kill_urb (priv->irq_urb);
  1495. // free irq urb
  1496. usb_free_urb (priv->irq_urb);
  1497. // free the private data structure
  1498. kfree (priv);
  1499. return 0;
  1500. }
  1501. #endif
  1502. static int genelink_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
  1503. {
  1504. struct gl_header *header;
  1505. struct gl_packet *packet;
  1506. struct sk_buff *gl_skb;
  1507. u32 size;
  1508. header = (struct gl_header *) skb->data;
  1509. // get the packet count of the received skb
  1510. le32_to_cpus (&header->packet_count);
  1511. if ((header->packet_count > GL_MAX_TRANSMIT_PACKETS)
  1512. || (header->packet_count < 0)) {
  1513. dbg ("genelink: invalid received packet count %d",
  1514. header->packet_count);
  1515. return 0;
  1516. }
  1517. // set the current packet pointer to the first packet
  1518. packet = &header->packets;
  1519. // decrement the length for the packet count size 4 bytes
  1520. skb_pull (skb, 4);
  1521. while (header->packet_count > 1) {
  1522. // get the packet length
  1523. size = packet->packet_length;
  1524. // this may be a broken packet
  1525. if (size > GL_MAX_PACKET_LEN) {
  1526. dbg ("genelink: invalid rx length %d", size);
  1527. return 0;
  1528. }
  1529. // allocate the skb for the individual packet
  1530. gl_skb = alloc_skb (size, GFP_ATOMIC);
  1531. if (gl_skb) {
  1532. // copy the packet data to the new skb
  1533. memcpy(skb_put(gl_skb, size), packet->packet_data, size);
  1534. skb_return (dev, gl_skb);
  1535. }
  1536. // advance to the next packet
  1537. packet = (struct gl_packet *)
  1538. &packet->packet_data [size];
  1539. header->packet_count--;
  1540. // shift the data pointer to the next gl_packet
  1541. skb_pull (skb, size + 4);
  1542. }
  1543. // skip the packet length field 4 bytes
  1544. skb_pull (skb, 4);
  1545. if (skb->len > GL_MAX_PACKET_LEN) {
  1546. dbg ("genelink: invalid rx length %d", skb->len);
  1547. return 0;
  1548. }
  1549. return 1;
  1550. }
  1551. static struct sk_buff *
  1552. genelink_tx_fixup (struct usbnet *dev, struct sk_buff *skb, unsigned flags)
  1553. {
  1554. int padlen;
  1555. int length = skb->len;
  1556. int headroom = skb_headroom (skb);
  1557. int tailroom = skb_tailroom (skb);
  1558. u32 *packet_count;
  1559. u32 *packet_len;
  1560. // FIXME: magic numbers, bleech
  1561. padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1;
  1562. if ((!skb_cloned (skb))
  1563. && ((headroom + tailroom) >= (padlen + (4 + 4*1)))) {
  1564. if ((headroom < (4 + 4*1)) || (tailroom < padlen)) {
  1565. skb->data = memmove (skb->head + (4 + 4*1),
  1566. skb->data, skb->len);
  1567. skb->tail = skb->data + skb->len;
  1568. }
  1569. } else {
  1570. struct sk_buff *skb2;
  1571. skb2 = skb_copy_expand (skb, (4 + 4*1) , padlen, flags);
  1572. dev_kfree_skb_any (skb);
  1573. skb = skb2;
  1574. if (!skb)
  1575. return NULL;
  1576. }
  1577. // attach the packet count to the header
  1578. packet_count = (u32 *) skb_push (skb, (4 + 4*1));
  1579. packet_len = packet_count + 1;
  1580. // FIXME little endian?
  1581. *packet_count = 1;
  1582. *packet_len = length;
  1583. // add padding byte
  1584. if ((skb->len % dev->maxpacket) == 0)
  1585. skb_put (skb, 1);
  1586. return skb;
  1587. }
  1588. static int genelink_bind (struct usbnet *dev, struct usb_interface *intf)
  1589. {
  1590. dev->hard_mtu = GL_RCV_BUF_SIZE;
  1591. dev->net->hard_header_len += 4;
  1592. return 0;
  1593. }
  1594. static const struct driver_info genelink_info = {
  1595. .description = "Genesys GeneLink",
  1596. .flags = FLAG_FRAMING_GL | FLAG_NO_SETINT,
  1597. .bind = genelink_bind,
  1598. .rx_fixup = genelink_rx_fixup,
  1599. .tx_fixup = genelink_tx_fixup,
  1600. .in = 1, .out = 2,
  1601. #ifdef GENELINK_ACK
  1602. .check_connect =genelink_check_connect,
  1603. #endif
  1604. };
  1605. #endif /* CONFIG_USB_GENESYS */
  1606. #ifdef CONFIG_USB_NET1080
  1607. #define HAVE_HARDWARE
  1608. /*-------------------------------------------------------------------------
  1609. *
  1610. * Netchip 1080 driver ... http://www.netchip.com
  1611. * Used in LapLink cables
  1612. *
  1613. *-------------------------------------------------------------------------*/
  1614. #define frame_errors data[1]
  1615. /*
  1616. * NetChip framing of ethernet packets, supporting additional error
  1617. * checks for links that may drop bulk packets from inside messages.
  1618. * Odd USB length == always short read for last usb packet.
  1619. * - nc_header
  1620. * - Ethernet header (14 bytes)
  1621. * - payload
  1622. * - (optional padding byte, if needed so length becomes odd)
  1623. * - nc_trailer
  1624. *
  1625. * This framing is to be avoided for non-NetChip devices.
  1626. */
  1627. struct nc_header { // packed:
  1628. __le16 hdr_len; // sizeof nc_header (LE, all)
  1629. __le16 packet_len; // payload size (including ethhdr)
  1630. __le16 packet_id; // detects dropped packets
  1631. #define MIN_HEADER 6
  1632. // all else is optional, and must start with:
  1633. // u16 vendorId; // from usb-if
  1634. // u16 productId;
  1635. } __attribute__((__packed__));
  1636. #define PAD_BYTE ((unsigned char)0xAC)
  1637. struct nc_trailer {
  1638. __le16 packet_id;
  1639. } __attribute__((__packed__));
  1640. // packets may use FLAG_FRAMING_NC and optional pad
  1641. #define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \
  1642. + sizeof (struct ethhdr) \
  1643. + (mtu) \
  1644. + 1 \
  1645. + sizeof (struct nc_trailer))
  1646. #define MIN_FRAMED FRAMED_SIZE(0)
  1647. /* packets _could_ be up to 64KB... */
  1648. #define NC_MAX_PACKET 32767
  1649. /*
  1650. * Zero means no timeout; else, how long a 64 byte bulk packet may be queued
  1651. * before the hardware drops it. If that's done, the driver will need to
  1652. * frame network packets to guard against the dropped USB packets. The win32
  1653. * driver sets this for both sides of the link.
  1654. */
  1655. #define NC_READ_TTL_MS ((u8)255) // ms
  1656. /*
  1657. * We ignore most registers and EEPROM contents.
  1658. */
  1659. #define REG_USBCTL ((u8)0x04)
  1660. #define REG_TTL ((u8)0x10)
  1661. #define REG_STATUS ((u8)0x11)
  1662. /*
  1663. * Vendor specific requests to read/write data
  1664. */
  1665. #define REQUEST_REGISTER ((u8)0x10)
  1666. #define REQUEST_EEPROM ((u8)0x11)
  1667. static int
  1668. nc_vendor_read (struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr)
  1669. {
  1670. int status = usb_control_msg (dev->udev,
  1671. usb_rcvctrlpipe (dev->udev, 0),
  1672. req,
  1673. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  1674. 0, regnum,
  1675. retval_ptr, sizeof *retval_ptr,
  1676. CONTROL_TIMEOUT_MS);
  1677. if (status > 0)
  1678. status = 0;
  1679. if (!status)
  1680. le16_to_cpus (retval_ptr);
  1681. return status;
  1682. }
  1683. static inline int
  1684. nc_register_read (struct usbnet *dev, u8 regnum, u16 *retval_ptr)
  1685. {
  1686. return nc_vendor_read (dev, REQUEST_REGISTER, regnum, retval_ptr);
  1687. }
  1688. // no retval ... can become async, usable in_interrupt()
  1689. static void
  1690. nc_vendor_write (struct usbnet *dev, u8 req, u8 regnum, u16 value)
  1691. {
  1692. usb_control_msg (dev->udev,
  1693. usb_sndctrlpipe (dev->udev, 0),
  1694. req,
  1695. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  1696. value, regnum,
  1697. NULL, 0, // data is in setup packet
  1698. CONTROL_TIMEOUT_MS);
  1699. }
  1700. static inline void
  1701. nc_register_write (struct usbnet *dev, u8 regnum, u16 value)
  1702. {
  1703. nc_vendor_write (dev, REQUEST_REGISTER, regnum, value);
  1704. }
  1705. #if 0
  1706. static void nc_dump_registers (struct usbnet *dev)
  1707. {
  1708. u8 reg;
  1709. u16 *vp = kmalloc (sizeof (u16));
  1710. if (!vp) {
  1711. dbg ("no memory?");
  1712. return;
  1713. }
  1714. dbg ("%s registers:", dev->net->name);
  1715. for (reg = 0; reg < 0x20; reg++) {
  1716. int retval;
  1717. // reading some registers is trouble
  1718. if (reg >= 0x08 && reg <= 0xf)
  1719. continue;
  1720. if (reg >= 0x12 && reg <= 0x1e)
  1721. continue;
  1722. retval = nc_register_read (dev, reg, vp);
  1723. if (retval < 0)
  1724. dbg ("%s reg [0x%x] ==> error %d",
  1725. dev->net->name, reg, retval);
  1726. else
  1727. dbg ("%s reg [0x%x] = 0x%x",
  1728. dev->net->name, reg, *vp);
  1729. }
  1730. kfree (vp);
  1731. }
  1732. #endif
  1733. /*-------------------------------------------------------------------------*/
  1734. /*
  1735. * Control register
  1736. */
  1737. #define USBCTL_WRITABLE_MASK 0x1f0f
  1738. // bits 15-13 reserved, r/o
  1739. #define USBCTL_ENABLE_LANG (1 << 12)
  1740. #define USBCTL_ENABLE_MFGR (1 << 11)
  1741. #define USBCTL_ENABLE_PROD (1 << 10)
  1742. #define USBCTL_ENABLE_SERIAL (1 << 9)
  1743. #define USBCTL_ENABLE_DEFAULTS (1 << 8)
  1744. // bits 7-4 reserved, r/o
  1745. #define USBCTL_FLUSH_OTHER (1 << 3)
  1746. #define USBCTL_FLUSH_THIS (1 << 2)
  1747. #define USBCTL_DISCONN_OTHER (1 << 1)
  1748. #define USBCTL_DISCONN_THIS (1 << 0)
  1749. static inline void nc_dump_usbctl (struct usbnet *dev, u16 usbctl)
  1750. {
  1751. if (!netif_msg_link (dev))
  1752. return;
  1753. devdbg (dev, "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s;"
  1754. " this%s%s;"
  1755. " other%s%s; r/o 0x%x",
  1756. dev->udev->bus->bus_name, dev->udev->devpath,
  1757. usbctl,
  1758. (usbctl & USBCTL_ENABLE_LANG) ? " lang" : "",
  1759. (usbctl & USBCTL_ENABLE_MFGR) ? " mfgr" : "",
  1760. (usbctl & USBCTL_ENABLE_PROD) ? " prod" : "",
  1761. (usbctl & USBCTL_ENABLE_SERIAL) ? " serial" : "",
  1762. (usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "",
  1763. (usbctl & USBCTL_FLUSH_OTHER) ? " FLUSH" : "",
  1764. (usbctl & USBCTL_DISCONN_OTHER) ? " DIS" : "",
  1765. (usbctl & USBCTL_FLUSH_THIS) ? " FLUSH" : "",
  1766. (usbctl & USBCTL_DISCONN_THIS) ? " DIS" : "",
  1767. usbctl & ~USBCTL_WRITABLE_MASK
  1768. );
  1769. }
  1770. /*-------------------------------------------------------------------------*/
  1771. /*
  1772. * Status register
  1773. */
  1774. #define STATUS_PORT_A (1 << 15)
  1775. #define STATUS_CONN_OTHER (1 << 14)
  1776. #define STATUS_SUSPEND_OTHER (1 << 13)
  1777. #define STATUS_MAILBOX_OTHER (1 << 12)
  1778. #define STATUS_PACKETS_OTHER(n) (((n) >> 8) && 0x03)
  1779. #define STATUS_CONN_THIS (1 << 6)
  1780. #define STATUS_SUSPEND_THIS (1 << 5)
  1781. #define STATUS_MAILBOX_THIS (1 << 4)
  1782. #define STATUS_PACKETS_THIS(n) (((n) >> 0) && 0x03)
  1783. #define STATUS_UNSPEC_MASK 0x0c8c
  1784. #define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK))
  1785. static inline void nc_dump_status (struct usbnet *dev, u16 status)
  1786. {
  1787. if (!netif_msg_link (dev))
  1788. return;
  1789. devdbg (dev, "net1080 %s-%s status 0x%x:"
  1790. " this (%c) PKT=%d%s%s%s;"
  1791. " other PKT=%d%s%s%s; unspec 0x%x",
  1792. dev->udev->bus->bus_name, dev->udev->devpath,
  1793. status,
  1794. // XXX the packet counts don't seem right
  1795. // (1 at reset, not 0); maybe UNSPEC too
  1796. (status & STATUS_PORT_A) ? 'A' : 'B',
  1797. STATUS_PACKETS_THIS (status),
  1798. (status & STATUS_CONN_THIS) ? " CON" : "",
  1799. (status & STATUS_SUSPEND_THIS) ? " SUS" : "",
  1800. (status & STATUS_MAILBOX_THIS) ? " MBOX" : "",
  1801. STATUS_PACKETS_OTHER (status),
  1802. (status & STATUS_CONN_OTHER) ? " CON" : "",
  1803. (status & STATUS_SUSPEND_OTHER) ? " SUS" : "",
  1804. (status & STATUS_MAILBOX_OTHER) ? " MBOX" : "",
  1805. status & STATUS_UNSPEC_MASK
  1806. );
  1807. }
  1808. /*-------------------------------------------------------------------------*/
  1809. /*
  1810. * TTL register
  1811. */
  1812. #define TTL_THIS(ttl) (0x00ff & ttl)
  1813. #define TTL_OTHER(ttl) (0x00ff & (ttl >> 8))
  1814. #define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this))))
  1815. static inline void nc_dump_ttl (struct usbnet *dev, u16 ttl)
  1816. {
  1817. if (netif_msg_link (dev))
  1818. devdbg (dev, "net1080 %s-%s ttl 0x%x this = %d, other = %d",
  1819. dev->udev->bus->bus_name, dev->udev->devpath,
  1820. ttl, TTL_THIS (ttl), TTL_OTHER (ttl));
  1821. }
  1822. /*-------------------------------------------------------------------------*/
  1823. static int net1080_reset (struct usbnet *dev)
  1824. {
  1825. u16 usbctl, status, ttl;
  1826. u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL);
  1827. int retval;
  1828. if (!vp)
  1829. return -ENOMEM;
  1830. // nc_dump_registers (dev);
  1831. if ((retval = nc_register_read (dev, REG_STATUS, vp)) < 0) {
  1832. dbg ("can't read %s-%s status: %d",
  1833. dev->udev->bus->bus_name, dev->udev->devpath, retval);
  1834. goto done;
  1835. }
  1836. status = *vp;
  1837. nc_dump_status (dev, status);
  1838. if ((retval = nc_register_read (dev, REG_USBCTL, vp)) < 0) {
  1839. dbg ("can't read USBCTL, %d", retval);
  1840. goto done;
  1841. }
  1842. usbctl = *vp;
  1843. nc_dump_usbctl (dev, usbctl);
  1844. nc_register_write (dev, REG_USBCTL,
  1845. USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER);
  1846. if ((retval = nc_register_read (dev, REG_TTL, vp)) < 0) {
  1847. dbg ("can't read TTL, %d", retval);
  1848. goto done;
  1849. }
  1850. ttl = *vp;
  1851. // nc_dump_ttl (dev, ttl);
  1852. nc_register_write (dev, REG_TTL,
  1853. MK_TTL (NC_READ_TTL_MS, TTL_OTHER (ttl)) );
  1854. dbg ("%s: assigned TTL, %d ms", dev->net->name, NC_READ_TTL_MS);
  1855. if (netif_msg_link (dev))
  1856. devinfo (dev, "port %c, peer %sconnected",
  1857. (status & STATUS_PORT_A) ? 'A' : 'B',
  1858. (status & STATUS_CONN_OTHER) ? "" : "dis"
  1859. );
  1860. retval = 0;
  1861. done:
  1862. kfree (vp);
  1863. return retval;
  1864. }
  1865. static int net1080_check_connect (struct usbnet *dev)
  1866. {
  1867. int retval;
  1868. u16 status;
  1869. u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL);
  1870. if (!vp)
  1871. return -ENOMEM;
  1872. retval = nc_register_read (dev, REG_STATUS, vp);
  1873. status = *vp;
  1874. kfree (vp);
  1875. if (retval != 0) {
  1876. dbg ("%s net1080_check_conn read - %d", dev->net->name, retval);
  1877. return retval;
  1878. }
  1879. if ((status & STATUS_CONN_OTHER) != STATUS_CONN_OTHER)
  1880. return -ENOLINK;
  1881. return 0;
  1882. }
  1883. static void nc_flush_complete (struct urb *urb, struct pt_regs *regs)
  1884. {
  1885. kfree (urb->context);
  1886. usb_free_urb(urb);
  1887. }
  1888. static void nc_ensure_sync (struct usbnet *dev)
  1889. {
  1890. dev->frame_errors++;
  1891. if (dev->frame_errors > 5) {
  1892. struct urb *urb;
  1893. struct usb_ctrlrequest *req;
  1894. int status;
  1895. /* Send a flush */
  1896. urb = usb_alloc_urb (0, SLAB_ATOMIC);
  1897. if (!urb)
  1898. return;
  1899. req = kmalloc (sizeof *req, GFP_ATOMIC);
  1900. if (!req) {
  1901. usb_free_urb (urb);
  1902. return;
  1903. }
  1904. req->bRequestType = USB_DIR_OUT
  1905. | USB_TYPE_VENDOR
  1906. | USB_RECIP_DEVICE;
  1907. req->bRequest = REQUEST_REGISTER;
  1908. req->wValue = cpu_to_le16 (USBCTL_FLUSH_THIS
  1909. | USBCTL_FLUSH_OTHER);
  1910. req->wIndex = cpu_to_le16 (REG_USBCTL);
  1911. req->wLength = cpu_to_le16 (0);
  1912. /* queue an async control request, we don't need
  1913. * to do anything when it finishes except clean up.
  1914. */
  1915. usb_fill_control_urb (urb, dev->udev,
  1916. usb_sndctrlpipe (dev->udev, 0),
  1917. (unsigned char *) req,
  1918. NULL, 0,
  1919. nc_flush_complete, req);
  1920. status = usb_submit_urb (urb, GFP_ATOMIC);
  1921. if (status) {
  1922. kfree (req);
  1923. usb_free_urb (urb);
  1924. return;
  1925. }
  1926. if (netif_msg_rx_err (dev))
  1927. devdbg (dev, "flush net1080; too many framing errors");
  1928. dev->frame_errors = 0;
  1929. }
  1930. }
  1931. static int net1080_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
  1932. {
  1933. struct nc_header *header;
  1934. struct net_device *net = dev->net;
  1935. struct nc_trailer *trailer;
  1936. u16 hdr_len, packet_len;
  1937. if (!(skb->len & 0x01)) {
  1938. dev->stats.rx_frame_errors++;
  1939. dbg ("rx framesize %d range %d..%d mtu %d", skb->len,
  1940. net->hard_header_len, dev->hard_mtu, net->mtu);
  1941. nc_ensure_sync (dev);
  1942. return 0;
  1943. }
  1944. header = (struct nc_header *) skb->data;
  1945. hdr_len = le16_to_cpup (&header->hdr_len);
  1946. packet_len = le16_to_cpup (&header->packet_len);
  1947. if (FRAMED_SIZE (packet_len) > NC_MAX_PACKET) {
  1948. dev->stats.rx_frame_errors++;
  1949. dbg ("packet too big, %d", packet_len);
  1950. nc_ensure_sync (dev);
  1951. return 0;
  1952. } else if (hdr_len < MIN_HEADER) {
  1953. dev->stats.rx_frame_errors++;
  1954. dbg ("header too short, %d", hdr_len);
  1955. nc_ensure_sync (dev);
  1956. return 0;
  1957. } else if (hdr_len > MIN_HEADER) {
  1958. // out of band data for us?
  1959. dbg ("header OOB, %d bytes", hdr_len - MIN_HEADER);
  1960. nc_ensure_sync (dev);
  1961. // switch (vendor/product ids) { ... }
  1962. }
  1963. skb_pull (skb, hdr_len);
  1964. trailer = (struct nc_trailer *)
  1965. (skb->data + skb->len - sizeof *trailer);
  1966. skb_trim (skb, skb->len - sizeof *trailer);
  1967. if ((packet_len & 0x01) == 0) {
  1968. if (skb->data [packet_len] != PAD_BYTE) {
  1969. dev->stats.rx_frame_errors++;
  1970. dbg ("bad pad");
  1971. return 0;
  1972. }
  1973. skb_trim (skb, skb->len - 1);
  1974. }
  1975. if (skb->len != packet_len) {
  1976. dev->stats.rx_frame_errors++;
  1977. dbg ("bad packet len %d (expected %d)",
  1978. skb->len, packet_len);
  1979. nc_ensure_sync (dev);
  1980. return 0;
  1981. }
  1982. if (header->packet_id != get_unaligned (&trailer->packet_id)) {
  1983. dev->stats.rx_fifo_errors++;
  1984. dbg ("(2+ dropped) rx packet_id mismatch 0x%x 0x%x",
  1985. le16_to_cpu (header->packet_id),
  1986. le16_to_cpu (trailer->packet_id));
  1987. return 0;
  1988. }
  1989. #if 0
  1990. devdbg (dev, "frame <rx h %d p %d id %d", header->hdr_len,
  1991. header->packet_len, header->packet_id);
  1992. #endif
  1993. dev->frame_errors = 0;
  1994. return 1;
  1995. }
  1996. static struct sk_buff *
  1997. net1080_tx_fixup (struct usbnet *dev, struct sk_buff *skb, unsigned flags)
  1998. {
  1999. int padlen;
  2000. struct sk_buff *skb2;
  2001. padlen = ((skb->len + sizeof (struct nc_header)
  2002. + sizeof (struct nc_trailer)) & 0x01) ? 0 : 1;
  2003. if (!skb_cloned (skb)) {
  2004. int headroom = skb_headroom (skb);
  2005. int tailroom = skb_tailroom (skb);
  2006. if ((padlen + sizeof (struct nc_trailer)) <= tailroom
  2007. && sizeof (struct nc_header) <= headroom)
  2008. /* There's enough head and tail room */
  2009. return skb;
  2010. if ((sizeof (struct nc_header) + padlen
  2011. + sizeof (struct nc_trailer)) <
  2012. (headroom + tailroom)) {
  2013. /* There's enough total room, so just readjust */
  2014. skb->data = memmove (skb->head
  2015. + sizeof (struct nc_header),
  2016. skb->data, skb->len);
  2017. skb->tail = skb->data + skb->len;
  2018. return skb;
  2019. }
  2020. }
  2021. /* Create a new skb to use with the correct size */
  2022. skb2 = skb_copy_expand (skb,
  2023. sizeof (struct nc_header),
  2024. sizeof (struct nc_trailer) + padlen,
  2025. flags);
  2026. dev_kfree_skb_any (skb);
  2027. return skb2;
  2028. }
  2029. static int net1080_bind (struct usbnet *dev, struct usb_interface *intf)
  2030. {
  2031. unsigned extra = sizeof (struct nc_header)
  2032. + 1
  2033. + sizeof (struct nc_trailer);
  2034. dev->net->hard_header_len += extra;
  2035. dev->hard_mtu = NC_MAX_PACKET;
  2036. return 0;
  2037. }
  2038. static const struct driver_info net1080_info = {
  2039. .description = "NetChip TurboCONNECT",
  2040. .flags = FLAG_FRAMING_NC,
  2041. .bind = net1080_bind,
  2042. .reset = net1080_reset,
  2043. .check_connect = net1080_check_connect,
  2044. .rx_fixup = net1080_rx_fixup,
  2045. .tx_fixup = net1080_tx_fixup,
  2046. };
  2047. #endif /* CONFIG_USB_NET1080 */
  2048. #ifdef CONFIG_USB_PL2301
  2049. #define HAVE_HARDWARE
  2050. /*-------------------------------------------------------------------------
  2051. *
  2052. * Prolific PL-2301/PL-2302 driver ... http://www.prolifictech.com
  2053. *
  2054. * The protocol and handshaking used here should be bug-compatible
  2055. * with the Linux 2.2 "plusb" driver, by Deti Fliegl.
  2056. *
  2057. *-------------------------------------------------------------------------*/
  2058. /*
  2059. * Bits 0-4 can be used for software handshaking; they're set from
  2060. * one end, cleared from the other, "read" with the interrupt byte.
  2061. */
  2062. #define PL_S_EN (1<<7) /* (feature only) suspend enable */
  2063. /* reserved bit -- rx ready (6) ? */
  2064. #define PL_TX_READY (1<<5) /* (interrupt only) transmit ready */
  2065. #define PL_RESET_OUT (1<<4) /* reset output pipe */
  2066. #define PL_RESET_IN (1<<3) /* reset input pipe */
  2067. #define PL_TX_C (1<<2) /* transmission complete */
  2068. #define PL_TX_REQ (1<<1) /* transmission received */
  2069. #define PL_PEER_E (1<<0) /* peer exists */
  2070. static inline int
  2071. pl_vendor_req (struct usbnet *dev, u8 req, u8 val, u8 index)
  2072. {
  2073. return usb_control_msg (dev->udev,
  2074. usb_rcvctrlpipe (dev->udev, 0),
  2075. req,
  2076. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  2077. val, index,
  2078. NULL, 0,
  2079. CONTROL_TIMEOUT_MS);
  2080. }
  2081. static inline int
  2082. pl_clear_QuickLink_features (struct usbnet *dev, int val)
  2083. {
  2084. return pl_vendor_req (dev, 1, (u8) val, 0);
  2085. }
  2086. static inline int
  2087. pl_set_QuickLink_features (struct usbnet *dev, int val)
  2088. {
  2089. return pl_vendor_req (dev, 3, (u8) val, 0);
  2090. }
  2091. /*-------------------------------------------------------------------------*/
  2092. static int pl_reset (struct usbnet *dev)
  2093. {
  2094. /* some units seem to need this reset, others reject it utterly.
  2095. * FIXME be more like "naplink" or windows drivers.
  2096. */
  2097. (void) pl_set_QuickLink_features (dev,
  2098. PL_S_EN|PL_RESET_OUT|PL_RESET_IN|PL_PEER_E);
  2099. return 0;
  2100. }
  2101. static const struct driver_info prolific_info = {
  2102. .description = "Prolific PL-2301/PL-2302",
  2103. .flags = FLAG_NO_SETINT,
  2104. /* some PL-2302 versions seem to fail usb_set_interface() */
  2105. .reset = pl_reset,
  2106. };
  2107. #endif /* CONFIG_USB_PL2301 */
  2108. #ifdef CONFIG_USB_KC2190
  2109. #define HAVE_HARDWARE
  2110. static const struct driver_info kc2190_info = {
  2111. .description = "KC Technology KC-190",
  2112. };
  2113. #endif /* CONFIG_USB_KC2190 */
  2114. #ifdef CONFIG_USB_ARMLINUX
  2115. #define HAVE_HARDWARE
  2116. /*-------------------------------------------------------------------------
  2117. *
  2118. * Intel's SA-1100 chip integrates basic USB support, and is used
  2119. * in PDAs like some iPaqs, the Yopy, some Zaurus models, and more.
  2120. * When they run Linux, arch/arm/mach-sa1100/usb-eth.c may be used to
  2121. * network using minimal USB framing data.
  2122. *
  2123. * This describes the driver currently in standard ARM Linux kernels.
  2124. * The Zaurus uses a different driver (see later).
  2125. *
  2126. * PXA25x and PXA210 use XScale cores (ARM v5TE) with better USB support
  2127. * and different USB endpoint numbering than the SA1100 devices. The
  2128. * mach-pxa/usb-eth.c driver re-uses the device ids from mach-sa1100
  2129. * so we rely on the endpoint descriptors.
  2130. *
  2131. *-------------------------------------------------------------------------*/
  2132. static const struct driver_info linuxdev_info = {
  2133. .description = "Linux Device",
  2134. .check_connect = always_connected,
  2135. };
  2136. static const struct driver_info yopy_info = {
  2137. .description = "Yopy",
  2138. .check_connect = always_connected,
  2139. };
  2140. static const struct driver_info blob_info = {
  2141. .description = "Boot Loader OBject",
  2142. .check_connect = always_connected,
  2143. };
  2144. #endif /* CONFIG_USB_ARMLINUX */
  2145. #ifdef CONFIG_USB_ZAURUS
  2146. #define HAVE_HARDWARE
  2147. #include <linux/crc32.h>
  2148. /*-------------------------------------------------------------------------
  2149. *
  2150. * Zaurus is also a SA-1110 based PDA, but one using a different driver
  2151. * (and framing) for its USB slave/gadget controller than the case above.
  2152. *
  2153. * For the current version of that driver, the main way that framing is
  2154. * nonstandard (also from perspective of the CDC ethernet model!) is a
  2155. * crc32, added to help detect when some sa1100 usb-to-memory DMA errata
  2156. * haven't been fully worked around. Also, all Zaurii use the same
  2157. * default Ethernet address.
  2158. *
  2159. * PXA based models use the same framing, and also can't implement
  2160. * set_interface properly.
  2161. *
  2162. * All known Zaurii lie about their standards conformance. Most lie by
  2163. * saying they support CDC Ethernet. Some lie and say they support CDC
  2164. * MDLM (as if for access to cell phone modems). Someone, please beat
  2165. * on Sharp (and other such vendors) for a while with a cluestick.
  2166. *
  2167. *-------------------------------------------------------------------------*/
  2168. static struct sk_buff *
  2169. zaurus_tx_fixup (struct usbnet *dev, struct sk_buff *skb, unsigned flags)
  2170. {
  2171. int padlen;
  2172. struct sk_buff *skb2;
  2173. padlen = 2;
  2174. if (!skb_cloned (skb)) {
  2175. int tailroom = skb_tailroom (skb);
  2176. if ((padlen + 4) <= tailroom)
  2177. goto done;
  2178. }
  2179. skb2 = skb_copy_expand (skb, 0, 4 + padlen, flags);
  2180. dev_kfree_skb_any (skb);
  2181. skb = skb2;
  2182. if (skb) {
  2183. u32 fcs;
  2184. done:
  2185. fcs = crc32_le (~0, skb->data, skb->len);
  2186. fcs = ~fcs;
  2187. *skb_put (skb, 1) = fcs & 0xff;
  2188. *skb_put (skb, 1) = (fcs>> 8) & 0xff;
  2189. *skb_put (skb, 1) = (fcs>>16) & 0xff;
  2190. *skb_put (skb, 1) = (fcs>>24) & 0xff;
  2191. }
  2192. return skb;
  2193. }
  2194. static int zaurus_bind (struct usbnet *dev, struct usb_interface *intf)
  2195. {
  2196. /* Belcarra's funky framing has other options; mostly
  2197. * TRAILERS (!) with 4 bytes CRC, and maybe 2 pad bytes.
  2198. */
  2199. dev->net->hard_header_len += 6;
  2200. return generic_cdc_bind(dev, intf);
  2201. }
  2202. static const struct driver_info zaurus_sl5x00_info = {
  2203. .description = "Sharp Zaurus SL-5x00",
  2204. .flags = FLAG_FRAMING_Z,
  2205. .check_connect = always_connected,
  2206. .bind = zaurus_bind,
  2207. .unbind = cdc_unbind,
  2208. .tx_fixup = zaurus_tx_fixup,
  2209. };
  2210. #define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info)
  2211. static const struct driver_info zaurus_pxa_info = {
  2212. .description = "Sharp Zaurus, PXA-2xx based",
  2213. .flags = FLAG_FRAMING_Z,
  2214. .check_connect = always_connected,
  2215. .bind = zaurus_bind,
  2216. .unbind = cdc_unbind,
  2217. .tx_fixup = zaurus_tx_fixup,
  2218. };
  2219. #define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info)
  2220. static const struct driver_info olympus_mxl_info = {
  2221. .description = "Olympus R1000",
  2222. .flags = FLAG_FRAMING_Z,
  2223. .check_connect = always_connected,
  2224. .bind = zaurus_bind,
  2225. .unbind = cdc_unbind,
  2226. .tx_fixup = zaurus_tx_fixup,
  2227. };
  2228. #define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info)
  2229. /* Some more recent products using Lineo/Belcarra code will wrongly claim
  2230. * CDC MDLM conformance. They aren't conformant: data endpoints live
  2231. * in the control interface, there's no data interface, and it's not used
  2232. * to talk to a cell phone radio. But at least we can detect these two
  2233. * pseudo-classes, rather than growing this product list with entries for
  2234. * each new nonconformant product (sigh).
  2235. */
  2236. static const u8 safe_guid[16] = {
  2237. 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
  2238. 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
  2239. };
  2240. static const u8 blan_guid[16] = {
  2241. 0x74, 0xf0, 0x3d, 0xbd, 0x1e, 0xc1, 0x44, 0x70,
  2242. 0xa3, 0x67, 0x71, 0x34, 0xc9, 0xf5, 0x54, 0x37,
  2243. };
  2244. static int blan_mdlm_bind (struct usbnet *dev, struct usb_interface *intf)
  2245. {
  2246. u8 *buf = intf->cur_altsetting->extra;
  2247. int len = intf->cur_altsetting->extralen;
  2248. struct usb_cdc_mdlm_desc *desc = NULL;
  2249. struct usb_cdc_mdlm_detail_desc *detail = NULL;
  2250. while (len > 3) {
  2251. if (buf [1] != USB_DT_CS_INTERFACE)
  2252. goto next_desc;
  2253. /* use bDescriptorSubType, and just verify that we get a
  2254. * "BLAN" (or "SAFE") descriptor.
  2255. */
  2256. switch (buf [2]) {
  2257. case USB_CDC_MDLM_TYPE:
  2258. if (desc) {
  2259. dev_dbg (&intf->dev, "extra MDLM\n");
  2260. goto bad_desc;
  2261. }
  2262. desc = (void *) buf;
  2263. if (desc->bLength != sizeof *desc) {
  2264. dev_dbg (&intf->dev, "MDLM len %u\n",
  2265. desc->bLength);
  2266. goto bad_desc;
  2267. }
  2268. /* expect bcdVersion 1.0, ignore */
  2269. if (memcmp(&desc->bGUID, blan_guid, 16)
  2270. && memcmp(&desc->bGUID, safe_guid, 16) ) {
  2271. /* hey, this one might _really_ be MDLM! */
  2272. dev_dbg (&intf->dev, "MDLM guid\n");
  2273. goto bad_desc;
  2274. }
  2275. break;
  2276. case USB_CDC_MDLM_DETAIL_TYPE:
  2277. if (detail) {
  2278. dev_dbg (&intf->dev, "extra MDLM detail\n");
  2279. goto bad_desc;
  2280. }
  2281. detail = (void *) buf;
  2282. switch (detail->bGuidDescriptorType) {
  2283. case 0: /* "SAFE" */
  2284. if (detail->bLength != (sizeof *detail + 2))
  2285. goto bad_detail;
  2286. break;
  2287. case 1: /* "BLAN" */
  2288. if (detail->bLength != (sizeof *detail + 3))
  2289. goto bad_detail;
  2290. break;
  2291. default:
  2292. goto bad_detail;
  2293. }
  2294. /* assuming we either noticed BLAN already, or will
  2295. * find it soon, there are some data bytes here:
  2296. * - bmNetworkCapabilities (unused)
  2297. * - bmDataCapabilities (bits, see below)
  2298. * - bPad (ignored, for PADAFTER -- BLAN-only)
  2299. * bits are:
  2300. * - 0x01 -- Zaurus framing (add CRC)
  2301. * - 0x02 -- PADBEFORE (CRC includes some padding)
  2302. * - 0x04 -- PADAFTER (some padding after CRC)
  2303. * - 0x08 -- "fermat" packet mangling (for hw bugs)
  2304. * the PADBEFORE appears not to matter; we interop
  2305. * with devices that use it and those that don't.
  2306. */
  2307. if ((detail->bDetailData[1] & ~02) != 0x01) {
  2308. /* bmDataCapabilites == 0 would be fine too,
  2309. * but framing is minidriver-coupled for now.
  2310. */
  2311. bad_detail:
  2312. dev_dbg (&intf->dev,
  2313. "bad MDLM detail, %d %d %d\n",
  2314. detail->bLength,
  2315. detail->bDetailData[0],
  2316. detail->bDetailData[2]);
  2317. goto bad_desc;
  2318. }
  2319. break;
  2320. }
  2321. next_desc:
  2322. len -= buf [0]; /* bLength */
  2323. buf += buf [0];
  2324. }
  2325. if (!desc || !detail) {
  2326. dev_dbg (&intf->dev, "missing cdc mdlm %s%sdescriptor\n",
  2327. desc ? "" : "func ",
  2328. detail ? "" : "detail ");
  2329. goto bad_desc;
  2330. }
  2331. /* There's probably a CDC Ethernet descriptor there, but we can't
  2332. * rely on the Ethernet address it provides since not all vendors
  2333. * bother to make it unique. Likewise there's no point in tracking
  2334. * of the CDC event notifications.
  2335. */
  2336. return get_endpoints (dev, intf);
  2337. bad_desc:
  2338. dev_info (&dev->udev->dev, "unsupported MDLM descriptors\n");
  2339. return -ENODEV;
  2340. }
  2341. static const struct driver_info bogus_mdlm_info = {
  2342. .description = "pseudo-MDLM (BLAN) device",
  2343. .flags = FLAG_FRAMING_Z,
  2344. .check_connect = always_connected,
  2345. .tx_fixup = zaurus_tx_fixup,
  2346. .bind = blan_mdlm_bind,
  2347. };
  2348. #else
  2349. /* blacklist all those devices */
  2350. #define ZAURUS_STRONGARM_INFO 0
  2351. #define ZAURUS_PXA_INFO 0
  2352. #define OLYMPUS_MXL_INFO 0
  2353. #endif
  2354. /*-------------------------------------------------------------------------
  2355. *
  2356. * Network Device Driver (peer link to "Host Device", from USB host)
  2357. *
  2358. *-------------------------------------------------------------------------*/
  2359. static int usbnet_change_mtu (struct net_device *net, int new_mtu)
  2360. {
  2361. struct usbnet *dev = netdev_priv(net);
  2362. int ll_mtu = new_mtu + net->hard_header_len;
  2363. if (new_mtu <= 0 || ll_mtu > dev->hard_mtu)
  2364. return -EINVAL;
  2365. // no second zero-length packet read wanted after mtu-sized packets
  2366. if ((ll_mtu % dev->maxpacket) == 0)
  2367. return -EDOM;
  2368. net->mtu = new_mtu;
  2369. return 0;
  2370. }
  2371. /*-------------------------------------------------------------------------*/
  2372. static struct net_device_stats *usbnet_get_stats (struct net_device *net)
  2373. {
  2374. struct usbnet *dev = netdev_priv(net);
  2375. return &dev->stats;
  2376. }
  2377. /*-------------------------------------------------------------------------*/
  2378. /* some LK 2.4 HCDs oopsed if we freed or resubmitted urbs from
  2379. * completion callbacks. 2.5 should have fixed those bugs...
  2380. */
  2381. static void defer_bh(struct usbnet *dev, struct sk_buff *skb, struct sk_buff_head *list)
  2382. {
  2383. unsigned long flags;
  2384. spin_lock_irqsave(&list->lock, flags);
  2385. __skb_unlink(skb, list);
  2386. spin_unlock(&list->lock);
  2387. spin_lock(&dev->done.lock);
  2388. __skb_queue_tail(&dev->done, skb);
  2389. if (dev->done.qlen == 1)
  2390. tasklet_schedule(&dev->bh);
  2391. spin_unlock_irqrestore(&dev->done.lock, flags);
  2392. }
  2393. /* some work can't be done in tasklets, so we use keventd
  2394. *
  2395. * NOTE: annoying asymmetry: if it's active, schedule_work() fails,
  2396. * but tasklet_schedule() doesn't. hope the failure is rare.
  2397. */
  2398. static void defer_kevent (struct usbnet *dev, int work)
  2399. {
  2400. set_bit (work, &dev->flags);
  2401. if (!schedule_work (&dev->kevent))
  2402. deverr (dev, "kevent %d may have been dropped", work);
  2403. else
  2404. devdbg (dev, "kevent %d scheduled", work);
  2405. }
  2406. /*-------------------------------------------------------------------------*/
  2407. static void rx_complete (struct urb *urb, struct pt_regs *regs);
  2408. static void rx_submit (struct usbnet *dev, struct urb *urb, unsigned flags)
  2409. {
  2410. struct sk_buff *skb;
  2411. struct skb_data *entry;
  2412. int retval = 0;
  2413. unsigned long lockflags;
  2414. size_t size;
  2415. size = max(dev->net->hard_header_len + dev->net->mtu,
  2416. (unsigned)ETH_FRAME_LEN);
  2417. if ((skb = alloc_skb (size + NET_IP_ALIGN, flags)) == NULL) {
  2418. if (netif_msg_rx_err (dev))
  2419. devdbg (dev, "no rx skb");
  2420. defer_kevent (dev, EVENT_RX_MEMORY);
  2421. usb_free_urb (urb);
  2422. return;
  2423. }
  2424. skb_reserve (skb, NET_IP_ALIGN);
  2425. entry = (struct skb_data *) skb->cb;
  2426. entry->urb = urb;
  2427. entry->dev = dev;
  2428. entry->state = rx_start;
  2429. entry->length = 0;
  2430. usb_fill_bulk_urb (urb, dev->udev, dev->in,
  2431. skb->data, size, rx_complete, skb);
  2432. spin_lock_irqsave (&dev->rxq.lock, lockflags);
  2433. if (netif_running (dev->net)
  2434. && netif_device_present (dev->net)
  2435. && !test_bit (EVENT_RX_HALT, &dev->flags)) {
  2436. switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){
  2437. case -EPIPE:
  2438. defer_kevent (dev, EVENT_RX_HALT);
  2439. break;
  2440. case -ENOMEM:
  2441. defer_kevent (dev, EVENT_RX_MEMORY);
  2442. break;
  2443. case -ENODEV:
  2444. if (netif_msg_ifdown (dev))
  2445. devdbg (dev, "device gone");
  2446. netif_device_detach (dev->net);
  2447. break;
  2448. default:
  2449. if (netif_msg_rx_err (dev))
  2450. devdbg (dev, "rx submit, %d", retval);
  2451. tasklet_schedule (&dev->bh);
  2452. break;
  2453. case 0:
  2454. __skb_queue_tail (&dev->rxq, skb);
  2455. }
  2456. } else {
  2457. if (netif_msg_ifdown (dev))
  2458. devdbg (dev, "rx: stopped");
  2459. retval = -ENOLINK;
  2460. }
  2461. spin_unlock_irqrestore (&dev->rxq.lock, lockflags);
  2462. if (retval) {
  2463. dev_kfree_skb_any (skb);
  2464. usb_free_urb (urb);
  2465. }
  2466. }
  2467. /*-------------------------------------------------------------------------*/
  2468. static inline void rx_process (struct usbnet *dev, struct sk_buff *skb)
  2469. {
  2470. if (dev->driver_info->rx_fixup
  2471. && !dev->driver_info->rx_fixup (dev, skb))
  2472. goto error;
  2473. // else network stack removes extra byte if we forced a short packet
  2474. if (skb->len)
  2475. skb_return (dev, skb);
  2476. else {
  2477. if (netif_msg_rx_err (dev))
  2478. devdbg (dev, "drop");
  2479. error:
  2480. dev->stats.rx_errors++;
  2481. skb_queue_tail (&dev->done, skb);
  2482. }
  2483. }
  2484. /*-------------------------------------------------------------------------*/
  2485. static void rx_complete (struct urb *urb, struct pt_regs *regs)
  2486. {
  2487. struct sk_buff *skb = (struct sk_buff *) urb->context;
  2488. struct skb_data *entry = (struct skb_data *) skb->cb;
  2489. struct usbnet *dev = entry->dev;
  2490. int urb_status = urb->status;
  2491. skb_put (skb, urb->actual_length);
  2492. entry->state = rx_done;
  2493. entry->urb = NULL;
  2494. switch (urb_status) {
  2495. // success
  2496. case 0:
  2497. if (skb->len < dev->net->hard_header_len) {
  2498. entry->state = rx_cleanup;
  2499. dev->stats.rx_errors++;
  2500. dev->stats.rx_length_errors++;
  2501. if (netif_msg_rx_err (dev))
  2502. devdbg (dev, "rx length %d", skb->len);
  2503. }
  2504. break;
  2505. // stalls need manual reset. this is rare ... except that
  2506. // when going through USB 2.0 TTs, unplug appears this way.
  2507. // we avoid the highspeed version of the ETIMEOUT/EILSEQ
  2508. // storm, recovering as needed.
  2509. case -EPIPE:
  2510. dev->stats.rx_errors++;
  2511. defer_kevent (dev, EVENT_RX_HALT);
  2512. // FALLTHROUGH
  2513. // software-driven interface shutdown
  2514. case -ECONNRESET: // async unlink
  2515. case -ESHUTDOWN: // hardware gone
  2516. if (netif_msg_ifdown (dev))
  2517. devdbg (dev, "rx shutdown, code %d", urb_status);
  2518. goto block;
  2519. // we get controller i/o faults during khubd disconnect() delays.
  2520. // throttle down resubmits, to avoid log floods; just temporarily,
  2521. // so we still recover when the fault isn't a khubd delay.
  2522. case -EPROTO: // ehci
  2523. case -ETIMEDOUT: // ohci
  2524. case -EILSEQ: // uhci
  2525. dev->stats.rx_errors++;
  2526. if (!timer_pending (&dev->delay)) {
  2527. mod_timer (&dev->delay, jiffies + THROTTLE_JIFFIES);
  2528. if (netif_msg_link (dev))
  2529. devdbg (dev, "rx throttle %d", urb_status);
  2530. }
  2531. block:
  2532. entry->state = rx_cleanup;
  2533. entry->urb = urb;
  2534. urb = NULL;
  2535. break;
  2536. // data overrun ... flush fifo?
  2537. case -EOVERFLOW:
  2538. dev->stats.rx_over_errors++;
  2539. // FALLTHROUGH
  2540. default:
  2541. entry->state = rx_cleanup;
  2542. dev->stats.rx_errors++;
  2543. if (netif_msg_rx_err (dev))
  2544. devdbg (dev, "rx status %d", urb_status);
  2545. break;
  2546. }
  2547. defer_bh(dev, skb, &dev->rxq);
  2548. if (urb) {
  2549. if (netif_running (dev->net)
  2550. && !test_bit (EVENT_RX_HALT, &dev->flags)) {
  2551. rx_submit (dev, urb, GFP_ATOMIC);
  2552. return;
  2553. }
  2554. usb_free_urb (urb);
  2555. }
  2556. if (netif_msg_rx_err (dev))
  2557. devdbg (dev, "no read resubmitted");
  2558. }
  2559. static void intr_complete (struct urb *urb, struct pt_regs *regs)
  2560. {
  2561. struct usbnet *dev = urb->context;
  2562. int status = urb->status;
  2563. switch (status) {
  2564. /* success */
  2565. case 0:
  2566. dev->driver_info->status(dev, urb);
  2567. break;
  2568. /* software-driven interface shutdown */
  2569. case -ENOENT: // urb killed
  2570. case -ESHUTDOWN: // hardware gone
  2571. if (netif_msg_ifdown (dev))
  2572. devdbg (dev, "intr shutdown, code %d", status);
  2573. return;
  2574. /* NOTE: not throttling like RX/TX, since this endpoint
  2575. * already polls infrequently
  2576. */
  2577. default:
  2578. devdbg (dev, "intr status %d", status);
  2579. break;
  2580. }
  2581. if (!netif_running (dev->net))
  2582. return;
  2583. memset(urb->transfer_buffer, 0, urb->transfer_buffer_length);
  2584. status = usb_submit_urb (urb, GFP_ATOMIC);
  2585. if (status != 0 && netif_msg_timer (dev))
  2586. deverr(dev, "intr resubmit --> %d", status);
  2587. }
  2588. /*-------------------------------------------------------------------------*/
  2589. // unlink pending rx/tx; completion handlers do all other cleanup
  2590. static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q)
  2591. {
  2592. unsigned long flags;
  2593. struct sk_buff *skb, *skbnext;
  2594. int count = 0;
  2595. spin_lock_irqsave (&q->lock, flags);
  2596. for (skb = q->next; skb != (struct sk_buff *) q; skb = skbnext) {
  2597. struct skb_data *entry;
  2598. struct urb *urb;
  2599. int retval;
  2600. entry = (struct skb_data *) skb->cb;
  2601. urb = entry->urb;
  2602. skbnext = skb->next;
  2603. // during some PM-driven resume scenarios,
  2604. // these (async) unlinks complete immediately
  2605. retval = usb_unlink_urb (urb);
  2606. if (retval != -EINPROGRESS && retval != 0)
  2607. devdbg (dev, "unlink urb err, %d", retval);
  2608. else
  2609. count++;
  2610. }
  2611. spin_unlock_irqrestore (&q->lock, flags);
  2612. return count;
  2613. }
  2614. /*-------------------------------------------------------------------------*/
  2615. // precondition: never called in_interrupt
  2616. static int usbnet_stop (struct net_device *net)
  2617. {
  2618. struct usbnet *dev = netdev_priv(net);
  2619. int temp;
  2620. DECLARE_WAIT_QUEUE_HEAD (unlink_wakeup);
  2621. DECLARE_WAITQUEUE (wait, current);
  2622. netif_stop_queue (net);
  2623. if (netif_msg_ifdown (dev))
  2624. devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld",
  2625. dev->stats.rx_packets, dev->stats.tx_packets,
  2626. dev->stats.rx_errors, dev->stats.tx_errors
  2627. );
  2628. // ensure there are no more active urbs
  2629. add_wait_queue (&unlink_wakeup, &wait);
  2630. dev->wait = &unlink_wakeup;
  2631. temp = unlink_urbs (dev, &dev->txq) + unlink_urbs (dev, &dev->rxq);
  2632. // maybe wait for deletions to finish.
  2633. while (!skb_queue_empty(&dev->rxq) &&
  2634. !skb_queue_empty(&dev->txq) &&
  2635. !skb_queue_empty(&dev->done)) {
  2636. msleep(UNLINK_TIMEOUT_MS);
  2637. if (netif_msg_ifdown (dev))
  2638. devdbg (dev, "waited for %d urb completions", temp);
  2639. }
  2640. dev->wait = NULL;
  2641. remove_wait_queue (&unlink_wakeup, &wait);
  2642. usb_kill_urb(dev->interrupt);
  2643. /* deferred work (task, timer, softirq) must also stop.
  2644. * can't flush_scheduled_work() until we drop rtnl (later),
  2645. * else workers could deadlock; so make workers a NOP.
  2646. */
  2647. dev->flags = 0;
  2648. del_timer_sync (&dev->delay);
  2649. tasklet_kill (&dev->bh);
  2650. return 0;
  2651. }
  2652. /*-------------------------------------------------------------------------*/
  2653. // posts reads, and enables write queuing
  2654. // precondition: never called in_interrupt
  2655. static int usbnet_open (struct net_device *net)
  2656. {
  2657. struct usbnet *dev = netdev_priv(net);
  2658. int retval = 0;
  2659. struct driver_info *info = dev->driver_info;
  2660. // put into "known safe" state
  2661. if (info->reset && (retval = info->reset (dev)) < 0) {
  2662. if (netif_msg_ifup (dev))
  2663. devinfo (dev,
  2664. "open reset fail (%d) usbnet usb-%s-%s, %s",
  2665. retval,
  2666. dev->udev->bus->bus_name, dev->udev->devpath,
  2667. info->description);
  2668. goto done;
  2669. }
  2670. // insist peer be connected
  2671. if (info->check_connect && (retval = info->check_connect (dev)) < 0) {
  2672. if (netif_msg_ifup (dev))
  2673. devdbg (dev, "can't open; %d", retval);
  2674. goto done;
  2675. }
  2676. /* start any status interrupt transfer */
  2677. if (dev->interrupt) {
  2678. retval = usb_submit_urb (dev->interrupt, GFP_KERNEL);
  2679. if (retval < 0) {
  2680. if (netif_msg_ifup (dev))
  2681. deverr (dev, "intr submit %d", retval);
  2682. goto done;
  2683. }
  2684. }
  2685. netif_start_queue (net);
  2686. if (netif_msg_ifup (dev)) {
  2687. char *framing;
  2688. if (dev->driver_info->flags & FLAG_FRAMING_NC)
  2689. framing = "NetChip";
  2690. else if (dev->driver_info->flags & FLAG_FRAMING_GL)
  2691. framing = "GeneSys";
  2692. else if (dev->driver_info->flags & FLAG_FRAMING_Z)
  2693. framing = "Zaurus";
  2694. else if (dev->driver_info->flags & FLAG_FRAMING_RN)
  2695. framing = "RNDIS";
  2696. else if (dev->driver_info->flags & FLAG_FRAMING_AX)
  2697. framing = "ASIX";
  2698. else
  2699. framing = "simple";
  2700. devinfo (dev, "open: enable queueing "
  2701. "(rx %d, tx %d) mtu %d %s framing",
  2702. RX_QLEN (dev), TX_QLEN (dev), dev->net->mtu,
  2703. framing);
  2704. }
  2705. // delay posting reads until we're fully open
  2706. tasklet_schedule (&dev->bh);
  2707. done:
  2708. return retval;
  2709. }
  2710. /*-------------------------------------------------------------------------*/
  2711. static void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info)
  2712. {
  2713. struct usbnet *dev = netdev_priv(net);
  2714. strncpy (info->driver, driver_name, sizeof info->driver);
  2715. strncpy (info->version, DRIVER_VERSION, sizeof info->version);
  2716. strncpy (info->fw_version, dev->driver_info->description,
  2717. sizeof info->fw_version);
  2718. usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info);
  2719. }
  2720. static u32 usbnet_get_link (struct net_device *net)
  2721. {
  2722. struct usbnet *dev = netdev_priv(net);
  2723. /* If a check_connect is defined, return its result */
  2724. if (dev->driver_info->check_connect)
  2725. return dev->driver_info->check_connect (dev) == 0;
  2726. /* Otherwise, say we're up (to avoid breaking scripts) */
  2727. return 1;
  2728. }
  2729. static u32 usbnet_get_msglevel (struct net_device *net)
  2730. {
  2731. struct usbnet *dev = netdev_priv(net);
  2732. return dev->msg_enable;
  2733. }
  2734. static void usbnet_set_msglevel (struct net_device *net, u32 level)
  2735. {
  2736. struct usbnet *dev = netdev_priv(net);
  2737. dev->msg_enable = level;
  2738. }
  2739. static int usbnet_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
  2740. {
  2741. #ifdef NEED_MII
  2742. {
  2743. struct usbnet *dev = netdev_priv(net);
  2744. if (dev->mii.mdio_read != NULL && dev->mii.mdio_write != NULL)
  2745. return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
  2746. }
  2747. #endif
  2748. return -EOPNOTSUPP;
  2749. }
  2750. /*-------------------------------------------------------------------------*/
  2751. /* work that cannot be done in interrupt context uses keventd.
  2752. *
  2753. * NOTE: with 2.5 we could do more of this using completion callbacks,
  2754. * especially now that control transfers can be queued.
  2755. */
  2756. static void
  2757. kevent (void *data)
  2758. {
  2759. struct usbnet *dev = data;
  2760. int status;
  2761. /* usb_clear_halt() needs a thread context */
  2762. if (test_bit (EVENT_TX_HALT, &dev->flags)) {
  2763. unlink_urbs (dev, &dev->txq);
  2764. status = usb_clear_halt (dev->udev, dev->out);
  2765. if (status < 0
  2766. && status != -EPIPE
  2767. && status != -ESHUTDOWN) {
  2768. if (netif_msg_tx_err (dev))
  2769. deverr (dev, "can't clear tx halt, status %d",
  2770. status);
  2771. } else {
  2772. clear_bit (EVENT_TX_HALT, &dev->flags);
  2773. if (status != -ESHUTDOWN)
  2774. netif_wake_queue (dev->net);
  2775. }
  2776. }
  2777. if (test_bit (EVENT_RX_HALT, &dev->flags)) {
  2778. unlink_urbs (dev, &dev->rxq);
  2779. status = usb_clear_halt (dev->udev, dev->in);
  2780. if (status < 0
  2781. && status != -EPIPE
  2782. && status != -ESHUTDOWN) {
  2783. if (netif_msg_rx_err (dev))
  2784. deverr (dev, "can't clear rx halt, status %d",
  2785. status);
  2786. } else {
  2787. clear_bit (EVENT_RX_HALT, &dev->flags);
  2788. tasklet_schedule (&dev->bh);
  2789. }
  2790. }
  2791. /* tasklet could resubmit itself forever if memory is tight */
  2792. if (test_bit (EVENT_RX_MEMORY, &dev->flags)) {
  2793. struct urb *urb = NULL;
  2794. if (netif_running (dev->net))
  2795. urb = usb_alloc_urb (0, GFP_KERNEL);
  2796. else
  2797. clear_bit (EVENT_RX_MEMORY, &dev->flags);
  2798. if (urb != NULL) {
  2799. clear_bit (EVENT_RX_MEMORY, &dev->flags);
  2800. rx_submit (dev, urb, GFP_KERNEL);
  2801. tasklet_schedule (&dev->bh);
  2802. }
  2803. }
  2804. if (test_bit (EVENT_LINK_RESET, &dev->flags)) {
  2805. struct driver_info *info = dev->driver_info;
  2806. int retval = 0;
  2807. clear_bit (EVENT_LINK_RESET, &dev->flags);
  2808. if(info->link_reset && (retval = info->link_reset(dev)) < 0) {
  2809. devinfo(dev, "link reset failed (%d) usbnet usb-%s-%s, %s",
  2810. retval,
  2811. dev->udev->bus->bus_name, dev->udev->devpath,
  2812. info->description);
  2813. }
  2814. }
  2815. if (dev->flags)
  2816. devdbg (dev, "kevent done, flags = 0x%lx",
  2817. dev->flags);
  2818. }
  2819. /*-------------------------------------------------------------------------*/
  2820. static void tx_complete (struct urb *urb, struct pt_regs *regs)
  2821. {
  2822. struct sk_buff *skb = (struct sk_buff *) urb->context;
  2823. struct skb_data *entry = (struct skb_data *) skb->cb;
  2824. struct usbnet *dev = entry->dev;
  2825. if (urb->status == 0) {
  2826. dev->stats.tx_packets++;
  2827. dev->stats.tx_bytes += entry->length;
  2828. } else {
  2829. dev->stats.tx_errors++;
  2830. switch (urb->status) {
  2831. case -EPIPE:
  2832. defer_kevent (dev, EVENT_TX_HALT);
  2833. break;
  2834. /* software-driven interface shutdown */
  2835. case -ECONNRESET: // async unlink
  2836. case -ESHUTDOWN: // hardware gone
  2837. break;
  2838. // like rx, tx gets controller i/o faults during khubd delays
  2839. // and so it uses the same throttling mechanism.
  2840. case -EPROTO: // ehci
  2841. case -ETIMEDOUT: // ohci
  2842. case -EILSEQ: // uhci
  2843. if (!timer_pending (&dev->delay)) {
  2844. mod_timer (&dev->delay,
  2845. jiffies + THROTTLE_JIFFIES);
  2846. if (netif_msg_link (dev))
  2847. devdbg (dev, "tx throttle %d",
  2848. urb->status);
  2849. }
  2850. netif_stop_queue (dev->net);
  2851. break;
  2852. default:
  2853. if (netif_msg_tx_err (dev))
  2854. devdbg (dev, "tx err %d", entry->urb->status);
  2855. break;
  2856. }
  2857. }
  2858. urb->dev = NULL;
  2859. entry->state = tx_done;
  2860. defer_bh(dev, skb, &dev->txq);
  2861. }
  2862. /*-------------------------------------------------------------------------*/
  2863. static void usbnet_tx_timeout (struct net_device *net)
  2864. {
  2865. struct usbnet *dev = netdev_priv(net);
  2866. unlink_urbs (dev, &dev->txq);
  2867. tasklet_schedule (&dev->bh);
  2868. // FIXME: device recovery -- reset?
  2869. }
  2870. /*-------------------------------------------------------------------------*/
  2871. static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
  2872. {
  2873. struct usbnet *dev = netdev_priv(net);
  2874. int length;
  2875. int retval = NET_XMIT_SUCCESS;
  2876. struct urb *urb = NULL;
  2877. struct skb_data *entry;
  2878. struct driver_info *info = dev->driver_info;
  2879. unsigned long flags;
  2880. #ifdef CONFIG_USB_NET1080
  2881. struct nc_header *header = NULL;
  2882. struct nc_trailer *trailer = NULL;
  2883. #endif /* CONFIG_USB_NET1080 */
  2884. // some devices want funky USB-level framing, for
  2885. // win32 driver (usually) and/or hardware quirks
  2886. if (info->tx_fixup) {
  2887. skb = info->tx_fixup (dev, skb, GFP_ATOMIC);
  2888. if (!skb) {
  2889. if (netif_msg_tx_err (dev))
  2890. devdbg (dev, "can't tx_fixup skb");
  2891. goto drop;
  2892. }
  2893. }
  2894. length = skb->len;
  2895. if (!(urb = usb_alloc_urb (0, GFP_ATOMIC))) {
  2896. if (netif_msg_tx_err (dev))
  2897. devdbg (dev, "no urb");
  2898. goto drop;
  2899. }
  2900. entry = (struct skb_data *) skb->cb;
  2901. entry->urb = urb;
  2902. entry->dev = dev;
  2903. entry->state = tx_start;
  2904. entry->length = length;
  2905. // FIXME: reorganize a bit, so that fixup() fills out NetChip
  2906. // framing too. (Packet ID update needs the spinlock...)
  2907. // [ BETTER: we already own net->xmit_lock, that's enough ]
  2908. #ifdef CONFIG_USB_NET1080
  2909. if (info->flags & FLAG_FRAMING_NC) {
  2910. header = (struct nc_header *) skb_push (skb, sizeof *header);
  2911. header->hdr_len = cpu_to_le16 (sizeof (*header));
  2912. header->packet_len = cpu_to_le16 (length);
  2913. if (!((skb->len + sizeof *trailer) & 0x01))
  2914. *skb_put (skb, 1) = PAD_BYTE;
  2915. trailer = (struct nc_trailer *) skb_put (skb, sizeof *trailer);
  2916. }
  2917. #endif /* CONFIG_USB_NET1080 */
  2918. usb_fill_bulk_urb (urb, dev->udev, dev->out,
  2919. skb->data, skb->len, tx_complete, skb);
  2920. /* don't assume the hardware handles USB_ZERO_PACKET
  2921. * NOTE: strictly conforming cdc-ether devices should expect
  2922. * the ZLP here, but ignore the one-byte packet.
  2923. *
  2924. * FIXME zero that byte, if it doesn't require a new skb.
  2925. */
  2926. if ((length % dev->maxpacket) == 0)
  2927. urb->transfer_buffer_length++;
  2928. spin_lock_irqsave (&dev->txq.lock, flags);
  2929. #ifdef CONFIG_USB_NET1080
  2930. if (info->flags & FLAG_FRAMING_NC) {
  2931. header->packet_id = cpu_to_le16 ((u16)dev->xid++);
  2932. put_unaligned (header->packet_id, &trailer->packet_id);
  2933. #if 0
  2934. devdbg (dev, "frame >tx h %d p %d id %d",
  2935. header->hdr_len, header->packet_len,
  2936. header->packet_id);
  2937. #endif
  2938. }
  2939. #endif /* CONFIG_USB_NET1080 */
  2940. switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) {
  2941. case -EPIPE:
  2942. netif_stop_queue (net);
  2943. defer_kevent (dev, EVENT_TX_HALT);
  2944. break;
  2945. default:
  2946. if (netif_msg_tx_err (dev))
  2947. devdbg (dev, "tx: submit urb err %d", retval);
  2948. break;
  2949. case 0:
  2950. net->trans_start = jiffies;
  2951. __skb_queue_tail (&dev->txq, skb);
  2952. if (dev->txq.qlen >= TX_QLEN (dev))
  2953. netif_stop_queue (net);
  2954. }
  2955. spin_unlock_irqrestore (&dev->txq.lock, flags);
  2956. if (retval) {
  2957. if (netif_msg_tx_err (dev))
  2958. devdbg (dev, "drop, code %d", retval);
  2959. drop:
  2960. retval = NET_XMIT_SUCCESS;
  2961. dev->stats.tx_dropped++;
  2962. if (skb)
  2963. dev_kfree_skb_any (skb);
  2964. usb_free_urb (urb);
  2965. } else if (netif_msg_tx_queued (dev)) {
  2966. devdbg (dev, "> tx, len %d, type 0x%x",
  2967. length, skb->protocol);
  2968. }
  2969. return retval;
  2970. }
  2971. /*-------------------------------------------------------------------------*/
  2972. // tasklet (work deferred from completions, in_irq) or timer
  2973. static void usbnet_bh (unsigned long param)
  2974. {
  2975. struct usbnet *dev = (struct usbnet *) param;
  2976. struct sk_buff *skb;
  2977. struct skb_data *entry;
  2978. while ((skb = skb_dequeue (&dev->done))) {
  2979. entry = (struct skb_data *) skb->cb;
  2980. switch (entry->state) {
  2981. case rx_done:
  2982. entry->state = rx_cleanup;
  2983. rx_process (dev, skb);
  2984. continue;
  2985. case tx_done:
  2986. case rx_cleanup:
  2987. usb_free_urb (entry->urb);
  2988. dev_kfree_skb (skb);
  2989. continue;
  2990. default:
  2991. devdbg (dev, "bogus skb state %d", entry->state);
  2992. }
  2993. }
  2994. // waiting for all pending urbs to complete?
  2995. if (dev->wait) {
  2996. if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) {
  2997. wake_up (dev->wait);
  2998. }
  2999. // or are we maybe short a few urbs?
  3000. } else if (netif_running (dev->net)
  3001. && netif_device_present (dev->net)
  3002. && !timer_pending (&dev->delay)
  3003. && !test_bit (EVENT_RX_HALT, &dev->flags)) {
  3004. int temp = dev->rxq.qlen;
  3005. int qlen = RX_QLEN (dev);
  3006. if (temp < qlen) {
  3007. struct urb *urb;
  3008. int i;
  3009. // don't refill the queue all at once
  3010. for (i = 0; i < 10 && dev->rxq.qlen < qlen; i++) {
  3011. urb = usb_alloc_urb (0, GFP_ATOMIC);
  3012. if (urb != NULL)
  3013. rx_submit (dev, urb, GFP_ATOMIC);
  3014. }
  3015. if (temp != dev->rxq.qlen && netif_msg_link (dev))
  3016. devdbg (dev, "rxqlen %d --> %d",
  3017. temp, dev->rxq.qlen);
  3018. if (dev->rxq.qlen < qlen)
  3019. tasklet_schedule (&dev->bh);
  3020. }
  3021. if (dev->txq.qlen < TX_QLEN (dev))
  3022. netif_wake_queue (dev->net);
  3023. }
  3024. }
  3025. /*-------------------------------------------------------------------------
  3026. *
  3027. * USB Device Driver support
  3028. *
  3029. *-------------------------------------------------------------------------*/
  3030. // precondition: never called in_interrupt
  3031. static void usbnet_disconnect (struct usb_interface *intf)
  3032. {
  3033. struct usbnet *dev;
  3034. struct usb_device *xdev;
  3035. struct net_device *net;
  3036. dev = usb_get_intfdata(intf);
  3037. usb_set_intfdata(intf, NULL);
  3038. if (!dev)
  3039. return;
  3040. xdev = interface_to_usbdev (intf);
  3041. if (netif_msg_probe (dev))
  3042. devinfo (dev, "unregister usbnet usb-%s-%s, %s",
  3043. xdev->bus->bus_name, xdev->devpath,
  3044. dev->driver_info->description);
  3045. net = dev->net;
  3046. unregister_netdev (net);
  3047. /* we don't hold rtnl here ... */
  3048. flush_scheduled_work ();
  3049. if (dev->driver_info->unbind)
  3050. dev->driver_info->unbind (dev, intf);
  3051. free_netdev(net);
  3052. usb_put_dev (xdev);
  3053. }
  3054. /*-------------------------------------------------------------------------*/
  3055. static struct ethtool_ops usbnet_ethtool_ops;
  3056. // precondition: never called in_interrupt
  3057. static int
  3058. usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
  3059. {
  3060. struct usbnet *dev;
  3061. struct net_device *net;
  3062. struct usb_host_interface *interface;
  3063. struct driver_info *info;
  3064. struct usb_device *xdev;
  3065. int status;
  3066. info = (struct driver_info *) prod->driver_info;
  3067. if (!info) {
  3068. dev_dbg (&udev->dev, "blacklisted by %s\n", driver_name);
  3069. return -ENODEV;
  3070. }
  3071. xdev = interface_to_usbdev (udev);
  3072. interface = udev->cur_altsetting;
  3073. usb_get_dev (xdev);
  3074. status = -ENOMEM;
  3075. // set up our own records
  3076. net = alloc_etherdev(sizeof(*dev));
  3077. if (!net) {
  3078. dbg ("can't kmalloc dev");
  3079. goto out;
  3080. }
  3081. dev = netdev_priv(net);
  3082. dev->udev = xdev;
  3083. dev->driver_info = info;
  3084. dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV
  3085. | NETIF_MSG_PROBE | NETIF_MSG_LINK);
  3086. skb_queue_head_init (&dev->rxq);
  3087. skb_queue_head_init (&dev->txq);
  3088. skb_queue_head_init (&dev->done);
  3089. dev->bh.func = usbnet_bh;
  3090. dev->bh.data = (unsigned long) dev;
  3091. INIT_WORK (&dev->kevent, kevent, dev);
  3092. dev->delay.function = usbnet_bh;
  3093. dev->delay.data = (unsigned long) dev;
  3094. init_timer (&dev->delay);
  3095. SET_MODULE_OWNER (net);
  3096. dev->net = net;
  3097. strcpy (net->name, "usb%d");
  3098. memcpy (net->dev_addr, node_id, sizeof node_id);
  3099. dev->hard_mtu = net->mtu + net->hard_header_len;
  3100. #if 0
  3101. // dma_supported() is deeply broken on almost all architectures
  3102. // possible with some EHCI controllers
  3103. if (dma_supported (&udev->dev, DMA_64BIT_MASK))
  3104. net->features |= NETIF_F_HIGHDMA;
  3105. #endif
  3106. net->change_mtu = usbnet_change_mtu;
  3107. net->get_stats = usbnet_get_stats;
  3108. net->hard_start_xmit = usbnet_start_xmit;
  3109. net->open = usbnet_open;
  3110. net->stop = usbnet_stop;
  3111. net->watchdog_timeo = TX_TIMEOUT_JIFFIES;
  3112. net->tx_timeout = usbnet_tx_timeout;
  3113. net->do_ioctl = usbnet_ioctl;
  3114. net->ethtool_ops = &usbnet_ethtool_ops;
  3115. // allow device-specific bind/init procedures
  3116. // NOTE net->name still not usable ...
  3117. if (info->bind) {
  3118. status = info->bind (dev, udev);
  3119. // heuristic: "usb%d" for links we know are two-host,
  3120. // else "eth%d" when there's reasonable doubt. userspace
  3121. // can rename the link if it knows better.
  3122. if ((dev->driver_info->flags & FLAG_ETHER) != 0
  3123. && (net->dev_addr [0] & 0x02) == 0)
  3124. strcpy (net->name, "eth%d");
  3125. /* maybe the remote can't receive an Ethernet MTU */
  3126. if (net->mtu > (dev->hard_mtu - net->hard_header_len))
  3127. net->mtu = dev->hard_mtu - net->hard_header_len;
  3128. } else if (!info->in || info->out)
  3129. status = get_endpoints (dev, udev);
  3130. else {
  3131. dev->in = usb_rcvbulkpipe (xdev, info->in);
  3132. dev->out = usb_sndbulkpipe (xdev, info->out);
  3133. if (!(info->flags & FLAG_NO_SETINT))
  3134. status = usb_set_interface (xdev,
  3135. interface->desc.bInterfaceNumber,
  3136. interface->desc.bAlternateSetting);
  3137. else
  3138. status = 0;
  3139. }
  3140. if (status == 0 && dev->status)
  3141. status = init_status (dev, udev);
  3142. if (status < 0)
  3143. goto out1;
  3144. dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
  3145. SET_NETDEV_DEV(net, &udev->dev);
  3146. status = register_netdev (net);
  3147. if (status)
  3148. goto out3;
  3149. if (netif_msg_probe (dev))
  3150. devinfo (dev, "register usbnet at usb-%s-%s, %s, "
  3151. "%02x:%02x:%02x:%02x:%02x:%02x",
  3152. xdev->bus->bus_name, xdev->devpath,
  3153. dev->driver_info->description,
  3154. net->dev_addr [0], net->dev_addr [1],
  3155. net->dev_addr [2], net->dev_addr [3],
  3156. net->dev_addr [4], net->dev_addr [5]);
  3157. // ok, it's ready to go.
  3158. usb_set_intfdata (udev, dev);
  3159. // start as if the link is up
  3160. netif_device_attach (net);
  3161. return 0;
  3162. out3:
  3163. if (info->unbind)
  3164. info->unbind (dev, udev);
  3165. out1:
  3166. free_netdev(net);
  3167. out:
  3168. usb_put_dev(xdev);
  3169. return status;
  3170. }
  3171. /*-------------------------------------------------------------------------*/
  3172. #ifdef CONFIG_PM
  3173. static int usbnet_suspend (struct usb_interface *intf, pm_message_t message)
  3174. {
  3175. struct usbnet *dev = usb_get_intfdata(intf);
  3176. /* accelerate emptying of the rx and queues, to avoid
  3177. * having everything error out.
  3178. */
  3179. netif_device_detach (dev->net);
  3180. (void) unlink_urbs (dev, &dev->rxq);
  3181. (void) unlink_urbs (dev, &dev->txq);
  3182. intf->dev.power.power_state = PMSG_SUSPEND;
  3183. return 0;
  3184. }
  3185. static int usbnet_resume (struct usb_interface *intf)
  3186. {
  3187. struct usbnet *dev = usb_get_intfdata(intf);
  3188. intf->dev.power.power_state = PMSG_ON;
  3189. netif_device_attach (dev->net);
  3190. tasklet_schedule (&dev->bh);
  3191. return 0;
  3192. }
  3193. #else /* !CONFIG_PM */
  3194. #define usbnet_suspend NULL
  3195. #define usbnet_resume NULL
  3196. #endif /* CONFIG_PM */
  3197. /*-------------------------------------------------------------------------*/
  3198. #ifndef HAVE_HARDWARE
  3199. #error You need to configure some hardware for this driver
  3200. #endif
  3201. /*
  3202. * chip vendor names won't normally be on the cables, and
  3203. * may not be on the device.
  3204. */
  3205. static const struct usb_device_id products [] = {
  3206. #ifdef CONFIG_USB_ALI_M5632
  3207. {
  3208. USB_DEVICE (0x0402, 0x5632), // ALi defaults
  3209. .driver_info = (unsigned long) &ali_m5632_info,
  3210. },
  3211. #endif
  3212. #ifdef CONFIG_USB_AN2720
  3213. {
  3214. USB_DEVICE (0x0547, 0x2720), // AnchorChips defaults
  3215. .driver_info = (unsigned long) &an2720_info,
  3216. }, {
  3217. USB_DEVICE (0x0547, 0x2727), // Xircom PGUNET
  3218. .driver_info = (unsigned long) &an2720_info,
  3219. },
  3220. #endif
  3221. #ifdef CONFIG_USB_BELKIN
  3222. {
  3223. USB_DEVICE (0x050d, 0x0004), // Belkin
  3224. .driver_info = (unsigned long) &belkin_info,
  3225. }, {
  3226. USB_DEVICE (0x056c, 0x8100), // eTEK
  3227. .driver_info = (unsigned long) &belkin_info,
  3228. }, {
  3229. USB_DEVICE (0x0525, 0x9901), // Advance USBNET (eTEK)
  3230. .driver_info = (unsigned long) &belkin_info,
  3231. },
  3232. #endif
  3233. #ifdef CONFIG_USB_AX8817X
  3234. {
  3235. // Linksys USB200M
  3236. USB_DEVICE (0x077b, 0x2226),
  3237. .driver_info = (unsigned long) &ax8817x_info,
  3238. }, {
  3239. // Netgear FA120
  3240. USB_DEVICE (0x0846, 0x1040),
  3241. .driver_info = (unsigned long) &netgear_fa120_info,
  3242. }, {
  3243. // DLink DUB-E100
  3244. USB_DEVICE (0x2001, 0x1a00),
  3245. .driver_info = (unsigned long) &dlink_dub_e100_info,
  3246. }, {
  3247. // Intellinet, ST Lab USB Ethernet
  3248. USB_DEVICE (0x0b95, 0x1720),
  3249. .driver_info = (unsigned long) &ax8817x_info,
  3250. }, {
  3251. // Hawking UF200, TrendNet TU2-ET100
  3252. USB_DEVICE (0x07b8, 0x420a),
  3253. .driver_info = (unsigned long) &hawking_uf200_info,
  3254. }, {
  3255. // Billionton Systems, USB2AR
  3256. USB_DEVICE (0x08dd, 0x90ff),
  3257. .driver_info = (unsigned long) &ax8817x_info,
  3258. }, {
  3259. // ATEN UC210T
  3260. USB_DEVICE (0x0557, 0x2009),
  3261. .driver_info = (unsigned long) &ax8817x_info,
  3262. }, {
  3263. // Buffalo LUA-U2-KTX
  3264. USB_DEVICE (0x0411, 0x003d),
  3265. .driver_info = (unsigned long) &ax8817x_info,
  3266. }, {
  3267. // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter"
  3268. USB_DEVICE (0x6189, 0x182d),
  3269. .driver_info = (unsigned long) &ax8817x_info,
  3270. }, {
  3271. // corega FEther USB2-TX
  3272. USB_DEVICE (0x07aa, 0x0017),
  3273. .driver_info = (unsigned long) &ax8817x_info,
  3274. }, {
  3275. // Surecom EP-1427X-2
  3276. USB_DEVICE (0x1189, 0x0893),
  3277. .driver_info = (unsigned long) &ax8817x_info,
  3278. }, {
  3279. // goodway corp usb gwusb2e
  3280. USB_DEVICE (0x1631, 0x6200),
  3281. .driver_info = (unsigned long) &ax8817x_info,
  3282. }, {
  3283. // ASIX AX88772 10/100
  3284. USB_DEVICE (0x0b95, 0x7720),
  3285. .driver_info = (unsigned long) &ax88772_info,
  3286. },
  3287. #endif
  3288. #ifdef CONFIG_USB_EPSON2888
  3289. {
  3290. USB_DEVICE (0x0525, 0x2888), // EPSON USB client
  3291. .driver_info = (unsigned long) &epson2888_info,
  3292. },
  3293. #endif
  3294. #ifdef CONFIG_USB_GENESYS
  3295. {
  3296. USB_DEVICE (0x05e3, 0x0502), // GL620USB-A
  3297. .driver_info = (unsigned long) &genelink_info,
  3298. },
  3299. /* NOT: USB_DEVICE (0x05e3, 0x0501), // GL620USB
  3300. * that's half duplex, not currently supported
  3301. */
  3302. #endif
  3303. #ifdef CONFIG_USB_NET1080
  3304. {
  3305. USB_DEVICE (0x0525, 0x1080), // NetChip ref design
  3306. .driver_info = (unsigned long) &net1080_info,
  3307. }, {
  3308. USB_DEVICE (0x06D0, 0x0622), // Laplink Gold
  3309. .driver_info = (unsigned long) &net1080_info,
  3310. },
  3311. #endif
  3312. #ifdef CONFIG_USB_PL2301
  3313. {
  3314. USB_DEVICE (0x067b, 0x0000), // PL-2301
  3315. .driver_info = (unsigned long) &prolific_info,
  3316. }, {
  3317. USB_DEVICE (0x067b, 0x0001), // PL-2302
  3318. .driver_info = (unsigned long) &prolific_info,
  3319. },
  3320. #endif
  3321. #ifdef CONFIG_USB_KC2190
  3322. {
  3323. USB_DEVICE (0x050f, 0x0190), // KC-190
  3324. .driver_info = (unsigned long) &kc2190_info,
  3325. },
  3326. #endif
  3327. #ifdef CONFIG_USB_RNDIS
  3328. {
  3329. /* RNDIS is MSFT's un-official variant of CDC ACM */
  3330. USB_INTERFACE_INFO (USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
  3331. .driver_info = (unsigned long) &rndis_info,
  3332. },
  3333. #endif
  3334. #ifdef CONFIG_USB_ARMLINUX
  3335. /*
  3336. * SA-1100 using standard ARM Linux kernels, or compatible.
  3337. * Often used when talking to Linux PDAs (iPaq, Yopy, etc).
  3338. * The sa-1100 "usb-eth" driver handles the basic framing.
  3339. *
  3340. * PXA25x or PXA210 ... these use a "usb-eth" driver much like
  3341. * the sa1100 one, but hardware uses different endpoint numbers.
  3342. *
  3343. * Or the Linux "Ethernet" gadget on hardware that can't talk
  3344. * CDC Ethernet (e.g., no altsettings), in either of two modes:
  3345. * - acting just like the old "usb-eth" firmware, though
  3346. * the implementation is different
  3347. * - supporting RNDIS as the first/default configuration for
  3348. * MS-Windows interop; Linux needs to use the other config
  3349. */
  3350. {
  3351. // 1183 = 0x049F, both used as hex values?
  3352. // Compaq "Itsy" vendor/product id
  3353. USB_DEVICE (0x049F, 0x505A), // usb-eth, or compatible
  3354. .driver_info = (unsigned long) &linuxdev_info,
  3355. }, {
  3356. USB_DEVICE (0x0E7E, 0x1001), // G.Mate "Yopy"
  3357. .driver_info = (unsigned long) &yopy_info,
  3358. }, {
  3359. USB_DEVICE (0x8086, 0x07d3), // "blob" bootloader
  3360. .driver_info = (unsigned long) &blob_info,
  3361. }, {
  3362. // Linux Ethernet/RNDIS gadget on pxa210/25x/26x
  3363. // e.g. Gumstix, current OpenZaurus, ...
  3364. USB_DEVICE_VER (0x0525, 0xa4a2, 0x0203, 0x0203),
  3365. .driver_info = (unsigned long) &linuxdev_info,
  3366. },
  3367. #endif
  3368. #if defined(CONFIG_USB_ZAURUS) || defined(CONFIG_USB_CDCETHER)
  3369. /*
  3370. * SA-1100 based Sharp Zaurus ("collie"), or compatible.
  3371. * Same idea as above, but different framing.
  3372. *
  3373. * PXA-2xx based models are also lying-about-cdc.
  3374. * Some models don't even tell the same lies ...
  3375. *
  3376. * NOTE: OpenZaurus versions with 2.6 kernels won't use these entries,
  3377. * unlike the older ones with 2.4 "embedix" kernels.
  3378. *
  3379. * NOTE: These entries do double-duty, serving as blacklist entries
  3380. * whenever Zaurus support isn't enabled, but CDC Ethernet is.
  3381. */
  3382. #define ZAURUS_MASTER_INTERFACE \
  3383. .bInterfaceClass = USB_CLASS_COMM, \
  3384. .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \
  3385. .bInterfaceProtocol = USB_CDC_PROTO_NONE
  3386. {
  3387. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  3388. | USB_DEVICE_ID_MATCH_DEVICE,
  3389. .idVendor = 0x04DD,
  3390. .idProduct = 0x8004,
  3391. ZAURUS_MASTER_INTERFACE,
  3392. .driver_info = ZAURUS_STRONGARM_INFO,
  3393. }, {
  3394. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  3395. | USB_DEVICE_ID_MATCH_DEVICE,
  3396. .idVendor = 0x04DD,
  3397. .idProduct = 0x8005, /* A-300 */
  3398. ZAURUS_MASTER_INTERFACE,
  3399. .driver_info = ZAURUS_PXA_INFO,
  3400. }, {
  3401. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  3402. | USB_DEVICE_ID_MATCH_DEVICE,
  3403. .idVendor = 0x04DD,
  3404. .idProduct = 0x8006, /* B-500/SL-5600 */
  3405. ZAURUS_MASTER_INTERFACE,
  3406. .driver_info = ZAURUS_PXA_INFO,
  3407. }, {
  3408. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  3409. | USB_DEVICE_ID_MATCH_DEVICE,
  3410. .idVendor = 0x04DD,
  3411. .idProduct = 0x8007, /* C-700 */
  3412. ZAURUS_MASTER_INTERFACE,
  3413. .driver_info = ZAURUS_PXA_INFO,
  3414. }, {
  3415. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  3416. | USB_DEVICE_ID_MATCH_DEVICE,
  3417. .idVendor = 0x04DD,
  3418. .idProduct = 0x9031, /* C-750 C-760 */
  3419. ZAURUS_MASTER_INTERFACE,
  3420. .driver_info = ZAURUS_PXA_INFO,
  3421. }, {
  3422. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  3423. | USB_DEVICE_ID_MATCH_DEVICE,
  3424. .idVendor = 0x04DD,
  3425. .idProduct = 0x9032, /* SL-6000 */
  3426. ZAURUS_MASTER_INTERFACE,
  3427. .driver_info = ZAURUS_PXA_INFO,
  3428. }, {
  3429. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  3430. | USB_DEVICE_ID_MATCH_DEVICE,
  3431. .idVendor = 0x04DD,
  3432. /* reported with some C860 units */
  3433. .idProduct = 0x9050, /* C-860 */
  3434. ZAURUS_MASTER_INTERFACE,
  3435. .driver_info = ZAURUS_PXA_INFO,
  3436. },
  3437. #ifdef CONFIG_USB_ZAURUS
  3438. /* At least some (reports vary) PXA units have very different lies
  3439. * about their standards support: they claim to be cell phones with
  3440. * direct access to their radios. (They don't conform to CDC MDLM.)
  3441. */
  3442. {
  3443. USB_INTERFACE_INFO (USB_CLASS_COMM, USB_CDC_SUBCLASS_MDLM,
  3444. USB_CDC_PROTO_NONE),
  3445. .driver_info = (unsigned long) &bogus_mdlm_info,
  3446. },
  3447. #endif
  3448. /* Olympus has some models with a Zaurus-compatible option.
  3449. * R-1000 uses a FreeScale i.MXL cpu (ARMv4T)
  3450. */
  3451. {
  3452. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  3453. | USB_DEVICE_ID_MATCH_DEVICE,
  3454. .idVendor = 0x07B4,
  3455. .idProduct = 0x0F02, /* R-1000 */
  3456. ZAURUS_MASTER_INTERFACE,
  3457. .driver_info = OLYMPUS_MXL_INFO,
  3458. },
  3459. #endif
  3460. #ifdef CONFIG_USB_CDCETHER
  3461. {
  3462. /* CDC Ether uses two interfaces, not necessarily consecutive.
  3463. * We match the main interface, ignoring the optional device
  3464. * class so we could handle devices that aren't exclusively
  3465. * CDC ether.
  3466. *
  3467. * NOTE: this match must come AFTER entries working around
  3468. * bugs/quirks in a given product (like Zaurus, above).
  3469. */
  3470. USB_INTERFACE_INFO (USB_CLASS_COMM, USB_CDC_SUBCLASS_ETHERNET,
  3471. USB_CDC_PROTO_NONE),
  3472. .driver_info = (unsigned long) &cdc_info,
  3473. },
  3474. #endif
  3475. { }, // END
  3476. };
  3477. MODULE_DEVICE_TABLE (usb, products);
  3478. static struct usb_driver usbnet_driver = {
  3479. .owner = THIS_MODULE,
  3480. .name = driver_name,
  3481. .id_table = products,
  3482. .probe = usbnet_probe,
  3483. .disconnect = usbnet_disconnect,
  3484. .suspend = usbnet_suspend,
  3485. .resume = usbnet_resume,
  3486. };
  3487. /* Default ethtool_ops assigned. Devices can override in their bind() routine */
  3488. static struct ethtool_ops usbnet_ethtool_ops = {
  3489. .get_drvinfo = usbnet_get_drvinfo,
  3490. .get_link = usbnet_get_link,
  3491. .get_msglevel = usbnet_get_msglevel,
  3492. .set_msglevel = usbnet_set_msglevel,
  3493. };
  3494. /*-------------------------------------------------------------------------*/
  3495. static int __init usbnet_init(void)
  3496. {
  3497. // compiler should optimize these out
  3498. BUG_ON (sizeof (((struct sk_buff *)0)->cb)
  3499. < sizeof (struct skb_data));
  3500. #ifdef CONFIG_USB_CDCETHER
  3501. BUG_ON ((sizeof (((struct usbnet *)0)->data)
  3502. < sizeof (struct cdc_state)));
  3503. #endif
  3504. random_ether_addr(node_id);
  3505. return usb_register(&usbnet_driver);
  3506. }
  3507. module_init(usbnet_init);
  3508. static void __exit usbnet_exit(void)
  3509. {
  3510. usb_deregister(&usbnet_driver);
  3511. }
  3512. module_exit(usbnet_exit);
  3513. MODULE_AUTHOR("David Brownell");
  3514. MODULE_DESCRIPTION("USB Host-to-Host Link Drivers (numerous vendors)");
  3515. MODULE_LICENSE("GPL");