usbnet.c 109 KB

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