usbnet.c 110 KB

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