usbnet.c 113 KB

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