usbnet.c 113 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243
  1. /*
  2. * USB Networking Links
  3. * Copyright (C) 2000-2005 by David Brownell <dbrownell@users.sourceforge.net>
  4. * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz>
  5. * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
  6. * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
  7. * Copyright (c) 2002-2003 TiVo Inc.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. /*
  24. * This is a generic "USB networking" framework that works with several
  25. * kinds of full and high speed networking devices:
  26. *
  27. * + USB host-to-host "network cables", used for IP-over-USB links.
  28. * These are often used for Laplink style connectivity products.
  29. * - AnchorChip 2720
  30. * - Belkin, eTEK (interops with Win32 drivers)
  31. * - GeneSys GL620USB-A
  32. * - NetChip 1080 (interoperates with NetChip Win32 drivers)
  33. * - Prolific PL-2301/2302 (replaces "plusb" driver)
  34. * - KC Technology KC2190
  35. *
  36. * + Smart USB devices can support such links directly, using Internet
  37. * standard protocols instead of proprietary host-to-device links.
  38. * - Linux PDAs like iPaq, Yopy, and Zaurus
  39. * - The BLOB boot loader (for diskless booting)
  40. * - Linux "gadgets", perhaps using PXA-2xx or Net2280 controllers
  41. * - Devices using EPSON's sample USB firmware
  42. * - CDC-Ethernet class devices, such as many cable modems
  43. *
  44. * + Adapters to networks such as Ethernet.
  45. * - AX8817X based USB 2.0 products
  46. *
  47. * Links to these devices can be bridged using Linux Ethernet bridging.
  48. * With minor exceptions, these all use similar USB framing for network
  49. * traffic, but need different protocols for control traffic.
  50. *
  51. * USB devices can implement their side of this protocol at the cost
  52. * of two bulk endpoints; it's not restricted to "cable" applications.
  53. * See the SA1110, Zaurus, or EPSON device/client support in this driver;
  54. * slave/target drivers such as "usb-eth" (on most SA-1100 PDAs) or
  55. * "g_ether" (in the Linux "gadget" framework) implement that behavior
  56. * within devices.
  57. *
  58. *
  59. * CHANGELOG:
  60. *
  61. * 13-sep-2000 experimental, new
  62. * 10-oct-2000 usb_device_id table created.
  63. * 28-oct-2000 misc fixes; mostly, discard more TTL-mangled rx packets.
  64. * 01-nov-2000 usb_device_id table and probing api update by
  65. * Adam J. Richter <adam@yggdrasil.com>.
  66. * 18-dec-2000 (db) tx watchdog, "net1080" renaming to "usbnet", device_info
  67. * and prolific support, isolate net1080-specific bits, cleanup.
  68. * fix unlink_urbs oops in D3 PM resume code path.
  69. *
  70. * 02-feb-2001 (db) fix tx skb sharing, packet length, match_flags, ...
  71. * 08-feb-2001 stubbed in "linuxdev", maybe the SA-1100 folk can use it;
  72. * AnchorChips 2720 support (from spec) for testing;
  73. * fix bit-ordering problem with ethernet multicast addr
  74. * 19-feb-2001 Support for clearing halt conditions. SA1100 UDC support
  75. * updates. Oleg Drokin (green@iXcelerator.com)
  76. * 25-mar-2001 More SA-1100 updates, including workaround for ip problem
  77. * expecting cleared skb->cb and framing change to match latest
  78. * handhelds.org version (Oleg). Enable device IDs from the
  79. * Win32 Belkin driver; other cleanups (db).
  80. * 16-jul-2001 Bugfixes for uhci oops-on-unplug, Belkin support, various
  81. * cleanups for problems not yet seen in the field. (db)
  82. * 17-oct-2001 Handle "Advance USBNET" product, like Belkin/eTEK devices,
  83. * from Ioannis Mavroukakis <i.mavroukakis@btinternet.com>;
  84. * rx unlinks somehow weren't async; minor cleanup.
  85. * 03-nov-2001 Merged GeneSys driver; original code from Jiun-Jie Huang
  86. * <huangjj@genesyslogic.com.tw>, updated by Stanislav Brabec
  87. * <utx@penguin.cz>. Made framing options (NetChip/GeneSys)
  88. * tie mostly to (sub)driver info. Workaround some PL-2302
  89. * chips that seem to reject SET_INTERFACE requests.
  90. *
  91. * 06-apr-2002 Added ethtool support, based on a patch from Brad Hards.
  92. * Level of diagnostics is more configurable; they use device
  93. * location (usb_device->devpath) instead of address (2.5).
  94. * For tx_fixup, memflags can't be NOIO.
  95. * 07-may-2002 Generalize/cleanup keventd support, handling rx stalls (mostly
  96. * for USB 2.0 TTs) and memory shortages (potential) too. (db)
  97. * Use "locally assigned" IEEE802 address space. (Brad Hards)
  98. * 18-oct-2002 Support for Zaurus (Pavel Machek), related cleanup (db).
  99. * 14-dec-2002 Remove Zaurus-private crc32 code (Pavel); 2.5 oops fix,
  100. * cleanups and stubbed PXA-250 support (db), fix for framing
  101. * issues on Z, net1080, and gl620a (Toby Milne)
  102. *
  103. * 31-mar-2003 Use endpoint descriptors: high speed support, simpler sa1100
  104. * vs pxa25x, and CDC Ethernet. Throttle down log floods on
  105. * disconnect; other cleanups. (db) Flush net1080 fifos
  106. * after several sequential framing errors. (Johannes Erdfelt)
  107. * 22-aug-2003 AX8817X support (Dave Hollis).
  108. * 14-jun-2004 Trivial patch for AX8817X based Buffalo LUA-U2-KTX in Japan
  109. * (Neil Bortnak)
  110. * 03-nov-2004 Trivial patch for KC2190 (KC-190) chip. (Jonathan McDowell)
  111. *
  112. * 01-feb-2005 AX88772 support (Phil Chang & Dave Hollis)
  113. *-------------------------------------------------------------------------*/
  114. // #define DEBUG // error path messages, extra info
  115. // #define VERBOSE // more; success messages
  116. #include <linux/config.h>
  117. #ifdef CONFIG_USB_DEBUG
  118. # define DEBUG
  119. #endif
  120. #include <linux/module.h>
  121. #include <linux/kmod.h>
  122. #include <linux/sched.h>
  123. #include <linux/init.h>
  124. #include <linux/netdevice.h>
  125. #include <linux/etherdevice.h>
  126. #include <linux/random.h>
  127. #include <linux/ethtool.h>
  128. #include <linux/workqueue.h>
  129. #include <linux/mii.h>
  130. #include <asm/uaccess.h>
  131. #include <asm/unaligned.h>
  132. #include <linux/usb.h>
  133. #include <asm/io.h>
  134. #include <asm/scatterlist.h>
  135. #include <linux/mm.h>
  136. #include <linux/dma-mapping.h>
  137. #define DRIVER_VERSION "03-Nov-2004"
  138. /*-------------------------------------------------------------------------*/
  139. /*
  140. * Nineteen USB 1.1 max size bulk transactions per frame (ms), max.
  141. * Several dozen bytes of IPv4 data can fit in two such transactions.
  142. * One maximum size Ethernet packet takes twenty four of them.
  143. * For high speed, each frame comfortably fits almost 36 max size
  144. * Ethernet packets (so queues should be bigger).
  145. */
  146. #define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
  147. #define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
  148. // packets are always ethernet inside
  149. // ... except they can be bigger (limit of 64K with NetChip framing)
  150. #define MIN_PACKET sizeof(struct ethhdr)
  151. #define MAX_PACKET 32768
  152. // reawaken network queue this soon after stopping; else watchdog barks
  153. #define TX_TIMEOUT_JIFFIES (5*HZ)
  154. // throttle rx/tx briefly after some faults, so khubd might disconnect()
  155. // us (it polls at HZ/4 usually) before we report too many false errors.
  156. #define THROTTLE_JIFFIES (HZ/8)
  157. // for vendor-specific control operations
  158. #define CONTROL_TIMEOUT_MS 500
  159. // between wakeups
  160. #define UNLINK_TIMEOUT_MS 3
  161. /*-------------------------------------------------------------------------*/
  162. // randomly generated ethernet address
  163. static u8 node_id [ETH_ALEN];
  164. // state we keep for each device we handle
  165. struct usbnet {
  166. // housekeeping
  167. struct usb_device *udev;
  168. struct driver_info *driver_info;
  169. wait_queue_head_t *wait;
  170. // i/o info: pipes etc
  171. unsigned in, out;
  172. struct usb_host_endpoint *status;
  173. unsigned maxpacket;
  174. struct timer_list delay;
  175. // protocol/interface state
  176. struct net_device *net;
  177. struct net_device_stats stats;
  178. int msg_enable;
  179. unsigned long data [5];
  180. struct mii_if_info mii;
  181. // various kinds of pending driver work
  182. struct sk_buff_head rxq;
  183. struct sk_buff_head txq;
  184. struct sk_buff_head done;
  185. struct urb *interrupt;
  186. struct tasklet_struct bh;
  187. struct work_struct kevent;
  188. unsigned long flags;
  189. # define EVENT_TX_HALT 0
  190. # define EVENT_RX_HALT 1
  191. # define EVENT_RX_MEMORY 2
  192. # define EVENT_STS_SPLIT 3
  193. # define EVENT_LINK_RESET 4
  194. };
  195. // device-specific info used by the driver
  196. struct driver_info {
  197. char *description;
  198. int flags;
  199. /* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */
  200. #define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */
  201. #define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */
  202. #define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */
  203. #define FLAG_FRAMING_RN 0x0008 /* RNDIS batches, plus huge header */
  204. #define FLAG_NO_SETINT 0x0010 /* device can't set_interface() */
  205. #define FLAG_ETHER 0x0020 /* maybe use "eth%d" names */
  206. #define FLAG_FRAMING_AX 0x0040 /* AX88772/178 packets */
  207. /* init device ... can sleep, or cause probe() failure */
  208. int (*bind)(struct usbnet *, struct usb_interface *);
  209. /* cleanup device ... can sleep, but can't fail */
  210. void (*unbind)(struct usbnet *, struct usb_interface *);
  211. /* reset device ... can sleep */
  212. int (*reset)(struct usbnet *);
  213. /* see if peer is connected ... can sleep */
  214. int (*check_connect)(struct usbnet *);
  215. /* for status polling */
  216. void (*status)(struct usbnet *, struct urb *);
  217. /* link reset handling, called from defer_kevent */
  218. int (*link_reset)(struct usbnet *);
  219. /* fixup rx packet (strip framing) */
  220. int (*rx_fixup)(struct usbnet *dev, struct sk_buff *skb);
  221. /* fixup tx packet (add framing) */
  222. struct sk_buff *(*tx_fixup)(struct usbnet *dev,
  223. struct sk_buff *skb, int flags);
  224. // FIXME -- also an interrupt mechanism
  225. // useful for at least PL2301/2302 and GL620USB-A
  226. // and CDC use them to report 'is it connected' changes
  227. /* for new devices, use the descriptor-reading code instead */
  228. int in; /* rx endpoint */
  229. int out; /* tx endpoint */
  230. unsigned long data; /* Misc driver specific data */
  231. };
  232. // we record the state for each of our queued skbs
  233. enum skb_state {
  234. illegal = 0,
  235. tx_start, tx_done,
  236. rx_start, rx_done, rx_cleanup
  237. };
  238. struct skb_data { // skb->cb is one of these
  239. struct urb *urb;
  240. struct usbnet *dev;
  241. enum skb_state state;
  242. size_t length;
  243. };
  244. static const char driver_name [] = "usbnet";
  245. /* use ethtool to change the level for any given device */
  246. static int msg_level = -1;
  247. module_param (msg_level, int, 0);
  248. MODULE_PARM_DESC (msg_level, "Override default message level");
  249. #ifdef DEBUG
  250. #define devdbg(usbnet, fmt, arg...) \
  251. printk(KERN_DEBUG "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
  252. #else
  253. #define devdbg(usbnet, fmt, arg...) do {} while(0)
  254. #endif
  255. #define deverr(usbnet, fmt, arg...) \
  256. printk(KERN_ERR "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
  257. #define devwarn(usbnet, fmt, arg...) \
  258. printk(KERN_WARNING "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
  259. #define devinfo(usbnet, fmt, arg...) \
  260. printk(KERN_INFO "%s: " fmt "\n" , (usbnet)->net->name , ## arg); \
  261. /*-------------------------------------------------------------------------*/
  262. static void usbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *);
  263. static u32 usbnet_get_link (struct net_device *);
  264. static u32 usbnet_get_msglevel (struct net_device *);
  265. static void usbnet_set_msglevel (struct net_device *, u32);
  266. static void defer_kevent (struct usbnet *, int);
  267. /* mostly for PDA style devices, which are always connected if present */
  268. static int always_connected (struct usbnet *dev)
  269. {
  270. return 0;
  271. }
  272. /* handles CDC Ethernet and many other network "bulk data" interfaces */
  273. static int
  274. get_endpoints (struct usbnet *dev, struct usb_interface *intf)
  275. {
  276. int tmp;
  277. struct usb_host_interface *alt = NULL;
  278. struct usb_host_endpoint *in = NULL, *out = NULL;
  279. struct usb_host_endpoint *status = NULL;
  280. for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
  281. unsigned ep;
  282. in = out = status = NULL;
  283. alt = intf->altsetting + tmp;
  284. /* take the first altsetting with in-bulk + out-bulk;
  285. * remember any status endpoint, just in case;
  286. * ignore other endpoints and altsetttings.
  287. */
  288. for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
  289. struct usb_host_endpoint *e;
  290. int intr = 0;
  291. e = alt->endpoint + ep;
  292. switch (e->desc.bmAttributes) {
  293. case USB_ENDPOINT_XFER_INT:
  294. if (!(e->desc.bEndpointAddress & USB_DIR_IN))
  295. continue;
  296. intr = 1;
  297. /* FALLTHROUGH */
  298. case USB_ENDPOINT_XFER_BULK:
  299. break;
  300. default:
  301. continue;
  302. }
  303. if (e->desc.bEndpointAddress & USB_DIR_IN) {
  304. if (!intr && !in)
  305. in = e;
  306. else if (intr && !status)
  307. status = e;
  308. } else {
  309. if (!out)
  310. out = e;
  311. }
  312. }
  313. if (in && out)
  314. break;
  315. }
  316. if (!alt || !in || !out)
  317. return -EINVAL;
  318. if (alt->desc.bAlternateSetting != 0
  319. || !(dev->driver_info->flags & FLAG_NO_SETINT)) {
  320. tmp = usb_set_interface (dev->udev, alt->desc.bInterfaceNumber,
  321. alt->desc.bAlternateSetting);
  322. if (tmp < 0)
  323. return tmp;
  324. }
  325. dev->in = usb_rcvbulkpipe (dev->udev,
  326. in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
  327. dev->out = usb_sndbulkpipe (dev->udev,
  328. out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
  329. dev->status = status;
  330. return 0;
  331. }
  332. static void intr_complete (struct urb *urb, struct pt_regs *regs);
  333. static int init_status (struct usbnet *dev, struct usb_interface *intf)
  334. {
  335. char *buf = NULL;
  336. unsigned pipe = 0;
  337. unsigned maxp;
  338. unsigned period;
  339. if (!dev->driver_info->status)
  340. return 0;
  341. pipe = usb_rcvintpipe (dev->udev,
  342. dev->status->desc.bEndpointAddress
  343. & USB_ENDPOINT_NUMBER_MASK);
  344. maxp = usb_maxpacket (dev->udev, pipe, 0);
  345. /* avoid 1 msec chatter: min 8 msec poll rate */
  346. period = max ((int) dev->status->desc.bInterval,
  347. (dev->udev->speed == USB_SPEED_HIGH) ? 7 : 3);
  348. buf = kmalloc (maxp, SLAB_KERNEL);
  349. if (buf) {
  350. dev->interrupt = usb_alloc_urb (0, SLAB_KERNEL);
  351. if (!dev->interrupt) {
  352. kfree (buf);
  353. return -ENOMEM;
  354. } else {
  355. usb_fill_int_urb(dev->interrupt, dev->udev, pipe,
  356. buf, maxp, intr_complete, dev, period);
  357. dev_dbg(&intf->dev,
  358. "status ep%din, %d bytes period %d\n",
  359. usb_pipeendpoint(pipe), maxp, period);
  360. }
  361. }
  362. return 0;
  363. }
  364. static void skb_return (struct usbnet *dev, struct sk_buff *skb)
  365. {
  366. int status;
  367. skb->dev = dev->net;
  368. skb->protocol = eth_type_trans (skb, dev->net);
  369. dev->stats.rx_packets++;
  370. dev->stats.rx_bytes += skb->len;
  371. if (netif_msg_rx_status (dev))
  372. devdbg (dev, "< rx, len %zu, type 0x%x",
  373. skb->len + sizeof (struct ethhdr), skb->protocol);
  374. memset (skb->cb, 0, sizeof (struct skb_data));
  375. status = netif_rx (skb);
  376. if (status != NET_RX_SUCCESS && netif_msg_rx_err (dev))
  377. devdbg (dev, "netif_rx status %d", status);
  378. }
  379. #ifdef CONFIG_USB_ALI_M5632
  380. #define HAVE_HARDWARE
  381. /*-------------------------------------------------------------------------
  382. *
  383. * ALi M5632 driver ... does high speed
  384. *
  385. *-------------------------------------------------------------------------*/
  386. static const struct driver_info ali_m5632_info = {
  387. .description = "ALi M5632",
  388. };
  389. #endif
  390. #ifdef CONFIG_USB_AN2720
  391. #define HAVE_HARDWARE
  392. /*-------------------------------------------------------------------------
  393. *
  394. * AnchorChips 2720 driver ... http://www.cypress.com
  395. *
  396. * This doesn't seem to have a way to detect whether the peer is
  397. * connected, or need any reset handshaking. It's got pretty big
  398. * internal buffers (handles most of a frame's worth of data).
  399. * Chip data sheets don't describe any vendor control messages.
  400. *
  401. *-------------------------------------------------------------------------*/
  402. static const struct driver_info an2720_info = {
  403. .description = "AnchorChips/Cypress 2720",
  404. // no reset available!
  405. // no check_connect available!
  406. .in = 2, .out = 2, // direction distinguishes these
  407. };
  408. #endif /* CONFIG_USB_AN2720 */
  409. #ifdef CONFIG_USB_AX8817X
  410. /* ASIX AX8817X based USB 2.0 Ethernet Devices */
  411. #define HAVE_HARDWARE
  412. #define NEED_MII
  413. #include <linux/crc32.h>
  414. #define AX_CMD_SET_SW_MII 0x06
  415. #define AX_CMD_READ_MII_REG 0x07
  416. #define AX_CMD_WRITE_MII_REG 0x08
  417. #define AX_CMD_SET_HW_MII 0x0a
  418. #define AX_CMD_READ_EEPROM 0x0b
  419. #define AX_CMD_WRITE_EEPROM 0x0c
  420. #define AX_CMD_WRITE_ENABLE 0x0d
  421. #define AX_CMD_WRITE_DISABLE 0x0e
  422. #define AX_CMD_WRITE_RX_CTL 0x10
  423. #define AX_CMD_READ_IPG012 0x11
  424. #define AX_CMD_WRITE_IPG0 0x12
  425. #define AX_CMD_WRITE_IPG1 0x13
  426. #define AX_CMD_WRITE_IPG2 0x14
  427. #define AX_CMD_WRITE_MULTI_FILTER 0x16
  428. #define AX_CMD_READ_NODE_ID 0x17
  429. #define AX_CMD_READ_PHY_ID 0x19
  430. #define AX_CMD_READ_MEDIUM_STATUS 0x1a
  431. #define AX_CMD_WRITE_MEDIUM_MODE 0x1b
  432. #define AX_CMD_READ_MONITOR_MODE 0x1c
  433. #define AX_CMD_WRITE_MONITOR_MODE 0x1d
  434. #define AX_CMD_WRITE_GPIOS 0x1f
  435. #define AX_CMD_SW_RESET 0x20
  436. #define AX_CMD_SW_PHY_STATUS 0x21
  437. #define AX_CMD_SW_PHY_SELECT 0x22
  438. #define AX88772_CMD_READ_NODE_ID 0x13
  439. #define AX_MONITOR_MODE 0x01
  440. #define AX_MONITOR_LINK 0x02
  441. #define AX_MONITOR_MAGIC 0x04
  442. #define AX_MONITOR_HSFS 0x10
  443. /* AX88172 Medium Status Register values */
  444. #define AX_MEDIUM_FULL_DUPLEX 0x02
  445. #define AX_MEDIUM_TX_ABORT_ALLOW 0x04
  446. #define AX_MEDIUM_FLOW_CONTROL_EN 0x10
  447. #define AX_MCAST_FILTER_SIZE 8
  448. #define AX_MAX_MCAST 64
  449. #define AX_EEPROM_LEN 0x40
  450. #define AX_SWRESET_CLEAR 0x00
  451. #define AX_SWRESET_RR 0x01
  452. #define AX_SWRESET_RT 0x02
  453. #define AX_SWRESET_PRTE 0x04
  454. #define AX_SWRESET_PRL 0x08
  455. #define AX_SWRESET_BZ 0x10
  456. #define AX_SWRESET_IPRL 0x20
  457. #define AX_SWRESET_IPPD 0x40
  458. #define AX88772_IPG0_DEFAULT 0x15
  459. #define AX88772_IPG1_DEFAULT 0x0c
  460. #define AX88772_IPG2_DEFAULT 0x12
  461. #define AX88772_MEDIUM_FULL_DUPLEX 0x0002
  462. #define AX88772_MEDIUM_RESERVED 0x0004
  463. #define AX88772_MEDIUM_RX_FC_ENABLE 0x0010
  464. #define AX88772_MEDIUM_TX_FC_ENABLE 0x0020
  465. #define AX88772_MEDIUM_PAUSE_FORMAT 0x0080
  466. #define AX88772_MEDIUM_RX_ENABLE 0x0100
  467. #define AX88772_MEDIUM_100MB 0x0200
  468. #define AX88772_MEDIUM_DEFAULT \
  469. (AX88772_MEDIUM_FULL_DUPLEX | AX88772_MEDIUM_RX_FC_ENABLE | \
  470. AX88772_MEDIUM_TX_FC_ENABLE | AX88772_MEDIUM_100MB | \
  471. AX88772_MEDIUM_RESERVED | AX88772_MEDIUM_RX_ENABLE )
  472. #define AX_EEPROM_MAGIC 0xdeadbeef
  473. /* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
  474. struct ax8817x_data {
  475. u8 multi_filter[AX_MCAST_FILTER_SIZE];
  476. };
  477. struct ax88172_int_data {
  478. u16 res1;
  479. u8 link;
  480. u16 res2;
  481. u8 status;
  482. u16 res3;
  483. } __attribute__ ((packed));
  484. static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
  485. u16 size, void *data)
  486. {
  487. return usb_control_msg(
  488. dev->udev,
  489. usb_rcvctrlpipe(dev->udev, 0),
  490. cmd,
  491. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  492. value,
  493. index,
  494. data,
  495. size,
  496. CONTROL_TIMEOUT_MS);
  497. }
  498. static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
  499. u16 size, void *data)
  500. {
  501. return usb_control_msg(
  502. dev->udev,
  503. usb_sndctrlpipe(dev->udev, 0),
  504. cmd,
  505. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  506. value,
  507. index,
  508. data,
  509. size,
  510. CONTROL_TIMEOUT_MS);
  511. }
  512. static void ax8817x_async_cmd_callback(struct urb *urb, struct pt_regs *regs)
  513. {
  514. struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
  515. if (urb->status < 0)
  516. printk(KERN_DEBUG "ax8817x_async_cmd_callback() failed with %d",
  517. urb->status);
  518. kfree(req);
  519. usb_free_urb(urb);
  520. }
  521. static void ax8817x_status(struct usbnet *dev, struct urb *urb)
  522. {
  523. struct ax88172_int_data *event;
  524. int link;
  525. if (urb->actual_length < 8)
  526. return;
  527. event = urb->transfer_buffer;
  528. link = event->link & 0x01;
  529. if (netif_carrier_ok(dev->net) != link) {
  530. if (link) {
  531. netif_carrier_on(dev->net);
  532. defer_kevent (dev, EVENT_LINK_RESET );
  533. } else
  534. netif_carrier_off(dev->net);
  535. devdbg(dev, "ax8817x - Link Status is: %d", link);
  536. }
  537. }
  538. static void ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
  539. u16 size, void *data)
  540. {
  541. struct usb_ctrlrequest *req;
  542. int status;
  543. struct urb *urb;
  544. if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) {
  545. devdbg(dev, "Error allocating URB in write_cmd_async!");
  546. return;
  547. }
  548. if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) {
  549. deverr(dev, "Failed to allocate memory for control request");
  550. usb_free_urb(urb);
  551. return;
  552. }
  553. req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
  554. req->bRequest = cmd;
  555. req->wValue = cpu_to_le16(value);
  556. req->wIndex = cpu_to_le16(index);
  557. req->wLength = cpu_to_le16(size);
  558. usb_fill_control_urb(urb, dev->udev,
  559. usb_sndctrlpipe(dev->udev, 0),
  560. (void *)req, data, size,
  561. ax8817x_async_cmd_callback, req);
  562. if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
  563. deverr(dev, "Error submitting the control message: status=%d", status);
  564. kfree(req);
  565. usb_free_urb(urb);
  566. }
  567. }
  568. static void ax8817x_set_multicast(struct net_device *net)
  569. {
  570. struct usbnet *dev = netdev_priv(net);
  571. struct ax8817x_data *data = (struct ax8817x_data *)&dev->data;
  572. u8 rx_ctl = 0x8c;
  573. if (net->flags & IFF_PROMISC) {
  574. rx_ctl |= 0x01;
  575. } else if (net->flags & IFF_ALLMULTI
  576. || net->mc_count > AX_MAX_MCAST) {
  577. rx_ctl |= 0x02;
  578. } else if (net->mc_count == 0) {
  579. /* just broadcast and directed */
  580. } else {
  581. /* We use the 20 byte dev->data
  582. * for our 8 byte filter buffer
  583. * to avoid allocating memory that
  584. * is tricky to free later */
  585. struct dev_mc_list *mc_list = net->mc_list;
  586. u32 crc_bits;
  587. int i;
  588. memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
  589. /* Build the multicast hash filter. */
  590. for (i = 0; i < net->mc_count; i++) {
  591. crc_bits =
  592. ether_crc(ETH_ALEN,
  593. mc_list->dmi_addr) >> 26;
  594. data->multi_filter[crc_bits >> 3] |=
  595. 1 << (crc_bits & 7);
  596. mc_list = mc_list->next;
  597. }
  598. ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
  599. AX_MCAST_FILTER_SIZE, data->multi_filter);
  600. rx_ctl |= 0x10;
  601. }
  602. ax8817x_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
  603. }
  604. static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc)
  605. {
  606. struct usbnet *dev = netdev_priv(netdev);
  607. u16 res;
  608. u8 buf[1];
  609. ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
  610. ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
  611. ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
  612. return res & 0xffff;
  613. }
  614. static void ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
  615. {
  616. struct usbnet *dev = netdev_priv(netdev);
  617. u16 res = val;
  618. u8 buf[1];
  619. ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
  620. ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
  621. ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
  622. }
  623. static int ax88172_link_reset(struct usbnet *dev)
  624. {
  625. u16 lpa;
  626. u8 mode;
  627. mode = AX_MEDIUM_TX_ABORT_ALLOW | AX_MEDIUM_FLOW_CONTROL_EN;
  628. lpa = ax8817x_mdio_read(dev->net, dev->mii.phy_id, MII_LPA);
  629. if (lpa & LPA_DUPLEX)
  630. mode |= AX_MEDIUM_FULL_DUPLEX;
  631. ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
  632. return 0;
  633. }
  634. static void ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
  635. {
  636. struct usbnet *dev = netdev_priv(net);
  637. u8 opt;
  638. if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
  639. wolinfo->supported = 0;
  640. wolinfo->wolopts = 0;
  641. return;
  642. }
  643. wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
  644. wolinfo->wolopts = 0;
  645. if (opt & AX_MONITOR_MODE) {
  646. if (opt & AX_MONITOR_LINK)
  647. wolinfo->wolopts |= WAKE_PHY;
  648. if (opt & AX_MONITOR_MAGIC)
  649. wolinfo->wolopts |= WAKE_MAGIC;
  650. }
  651. }
  652. static int ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
  653. {
  654. struct usbnet *dev = netdev_priv(net);
  655. u8 opt = 0;
  656. u8 buf[1];
  657. if (wolinfo->wolopts & WAKE_PHY)
  658. opt |= AX_MONITOR_LINK;
  659. if (wolinfo->wolopts & WAKE_MAGIC)
  660. opt |= AX_MONITOR_MAGIC;
  661. if (opt != 0)
  662. opt |= AX_MONITOR_MODE;
  663. if (ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
  664. opt, 0, 0, &buf) < 0)
  665. return -EINVAL;
  666. return 0;
  667. }
  668. static int ax8817x_get_eeprom_len(struct net_device *net)
  669. {
  670. return AX_EEPROM_LEN;
  671. }
  672. static int ax8817x_get_eeprom(struct net_device *net,
  673. struct ethtool_eeprom *eeprom, u8 *data)
  674. {
  675. struct usbnet *dev = netdev_priv(net);
  676. u16 *ebuf = (u16 *)data;
  677. int i;
  678. /* Crude hack to ensure that we don't overwrite memory
  679. * if an odd length is supplied
  680. */
  681. if (eeprom->len % 2)
  682. return -EINVAL;
  683. eeprom->magic = AX_EEPROM_MAGIC;
  684. /* ax8817x returns 2 bytes from eeprom on read */
  685. for (i=0; i < eeprom->len / 2; i++) {
  686. if (ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM,
  687. eeprom->offset + i, 0, 2, &ebuf[i]) < 0)
  688. return -EINVAL;
  689. }
  690. return 0;
  691. }
  692. static void ax8817x_get_drvinfo (struct net_device *net,
  693. struct ethtool_drvinfo *info)
  694. {
  695. /* Inherit standard device info */
  696. usbnet_get_drvinfo(net, info);
  697. info->eedump_len = 0x3e;
  698. }
  699. static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
  700. {
  701. struct usbnet *dev = netdev_priv(net);
  702. return mii_ethtool_gset(&dev->mii,cmd);
  703. }
  704. static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
  705. {
  706. struct usbnet *dev = netdev_priv(net);
  707. return mii_ethtool_sset(&dev->mii,cmd);
  708. }
  709. /* We need to override some ethtool_ops so we require our
  710. own structure so we don't interfere with other usbnet
  711. devices that may be connected at the same time. */
  712. static struct ethtool_ops ax8817x_ethtool_ops = {
  713. .get_drvinfo = ax8817x_get_drvinfo,
  714. .get_link = ethtool_op_get_link,
  715. .get_msglevel = usbnet_get_msglevel,
  716. .set_msglevel = usbnet_set_msglevel,
  717. .get_wol = ax8817x_get_wol,
  718. .set_wol = ax8817x_set_wol,
  719. .get_eeprom_len = ax8817x_get_eeprom_len,
  720. .get_eeprom = ax8817x_get_eeprom,
  721. .get_settings = ax8817x_get_settings,
  722. .set_settings = ax8817x_set_settings,
  723. };
  724. static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf)
  725. {
  726. int ret = 0;
  727. void *buf;
  728. int i;
  729. unsigned long gpio_bits = dev->driver_info->data;
  730. get_endpoints(dev,intf);
  731. buf = kmalloc(ETH_ALEN, GFP_KERNEL);
  732. if(!buf) {
  733. ret = -ENOMEM;
  734. goto out1;
  735. }
  736. /* Toggle the GPIOs in a manufacturer/model specific way */
  737. for (i = 2; i >= 0; i--) {
  738. if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS,
  739. (gpio_bits >> (i * 8)) & 0xff, 0, 0,
  740. buf)) < 0)
  741. goto out2;
  742. msleep(5);
  743. }
  744. if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x80, 0, 0, buf)) < 0) {
  745. dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret);
  746. goto out2;
  747. }
  748. /* Get the MAC address */
  749. memset(buf, 0, ETH_ALEN);
  750. if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, 6, buf)) < 0) {
  751. dbg("read AX_CMD_READ_NODE_ID failed: %d", ret);
  752. goto out2;
  753. }
  754. memcpy(dev->net->dev_addr, buf, ETH_ALEN);
  755. /* Get the PHY id */
  756. if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) {
  757. dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret);
  758. goto out2;
  759. } else if (ret < 2) {
  760. /* this should always return 2 bytes */
  761. dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", ret);
  762. ret = -EIO;
  763. goto out2;
  764. }
  765. /* Initialize MII structure */
  766. dev->mii.dev = dev->net;
  767. dev->mii.mdio_read = ax8817x_mdio_read;
  768. dev->mii.mdio_write = ax8817x_mdio_write;
  769. dev->mii.phy_id_mask = 0x3f;
  770. dev->mii.reg_num_mask = 0x1f;
  771. dev->mii.phy_id = *((u8 *)buf + 1);
  772. dev->net->set_multicast_list = ax8817x_set_multicast;
  773. dev->net->ethtool_ops = &ax8817x_ethtool_ops;
  774. ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
  775. ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
  776. ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
  777. mii_nway_restart(&dev->mii);
  778. return 0;
  779. out2:
  780. kfree(buf);
  781. out1:
  782. return ret;
  783. }
  784. static struct ethtool_ops ax88772_ethtool_ops = {
  785. .get_drvinfo = ax8817x_get_drvinfo,
  786. .get_link = ethtool_op_get_link,
  787. .get_msglevel = usbnet_get_msglevel,
  788. .set_msglevel = usbnet_set_msglevel,
  789. .get_wol = ax8817x_get_wol,
  790. .set_wol = ax8817x_set_wol,
  791. .get_eeprom_len = ax8817x_get_eeprom_len,
  792. .get_eeprom = ax8817x_get_eeprom,
  793. .get_settings = ax8817x_get_settings,
  794. .set_settings = ax8817x_set_settings,
  795. };
  796. static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
  797. {
  798. int ret;
  799. void *buf;
  800. get_endpoints(dev,intf);
  801. buf = kmalloc(6, GFP_KERNEL);
  802. if(!buf) {
  803. dbg ("Cannot allocate memory for buffer");
  804. ret = -ENOMEM;
  805. goto out1;
  806. }
  807. if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS,
  808. 0x00B0, 0, 0, buf)) < 0)
  809. goto out2;
  810. msleep(5);
  811. if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 0x0001, 0, 0, buf)) < 0) {
  812. dbg("Select PHY #1 failed: %d", ret);
  813. goto out2;
  814. }
  815. if ((ret =
  816. ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPPD, 0, 0, buf)) < 0) {
  817. dbg("Failed to power down internal PHY: %d", ret);
  818. goto out2;
  819. }
  820. msleep(150);
  821. if ((ret =
  822. ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_CLEAR, 0, 0, buf)) < 0) {
  823. dbg("Failed to perform software reset: %d", ret);
  824. goto out2;
  825. }
  826. msleep(150);
  827. if ((ret =
  828. ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL | AX_SWRESET_PRL, 0, 0, buf)) < 0) {
  829. dbg("Failed to set Internal/External PHY reset control: %d", ret);
  830. goto out2;
  831. }
  832. msleep(150);
  833. if ((ret =
  834. ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0000, 0, 0,
  835. buf)) < 0) {
  836. dbg("Failed to reset RX_CTL: %d", ret);
  837. goto out2;
  838. }
  839. /* Get the MAC address */
  840. memset(buf, 0, ETH_ALEN);
  841. if ((ret = ax8817x_read_cmd(dev, AX88772_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf)) < 0) {
  842. dbg("Failed to read MAC address: %d", ret);
  843. goto out2;
  844. }
  845. memcpy(dev->net->dev_addr, buf, ETH_ALEN);
  846. if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, buf)) < 0) {
  847. dbg("Enabling software MII failed: %d", ret);
  848. goto out2;
  849. }
  850. if (((ret =
  851. ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, 0x0010, 2, 2, buf)) < 0)
  852. || (*((u16 *)buf) != 0x003b)) {
  853. dbg("Read PHY register 2 must be 0x3b00: %d", ret);
  854. goto out2;
  855. }
  856. /* Initialize MII structure */
  857. dev->mii.dev = dev->net;
  858. dev->mii.mdio_read = ax8817x_mdio_read;
  859. dev->mii.mdio_write = ax8817x_mdio_write;
  860. dev->mii.phy_id_mask = 0xff;
  861. dev->mii.reg_num_mask = 0xff;
  862. /* Get the PHY id */
  863. if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) {
  864. dbg("Error reading PHY ID: %02x", ret);
  865. goto out2;
  866. } else if (ret < 2) {
  867. /* this should always return 2 bytes */
  868. dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x",
  869. ret);
  870. ret = -EIO;
  871. goto out2;
  872. }
  873. dev->mii.phy_id = *((u8 *)buf + 1);
  874. if ((ret =
  875. ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_PRL, 0, 0, buf)) < 0) {
  876. dbg("Set external PHY reset pin level: %d", ret);
  877. goto out2;
  878. }
  879. msleep(150);
  880. if ((ret =
  881. ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL | AX_SWRESET_PRL, 0, 0, buf)) < 0) {
  882. dbg("Set Internal/External PHY reset control: %d", ret);
  883. goto out2;
  884. }
  885. msleep(150);
  886. dev->net->set_multicast_list = ax8817x_set_multicast;
  887. dev->net->ethtool_ops = &ax88772_ethtool_ops;
  888. ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
  889. ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
  890. ADVERTISE_ALL | ADVERTISE_CSMA);
  891. mii_nway_restart(&dev->mii);
  892. if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, AX88772_MEDIUM_DEFAULT, 0, 0, buf)) < 0) {
  893. dbg("Write medium mode register: %d", ret);
  894. goto out2;
  895. }
  896. if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_IPG0, AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,AX88772_IPG2_DEFAULT, 0, buf)) < 0) {
  897. dbg("Write IPG,IPG1,IPG2 failed: %d", ret);
  898. goto out2;
  899. }
  900. if ((ret =
  901. ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf)) < 0) {
  902. dbg("Failed to set hardware MII: %02x", ret);
  903. goto out2;
  904. }
  905. /* Set RX_CTL to default values with 2k buffer, and enable cactus */
  906. if ((ret =
  907. ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0088, 0, 0,
  908. buf)) < 0) {
  909. dbg("Reset RX_CTL failed: %d", ret);
  910. goto out2;
  911. }
  912. kfree(buf);
  913. return 0;
  914. out2:
  915. kfree(buf);
  916. out1:
  917. return ret;
  918. }
  919. static int ax88772_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
  920. {
  921. u32 *header;
  922. char *packet;
  923. struct sk_buff *ax_skb;
  924. u16 size;
  925. header = (u32 *) skb->data;
  926. le32_to_cpus(header);
  927. packet = (char *)(header + 1);
  928. skb_pull(skb, 4);
  929. while (skb->len > 0) {
  930. if ((short)(*header & 0x0000ffff) !=
  931. ~((short)((*header & 0xffff0000) >> 16))) {
  932. devdbg(dev,"header length data is error");
  933. }
  934. /* get the packet length */
  935. size = (u16) (*header & 0x0000ffff);
  936. if ((skb->len) - ((size + 1) & 0xfffe) == 0)
  937. return 2;
  938. if (size > ETH_FRAME_LEN) {
  939. devdbg(dev,"invalid rx length %d", size);
  940. return 0;
  941. }
  942. ax_skb = skb_clone(skb, GFP_ATOMIC);
  943. if (ax_skb) {
  944. ax_skb->len = size;
  945. ax_skb->data = packet;
  946. ax_skb->tail = packet + size;
  947. skb_return(dev, ax_skb);
  948. } else {
  949. return 0;
  950. }
  951. skb_pull(skb, (size + 1) & 0xfffe);
  952. if (skb->len == 0)
  953. break;
  954. header = (u32 *) skb->data;
  955. le32_to_cpus(header);
  956. packet = (char *)(header + 1);
  957. skb_pull(skb, 4);
  958. }
  959. if (skb->len < 0) {
  960. devdbg(dev,"invalid rx length %d", skb->len);
  961. return 0;
  962. }
  963. return 1;
  964. }
  965. static struct sk_buff *ax88772_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
  966. int flags)
  967. {
  968. int padlen;
  969. int headroom = skb_headroom(skb);
  970. int tailroom = skb_tailroom(skb);
  971. u32 *packet_len;
  972. u32 *padbytes_ptr;
  973. padlen = ((skb->len + 4) % 512) ? 0 : 4;
  974. if ((!skb_cloned(skb))
  975. && ((headroom + tailroom) >= (4 + padlen))) {
  976. if ((headroom < 4) || (tailroom < padlen)) {
  977. skb->data = memmove(skb->head + 4, skb->data, skb->len);
  978. skb->tail = skb->data + skb->len;
  979. }
  980. } else {
  981. struct sk_buff *skb2;
  982. skb2 = skb_copy_expand(skb, 4, padlen, flags);
  983. dev_kfree_skb_any(skb);
  984. skb = skb2;
  985. if (!skb)
  986. return NULL;
  987. }
  988. packet_len = (u32 *) skb_push(skb, 4);
  989. packet_len = (u32 *) skb->data;
  990. *packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4);
  991. if ((skb->len % 512) == 0) {
  992. padbytes_ptr = (u32 *) skb->tail;
  993. *padbytes_ptr = 0xffff0000;
  994. skb_put(skb, padlen);
  995. }
  996. return skb;
  997. }
  998. static int ax88772_link_reset(struct usbnet *dev)
  999. {
  1000. u16 lpa;
  1001. u16 mode;
  1002. mode = AX88772_MEDIUM_DEFAULT;
  1003. lpa = ax8817x_mdio_read(dev->net, dev->mii.phy_id, MII_LPA);
  1004. if ((lpa & LPA_DUPLEX) == 0)
  1005. mode &= ~AX88772_MEDIUM_FULL_DUPLEX;
  1006. if ((lpa & LPA_100) == 0)
  1007. mode &= ~AX88772_MEDIUM_100MB;
  1008. ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
  1009. return 0;
  1010. }
  1011. static const struct driver_info ax8817x_info = {
  1012. .description = "ASIX AX8817x USB 2.0 Ethernet",
  1013. .bind = ax8817x_bind,
  1014. .status = ax8817x_status,
  1015. .link_reset = ax88172_link_reset,
  1016. .reset = ax88172_link_reset,
  1017. .flags = FLAG_ETHER,
  1018. .data = 0x00130103,
  1019. };
  1020. static const struct driver_info dlink_dub_e100_info = {
  1021. .description = "DLink DUB-E100 USB Ethernet",
  1022. .bind = ax8817x_bind,
  1023. .status = ax8817x_status,
  1024. .link_reset = ax88172_link_reset,
  1025. .reset = ax88172_link_reset,
  1026. .flags = FLAG_ETHER,
  1027. .data = 0x009f9d9f,
  1028. };
  1029. static const struct driver_info netgear_fa120_info = {
  1030. .description = "Netgear FA-120 USB Ethernet",
  1031. .bind = ax8817x_bind,
  1032. .status = ax8817x_status,
  1033. .link_reset = ax88172_link_reset,
  1034. .reset = ax88172_link_reset,
  1035. .flags = FLAG_ETHER,
  1036. .data = 0x00130103,
  1037. };
  1038. static const struct driver_info hawking_uf200_info = {
  1039. .description = "Hawking UF200 USB Ethernet",
  1040. .bind = ax8817x_bind,
  1041. .status = ax8817x_status,
  1042. .link_reset = ax88172_link_reset,
  1043. .reset = ax88172_link_reset,
  1044. .flags = FLAG_ETHER,
  1045. .data = 0x001f1d1f,
  1046. };
  1047. static const struct driver_info ax88772_info = {
  1048. .description = "ASIX AX88772 USB 2.0 Ethernet",
  1049. .bind = ax88772_bind,
  1050. .status = ax8817x_status,
  1051. .link_reset = ax88772_link_reset,
  1052. .reset = ax88772_link_reset,
  1053. .flags = FLAG_ETHER | FLAG_FRAMING_AX,
  1054. .rx_fixup = ax88772_rx_fixup,
  1055. .tx_fixup = ax88772_tx_fixup,
  1056. .data = 0x00130103,
  1057. };
  1058. #endif /* CONFIG_USB_AX8817X */
  1059. #ifdef CONFIG_USB_BELKIN
  1060. #define HAVE_HARDWARE
  1061. /*-------------------------------------------------------------------------
  1062. *
  1063. * Belkin F5U104 ... two NetChip 2280 devices + Atmel microcontroller
  1064. *
  1065. * ... also two eTEK designs, including one sold as "Advance USBNET"
  1066. *
  1067. *-------------------------------------------------------------------------*/
  1068. static const struct driver_info belkin_info = {
  1069. .description = "Belkin, eTEK, or compatible",
  1070. };
  1071. #endif /* CONFIG_USB_BELKIN */
  1072. /*-------------------------------------------------------------------------
  1073. *
  1074. * Communications Device Class declarations.
  1075. * Used by CDC Ethernet, and some CDC variants
  1076. *
  1077. *-------------------------------------------------------------------------*/
  1078. #ifdef CONFIG_USB_CDCETHER
  1079. #define NEED_GENERIC_CDC
  1080. #endif
  1081. #ifdef CONFIG_USB_ZAURUS
  1082. /* Ethernet variant uses funky framing, broken ethernet addressing */
  1083. #define NEED_GENERIC_CDC
  1084. #endif
  1085. #ifdef CONFIG_USB_RNDIS
  1086. /* ACM variant uses even funkier framing, complex control RPC scheme */
  1087. #define NEED_GENERIC_CDC
  1088. #endif
  1089. #ifdef NEED_GENERIC_CDC
  1090. #include <linux/usb_cdc.h>
  1091. struct cdc_state {
  1092. struct usb_cdc_header_desc *header;
  1093. struct usb_cdc_union_desc *u;
  1094. struct usb_cdc_ether_desc *ether;
  1095. struct usb_interface *control;
  1096. struct usb_interface *data;
  1097. };
  1098. static struct usb_driver usbnet_driver;
  1099. /*
  1100. * probes control interface, claims data interface, collects the bulk
  1101. * endpoints, activates data interface (if needed), maybe sets MTU.
  1102. * all pure cdc, except for certain firmware workarounds.
  1103. */
  1104. static int generic_cdc_bind (struct usbnet *dev, struct usb_interface *intf)
  1105. {
  1106. u8 *buf = intf->cur_altsetting->extra;
  1107. int len = intf->cur_altsetting->extralen;
  1108. struct usb_interface_descriptor *d;
  1109. struct cdc_state *info = (void *) &dev->data;
  1110. int status;
  1111. int rndis;
  1112. if (sizeof dev->data < sizeof *info)
  1113. return -EDOM;
  1114. /* expect strict spec conformance for the descriptors, but
  1115. * cope with firmware which stores them in the wrong place
  1116. */
  1117. if (len == 0 && dev->udev->actconfig->extralen) {
  1118. /* Motorola SB4100 (and others: Brad Hards says it's
  1119. * from a Broadcom design) put CDC descriptors here
  1120. */
  1121. buf = dev->udev->actconfig->extra;
  1122. len = dev->udev->actconfig->extralen;
  1123. if (len)
  1124. dev_dbg (&intf->dev,
  1125. "CDC descriptors on config\n");
  1126. }
  1127. /* this assumes that if there's a non-RNDIS vendor variant
  1128. * of cdc-acm, it'll fail RNDIS requests cleanly.
  1129. */
  1130. rndis = (intf->cur_altsetting->desc.bInterfaceProtocol == 0xff);
  1131. memset (info, 0, sizeof *info);
  1132. info->control = intf;
  1133. while (len > 3) {
  1134. if (buf [1] != USB_DT_CS_INTERFACE)
  1135. goto next_desc;
  1136. /* use bDescriptorSubType to identify the CDC descriptors.
  1137. * We expect devices with CDC header and union descriptors.
  1138. * For CDC Ethernet we need the ethernet descriptor.
  1139. * For RNDIS, ignore two (pointless) CDC modem descriptors
  1140. * in favor of a complicated OID-based RPC scheme doing what
  1141. * CDC Ethernet achieves with a simple descriptor.
  1142. */
  1143. switch (buf [2]) {
  1144. case USB_CDC_HEADER_TYPE:
  1145. if (info->header) {
  1146. dev_dbg (&intf->dev, "extra CDC header\n");
  1147. goto bad_desc;
  1148. }
  1149. info->header = (void *) buf;
  1150. if (info->header->bLength != sizeof *info->header) {
  1151. dev_dbg (&intf->dev, "CDC header len %u\n",
  1152. info->header->bLength);
  1153. goto bad_desc;
  1154. }
  1155. break;
  1156. case USB_CDC_UNION_TYPE:
  1157. if (info->u) {
  1158. dev_dbg (&intf->dev, "extra CDC union\n");
  1159. goto bad_desc;
  1160. }
  1161. info->u = (void *) buf;
  1162. if (info->u->bLength != sizeof *info->u) {
  1163. dev_dbg (&intf->dev, "CDC union len %u\n",
  1164. info->u->bLength);
  1165. goto bad_desc;
  1166. }
  1167. /* we need a master/control interface (what we're
  1168. * probed with) and a slave/data interface; union
  1169. * descriptors sort this all out.
  1170. */
  1171. info->control = usb_ifnum_to_if(dev->udev,
  1172. info->u->bMasterInterface0);
  1173. info->data = usb_ifnum_to_if(dev->udev,
  1174. info->u->bSlaveInterface0);
  1175. if (!info->control || !info->data) {
  1176. dev_dbg (&intf->dev,
  1177. "master #%u/%p slave #%u/%p\n",
  1178. info->u->bMasterInterface0,
  1179. info->control,
  1180. info->u->bSlaveInterface0,
  1181. info->data);
  1182. goto bad_desc;
  1183. }
  1184. if (info->control != intf) {
  1185. dev_dbg (&intf->dev, "bogus CDC Union\n");
  1186. /* Ambit USB Cable Modem (and maybe others)
  1187. * interchanges master and slave interface.
  1188. */
  1189. if (info->data == intf) {
  1190. info->data = info->control;
  1191. info->control = intf;
  1192. } else
  1193. goto bad_desc;
  1194. }
  1195. /* a data interface altsetting does the real i/o */
  1196. d = &info->data->cur_altsetting->desc;
  1197. if (d->bInterfaceClass != USB_CLASS_CDC_DATA) {
  1198. dev_dbg (&intf->dev, "slave class %u\n",
  1199. d->bInterfaceClass);
  1200. goto bad_desc;
  1201. }
  1202. break;
  1203. case USB_CDC_ETHERNET_TYPE:
  1204. if (info->ether) {
  1205. dev_dbg (&intf->dev, "extra CDC ether\n");
  1206. goto bad_desc;
  1207. }
  1208. info->ether = (void *) buf;
  1209. if (info->ether->bLength != sizeof *info->ether) {
  1210. dev_dbg (&intf->dev, "CDC ether len %u\n",
  1211. info->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 (and other such vendors) for a while with a cluestick.
  2240. *
  2241. *-------------------------------------------------------------------------*/
  2242. static struct sk_buff *
  2243. zaurus_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
  2244. {
  2245. int padlen;
  2246. struct sk_buff *skb2;
  2247. padlen = 2;
  2248. if (!skb_cloned (skb)) {
  2249. int tailroom = skb_tailroom (skb);
  2250. if ((padlen + 4) <= tailroom)
  2251. goto done;
  2252. }
  2253. skb2 = skb_copy_expand (skb, 0, 4 + padlen, flags);
  2254. dev_kfree_skb_any (skb);
  2255. skb = skb2;
  2256. if (skb) {
  2257. u32 fcs;
  2258. done:
  2259. fcs = crc32_le (~0, skb->data, skb->len);
  2260. fcs = ~fcs;
  2261. *skb_put (skb, 1) = fcs & 0xff;
  2262. *skb_put (skb, 1) = (fcs>> 8) & 0xff;
  2263. *skb_put (skb, 1) = (fcs>>16) & 0xff;
  2264. *skb_put (skb, 1) = (fcs>>24) & 0xff;
  2265. }
  2266. return skb;
  2267. }
  2268. static const struct driver_info zaurus_sl5x00_info = {
  2269. .description = "Sharp Zaurus SL-5x00",
  2270. .flags = FLAG_FRAMING_Z,
  2271. .check_connect = always_connected,
  2272. .bind = generic_cdc_bind,
  2273. .unbind = cdc_unbind,
  2274. .tx_fixup = zaurus_tx_fixup,
  2275. };
  2276. #define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info)
  2277. static const struct driver_info zaurus_pxa_info = {
  2278. .description = "Sharp Zaurus, PXA-2xx based",
  2279. .flags = FLAG_FRAMING_Z,
  2280. .check_connect = always_connected,
  2281. .bind = generic_cdc_bind,
  2282. .unbind = cdc_unbind,
  2283. .tx_fixup = zaurus_tx_fixup,
  2284. };
  2285. #define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info)
  2286. static const struct driver_info olympus_mxl_info = {
  2287. .description = "Olympus R1000",
  2288. .flags = FLAG_FRAMING_Z,
  2289. .check_connect = always_connected,
  2290. .bind = generic_cdc_bind,
  2291. .unbind = cdc_unbind,
  2292. .tx_fixup = zaurus_tx_fixup,
  2293. };
  2294. #define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info)
  2295. /* Some more recent products using Lineo/Belcarra code will wrongly claim
  2296. * CDC MDLM conformance. They aren't conformant: data endpoints live
  2297. * in the control interface, there's no data interface, and it's not used
  2298. * to talk to a cell phone radio. But at least we can detect these two
  2299. * pseudo-classes, rather than growing this product list with entries for
  2300. * each new nonconformant product (sigh).
  2301. */
  2302. static const u8 safe_guid[16] = {
  2303. 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
  2304. 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
  2305. };
  2306. static const u8 blan_guid[16] = {
  2307. 0x74, 0xf0, 0x3d, 0xbd, 0x1e, 0xc1, 0x44, 0x70,
  2308. 0xa3, 0x67, 0x71, 0x34, 0xc9, 0xf5, 0x54, 0x37,
  2309. };
  2310. static int blan_mdlm_bind (struct usbnet *dev, struct usb_interface *intf)
  2311. {
  2312. u8 *buf = intf->cur_altsetting->extra;
  2313. int len = intf->cur_altsetting->extralen;
  2314. struct usb_cdc_mdlm_desc *desc = NULL;
  2315. struct usb_cdc_mdlm_detail_desc *detail = NULL;
  2316. while (len > 3) {
  2317. if (buf [1] != USB_DT_CS_INTERFACE)
  2318. goto next_desc;
  2319. /* use bDescriptorSubType, and just verify that we get a
  2320. * "BLAN" (or "SAFE") descriptor.
  2321. */
  2322. switch (buf [2]) {
  2323. case USB_CDC_MDLM_TYPE:
  2324. if (desc) {
  2325. dev_dbg (&intf->dev, "extra MDLM\n");
  2326. goto bad_desc;
  2327. }
  2328. desc = (void *) buf;
  2329. if (desc->bLength != sizeof *desc) {
  2330. dev_dbg (&intf->dev, "MDLM len %u\n",
  2331. desc->bLength);
  2332. goto bad_desc;
  2333. }
  2334. /* expect bcdVersion 1.0, ignore */
  2335. if (memcmp(&desc->bGUID, blan_guid, 16)
  2336. || memcmp(&desc->bGUID, blan_guid, 16) ) {
  2337. /* hey, this one might _really_ be MDLM! */
  2338. dev_dbg (&intf->dev, "MDLM guid\n");
  2339. goto bad_desc;
  2340. }
  2341. break;
  2342. case USB_CDC_MDLM_DETAIL_TYPE:
  2343. if (detail) {
  2344. dev_dbg (&intf->dev, "extra MDLM detail\n");
  2345. goto bad_desc;
  2346. }
  2347. detail = (void *) buf;
  2348. switch (detail->bGuidDescriptorType) {
  2349. case 0: /* "SAFE" */
  2350. if (detail->bLength != (sizeof *detail + 2))
  2351. goto bad_detail;
  2352. break;
  2353. case 1: /* "BLAN" */
  2354. if (detail->bLength != (sizeof *detail + 3))
  2355. goto bad_detail;
  2356. break;
  2357. default:
  2358. goto bad_detail;
  2359. }
  2360. /* assuming we either noticed BLAN already, or will
  2361. * find it soon, there are some data bytes here:
  2362. * - bmNetworkCapabilities (unused)
  2363. * - bmDataCapabilities (bits, see below)
  2364. * - bPad (ignored, for PADAFTER -- BLAN-only)
  2365. * bits are:
  2366. * - 0x01 -- Zaurus framing (add CRC)
  2367. * - 0x02 -- PADBEFORE
  2368. * - 0x04 -- PADAFTER
  2369. * - 0x08 -- "fermat" packet mangling (for hw bugs)
  2370. */
  2371. if (detail->bDetailData[1] != 0x01) {
  2372. /* bmDataCapabilites == 0 would be fine too,
  2373. * but framing is minidriver-coupled for now.
  2374. */
  2375. bad_detail:
  2376. dev_dbg (&intf->dev,
  2377. "bad MDLM detail, %d %d %d\n",
  2378. detail->bLength,
  2379. detail->bDetailData[0],
  2380. detail->bDetailData[2]);
  2381. goto bad_desc;
  2382. }
  2383. break;
  2384. }
  2385. next_desc:
  2386. len -= buf [0]; /* bLength */
  2387. buf += buf [0];
  2388. }
  2389. if (!desc || !detail) {
  2390. dev_dbg (&intf->dev, "missing cdc mdlm %s%sdescriptor\n",
  2391. desc ? "" : "func ",
  2392. detail ? "" : "detail ");
  2393. goto bad_desc;
  2394. }
  2395. /* There's probably a CDC Ethernet descriptor there, but we can't
  2396. * rely on the Ethernet address it provides since not all vendors
  2397. * bother to make it unique. Likewise there's no point in tracking
  2398. * of the CDC event notifications.
  2399. */
  2400. return get_endpoints (dev, intf);
  2401. bad_desc:
  2402. dev_info (&dev->udev->dev, "unsupported MDLM descriptors\n");
  2403. return -ENODEV;
  2404. }
  2405. static const struct driver_info bogus_mdlm_info = {
  2406. .description = "pseudo-MDLM (BLAN) device",
  2407. .flags = FLAG_FRAMING_Z,
  2408. .check_connect = always_connected,
  2409. .tx_fixup = zaurus_tx_fixup,
  2410. .bind = blan_mdlm_bind,
  2411. };
  2412. #else
  2413. /* blacklist all those devices */
  2414. #define ZAURUS_STRONGARM_INFO 0
  2415. #define ZAURUS_PXA_INFO 0
  2416. #define OLYMPUS_MXL_INFO 0
  2417. #endif
  2418. /*-------------------------------------------------------------------------
  2419. *
  2420. * Network Device Driver (peer link to "Host Device", from USB host)
  2421. *
  2422. *-------------------------------------------------------------------------*/
  2423. static int usbnet_change_mtu (struct net_device *net, int new_mtu)
  2424. {
  2425. struct usbnet *dev = netdev_priv(net);
  2426. if (new_mtu <= MIN_PACKET || new_mtu > MAX_PACKET)
  2427. return -EINVAL;
  2428. #ifdef CONFIG_USB_NET1080
  2429. if (((dev->driver_info->flags) & FLAG_FRAMING_NC)) {
  2430. if (FRAMED_SIZE (new_mtu) > MAX_PACKET)
  2431. return -EINVAL;
  2432. }
  2433. #endif
  2434. #ifdef CONFIG_USB_GENESYS
  2435. if (((dev->driver_info->flags) & FLAG_FRAMING_GL)
  2436. && new_mtu > GL_MAX_PACKET_LEN)
  2437. return -EINVAL;
  2438. #endif
  2439. // no second zero-length packet read wanted after mtu-sized packets
  2440. if (((new_mtu + sizeof (struct ethhdr)) % dev->maxpacket) == 0)
  2441. return -EDOM;
  2442. net->mtu = new_mtu;
  2443. return 0;
  2444. }
  2445. /*-------------------------------------------------------------------------*/
  2446. static struct net_device_stats *usbnet_get_stats (struct net_device *net)
  2447. {
  2448. struct usbnet *dev = netdev_priv(net);
  2449. return &dev->stats;
  2450. }
  2451. /*-------------------------------------------------------------------------*/
  2452. /* some LK 2.4 HCDs oopsed if we freed or resubmitted urbs from
  2453. * completion callbacks. 2.5 should have fixed those bugs...
  2454. */
  2455. static void defer_bh (struct usbnet *dev, struct sk_buff *skb)
  2456. {
  2457. struct sk_buff_head *list = skb->list;
  2458. unsigned long flags;
  2459. spin_lock_irqsave (&list->lock, flags);
  2460. __skb_unlink (skb, list);
  2461. spin_unlock (&list->lock);
  2462. spin_lock (&dev->done.lock);
  2463. __skb_queue_tail (&dev->done, skb);
  2464. if (dev->done.qlen == 1)
  2465. tasklet_schedule (&dev->bh);
  2466. spin_unlock_irqrestore (&dev->done.lock, flags);
  2467. }
  2468. /* some work can't be done in tasklets, so we use keventd
  2469. *
  2470. * NOTE: annoying asymmetry: if it's active, schedule_work() fails,
  2471. * but tasklet_schedule() doesn't. hope the failure is rare.
  2472. */
  2473. static void defer_kevent (struct usbnet *dev, int work)
  2474. {
  2475. set_bit (work, &dev->flags);
  2476. if (!schedule_work (&dev->kevent))
  2477. deverr (dev, "kevent %d may have been dropped", work);
  2478. else
  2479. devdbg (dev, "kevent %d scheduled", work);
  2480. }
  2481. /*-------------------------------------------------------------------------*/
  2482. static void rx_complete (struct urb *urb, struct pt_regs *regs);
  2483. static void rx_submit (struct usbnet *dev, struct urb *urb, int flags)
  2484. {
  2485. struct sk_buff *skb;
  2486. struct skb_data *entry;
  2487. int retval = 0;
  2488. unsigned long lockflags;
  2489. size_t size;
  2490. #ifdef CONFIG_USB_NET1080
  2491. if (dev->driver_info->flags & FLAG_FRAMING_NC)
  2492. size = FRAMED_SIZE (dev->net->mtu);
  2493. else
  2494. #endif
  2495. #ifdef CONFIG_USB_GENESYS
  2496. if (dev->driver_info->flags & FLAG_FRAMING_GL)
  2497. size = GL_RCV_BUF_SIZE;
  2498. else
  2499. #endif
  2500. #ifdef CONFIG_USB_ZAURUS
  2501. if (dev->driver_info->flags & FLAG_FRAMING_Z)
  2502. size = 6 + (sizeof (struct ethhdr) + dev->net->mtu);
  2503. else
  2504. #endif
  2505. #ifdef CONFIG_USB_RNDIS
  2506. if (dev->driver_info->flags & FLAG_FRAMING_RN)
  2507. size = RNDIS_MAX_TRANSFER;
  2508. else
  2509. #endif
  2510. #ifdef CONFIG_USB_AX8817X
  2511. if (dev->driver_info->flags & FLAG_FRAMING_AX)
  2512. size = 2048;
  2513. else
  2514. #endif
  2515. size = (sizeof (struct ethhdr) + dev->net->mtu);
  2516. if ((skb = alloc_skb (size + NET_IP_ALIGN, flags)) == NULL) {
  2517. if (netif_msg_rx_err (dev))
  2518. devdbg (dev, "no rx skb");
  2519. defer_kevent (dev, EVENT_RX_MEMORY);
  2520. usb_free_urb (urb);
  2521. return;
  2522. }
  2523. skb_reserve (skb, NET_IP_ALIGN);
  2524. entry = (struct skb_data *) skb->cb;
  2525. entry->urb = urb;
  2526. entry->dev = dev;
  2527. entry->state = rx_start;
  2528. entry->length = 0;
  2529. usb_fill_bulk_urb (urb, dev->udev, dev->in,
  2530. skb->data, size, rx_complete, skb);
  2531. urb->transfer_flags |= URB_ASYNC_UNLINK;
  2532. spin_lock_irqsave (&dev->rxq.lock, lockflags);
  2533. if (netif_running (dev->net)
  2534. && netif_device_present (dev->net)
  2535. && !test_bit (EVENT_RX_HALT, &dev->flags)) {
  2536. switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){
  2537. case -EPIPE:
  2538. defer_kevent (dev, EVENT_RX_HALT);
  2539. break;
  2540. case -ENOMEM:
  2541. defer_kevent (dev, EVENT_RX_MEMORY);
  2542. break;
  2543. case -ENODEV:
  2544. if (netif_msg_ifdown (dev))
  2545. devdbg (dev, "device gone");
  2546. netif_device_detach (dev->net);
  2547. break;
  2548. default:
  2549. if (netif_msg_rx_err (dev))
  2550. devdbg (dev, "rx submit, %d", retval);
  2551. tasklet_schedule (&dev->bh);
  2552. break;
  2553. case 0:
  2554. __skb_queue_tail (&dev->rxq, skb);
  2555. }
  2556. } else {
  2557. if (netif_msg_ifdown (dev))
  2558. devdbg (dev, "rx: stopped");
  2559. retval = -ENOLINK;
  2560. }
  2561. spin_unlock_irqrestore (&dev->rxq.lock, lockflags);
  2562. if (retval) {
  2563. dev_kfree_skb_any (skb);
  2564. usb_free_urb (urb);
  2565. }
  2566. }
  2567. /*-------------------------------------------------------------------------*/
  2568. static inline void rx_process (struct usbnet *dev, struct sk_buff *skb)
  2569. {
  2570. if (dev->driver_info->rx_fixup
  2571. && !dev->driver_info->rx_fixup (dev, skb))
  2572. goto error;
  2573. // else network stack removes extra byte if we forced a short packet
  2574. if (skb->len)
  2575. skb_return (dev, skb);
  2576. else {
  2577. if (netif_msg_rx_err (dev))
  2578. devdbg (dev, "drop");
  2579. error:
  2580. dev->stats.rx_errors++;
  2581. skb_queue_tail (&dev->done, skb);
  2582. }
  2583. }
  2584. /*-------------------------------------------------------------------------*/
  2585. static void rx_complete (struct urb *urb, struct pt_regs *regs)
  2586. {
  2587. struct sk_buff *skb = (struct sk_buff *) urb->context;
  2588. struct skb_data *entry = (struct skb_data *) skb->cb;
  2589. struct usbnet *dev = entry->dev;
  2590. int urb_status = urb->status;
  2591. skb_put (skb, urb->actual_length);
  2592. entry->state = rx_done;
  2593. entry->urb = NULL;
  2594. switch (urb_status) {
  2595. // success
  2596. case 0:
  2597. if (MIN_PACKET > skb->len || skb->len > MAX_PACKET) {
  2598. entry->state = rx_cleanup;
  2599. dev->stats.rx_errors++;
  2600. dev->stats.rx_length_errors++;
  2601. if (netif_msg_rx_err (dev))
  2602. devdbg (dev, "rx length %d", skb->len);
  2603. }
  2604. break;
  2605. // stalls need manual reset. this is rare ... except that
  2606. // when going through USB 2.0 TTs, unplug appears this way.
  2607. // we avoid the highspeed version of the ETIMEOUT/EILSEQ
  2608. // storm, recovering as needed.
  2609. case -EPIPE:
  2610. dev->stats.rx_errors++;
  2611. defer_kevent (dev, EVENT_RX_HALT);
  2612. // FALLTHROUGH
  2613. // software-driven interface shutdown
  2614. case -ECONNRESET: // async unlink
  2615. case -ESHUTDOWN: // hardware gone
  2616. if (netif_msg_ifdown (dev))
  2617. devdbg (dev, "rx shutdown, code %d", urb_status);
  2618. goto block;
  2619. // we get controller i/o faults during khubd disconnect() delays.
  2620. // throttle down resubmits, to avoid log floods; just temporarily,
  2621. // so we still recover when the fault isn't a khubd delay.
  2622. case -EPROTO: // ehci
  2623. case -ETIMEDOUT: // ohci
  2624. case -EILSEQ: // uhci
  2625. dev->stats.rx_errors++;
  2626. if (!timer_pending (&dev->delay)) {
  2627. mod_timer (&dev->delay, jiffies + THROTTLE_JIFFIES);
  2628. if (netif_msg_link (dev))
  2629. devdbg (dev, "rx throttle %d", urb_status);
  2630. }
  2631. block:
  2632. entry->state = rx_cleanup;
  2633. entry->urb = urb;
  2634. urb = NULL;
  2635. break;
  2636. // data overrun ... flush fifo?
  2637. case -EOVERFLOW:
  2638. dev->stats.rx_over_errors++;
  2639. // FALLTHROUGH
  2640. default:
  2641. entry->state = rx_cleanup;
  2642. dev->stats.rx_errors++;
  2643. if (netif_msg_rx_err (dev))
  2644. devdbg (dev, "rx status %d", urb_status);
  2645. break;
  2646. }
  2647. defer_bh (dev, skb);
  2648. if (urb) {
  2649. if (netif_running (dev->net)
  2650. && !test_bit (EVENT_RX_HALT, &dev->flags)) {
  2651. rx_submit (dev, urb, GFP_ATOMIC);
  2652. return;
  2653. }
  2654. usb_free_urb (urb);
  2655. }
  2656. if (netif_msg_rx_err (dev))
  2657. devdbg (dev, "no read resubmitted");
  2658. }
  2659. static void intr_complete (struct urb *urb, struct pt_regs *regs)
  2660. {
  2661. struct usbnet *dev = urb->context;
  2662. int status = urb->status;
  2663. switch (status) {
  2664. /* success */
  2665. case 0:
  2666. dev->driver_info->status(dev, urb);
  2667. break;
  2668. /* software-driven interface shutdown */
  2669. case -ENOENT: // urb killed
  2670. case -ESHUTDOWN: // hardware gone
  2671. if (netif_msg_ifdown (dev))
  2672. devdbg (dev, "intr shutdown, code %d", status);
  2673. return;
  2674. /* NOTE: not throttling like RX/TX, since this endpoint
  2675. * already polls infrequently
  2676. */
  2677. default:
  2678. devdbg (dev, "intr status %d", status);
  2679. break;
  2680. }
  2681. if (!netif_running (dev->net))
  2682. return;
  2683. memset(urb->transfer_buffer, 0, urb->transfer_buffer_length);
  2684. status = usb_submit_urb (urb, GFP_ATOMIC);
  2685. if (status != 0 && netif_msg_timer (dev))
  2686. deverr(dev, "intr resubmit --> %d", status);
  2687. }
  2688. /*-------------------------------------------------------------------------*/
  2689. // unlink pending rx/tx; completion handlers do all other cleanup
  2690. static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q)
  2691. {
  2692. unsigned long flags;
  2693. struct sk_buff *skb, *skbnext;
  2694. int count = 0;
  2695. spin_lock_irqsave (&q->lock, flags);
  2696. for (skb = q->next; skb != (struct sk_buff *) q; skb = skbnext) {
  2697. struct skb_data *entry;
  2698. struct urb *urb;
  2699. int retval;
  2700. entry = (struct skb_data *) skb->cb;
  2701. urb = entry->urb;
  2702. skbnext = skb->next;
  2703. // during some PM-driven resume scenarios,
  2704. // these (async) unlinks complete immediately
  2705. retval = usb_unlink_urb (urb);
  2706. if (retval != -EINPROGRESS && retval != 0)
  2707. devdbg (dev, "unlink urb err, %d", retval);
  2708. else
  2709. count++;
  2710. }
  2711. spin_unlock_irqrestore (&q->lock, flags);
  2712. return count;
  2713. }
  2714. /*-------------------------------------------------------------------------*/
  2715. // precondition: never called in_interrupt
  2716. static int usbnet_stop (struct net_device *net)
  2717. {
  2718. struct usbnet *dev = netdev_priv(net);
  2719. int temp;
  2720. DECLARE_WAIT_QUEUE_HEAD (unlink_wakeup);
  2721. DECLARE_WAITQUEUE (wait, current);
  2722. netif_stop_queue (net);
  2723. if (netif_msg_ifdown (dev))
  2724. devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld",
  2725. dev->stats.rx_packets, dev->stats.tx_packets,
  2726. dev->stats.rx_errors, dev->stats.tx_errors
  2727. );
  2728. // ensure there are no more active urbs
  2729. add_wait_queue (&unlink_wakeup, &wait);
  2730. dev->wait = &unlink_wakeup;
  2731. temp = unlink_urbs (dev, &dev->txq) + unlink_urbs (dev, &dev->rxq);
  2732. // maybe wait for deletions to finish.
  2733. while (skb_queue_len (&dev->rxq)
  2734. && skb_queue_len (&dev->txq)
  2735. && skb_queue_len (&dev->done)) {
  2736. msleep(UNLINK_TIMEOUT_MS);
  2737. if (netif_msg_ifdown (dev))
  2738. devdbg (dev, "waited for %d urb completions", temp);
  2739. }
  2740. dev->wait = NULL;
  2741. remove_wait_queue (&unlink_wakeup, &wait);
  2742. usb_kill_urb(dev->interrupt);
  2743. /* deferred work (task, timer, softirq) must also stop.
  2744. * can't flush_scheduled_work() until we drop rtnl (later),
  2745. * else workers could deadlock; so make workers a NOP.
  2746. */
  2747. dev->flags = 0;
  2748. del_timer_sync (&dev->delay);
  2749. tasklet_kill (&dev->bh);
  2750. return 0;
  2751. }
  2752. /*-------------------------------------------------------------------------*/
  2753. // posts reads, and enables write queuing
  2754. // precondition: never called in_interrupt
  2755. static int usbnet_open (struct net_device *net)
  2756. {
  2757. struct usbnet *dev = netdev_priv(net);
  2758. int retval = 0;
  2759. struct driver_info *info = dev->driver_info;
  2760. // put into "known safe" state
  2761. if (info->reset && (retval = info->reset (dev)) < 0) {
  2762. if (netif_msg_ifup (dev))
  2763. devinfo (dev,
  2764. "open reset fail (%d) usbnet usb-%s-%s, %s",
  2765. retval,
  2766. dev->udev->bus->bus_name, dev->udev->devpath,
  2767. info->description);
  2768. goto done;
  2769. }
  2770. // insist peer be connected
  2771. if (info->check_connect && (retval = info->check_connect (dev)) < 0) {
  2772. if (netif_msg_ifup (dev))
  2773. devdbg (dev, "can't open; %d", retval);
  2774. goto done;
  2775. }
  2776. /* start any status interrupt transfer */
  2777. if (dev->interrupt) {
  2778. retval = usb_submit_urb (dev->interrupt, GFP_KERNEL);
  2779. if (retval < 0) {
  2780. if (netif_msg_ifup (dev))
  2781. deverr (dev, "intr submit %d", retval);
  2782. goto done;
  2783. }
  2784. }
  2785. netif_start_queue (net);
  2786. if (netif_msg_ifup (dev)) {
  2787. char *framing;
  2788. if (dev->driver_info->flags & FLAG_FRAMING_NC)
  2789. framing = "NetChip";
  2790. else if (dev->driver_info->flags & FLAG_FRAMING_GL)
  2791. framing = "GeneSys";
  2792. else if (dev->driver_info->flags & FLAG_FRAMING_Z)
  2793. framing = "Zaurus";
  2794. else if (dev->driver_info->flags & FLAG_FRAMING_RN)
  2795. framing = "RNDIS";
  2796. else if (dev->driver_info->flags & FLAG_FRAMING_AX)
  2797. framing = "ASIX";
  2798. else
  2799. framing = "simple";
  2800. devinfo (dev, "open: enable queueing "
  2801. "(rx %d, tx %d) mtu %d %s framing",
  2802. RX_QLEN (dev), TX_QLEN (dev), dev->net->mtu,
  2803. framing);
  2804. }
  2805. // delay posting reads until we're fully open
  2806. tasklet_schedule (&dev->bh);
  2807. done:
  2808. return retval;
  2809. }
  2810. /*-------------------------------------------------------------------------*/
  2811. static void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info)
  2812. {
  2813. struct usbnet *dev = netdev_priv(net);
  2814. strncpy (info->driver, driver_name, sizeof info->driver);
  2815. strncpy (info->version, DRIVER_VERSION, sizeof info->version);
  2816. strncpy (info->fw_version, dev->driver_info->description,
  2817. sizeof info->fw_version);
  2818. usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info);
  2819. }
  2820. static u32 usbnet_get_link (struct net_device *net)
  2821. {
  2822. struct usbnet *dev = netdev_priv(net);
  2823. /* If a check_connect is defined, return it's results */
  2824. if (dev->driver_info->check_connect)
  2825. return dev->driver_info->check_connect (dev) == 0;
  2826. /* Otherwise, we're up to avoid breaking scripts */
  2827. return 1;
  2828. }
  2829. static u32 usbnet_get_msglevel (struct net_device *net)
  2830. {
  2831. struct usbnet *dev = netdev_priv(net);
  2832. return dev->msg_enable;
  2833. }
  2834. static void usbnet_set_msglevel (struct net_device *net, u32 level)
  2835. {
  2836. struct usbnet *dev = netdev_priv(net);
  2837. dev->msg_enable = level;
  2838. }
  2839. static int usbnet_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
  2840. {
  2841. #ifdef NEED_MII
  2842. {
  2843. struct usbnet *dev = netdev_priv(net);
  2844. if (dev->mii.mdio_read != NULL && dev->mii.mdio_write != NULL)
  2845. return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
  2846. }
  2847. #endif
  2848. return -EOPNOTSUPP;
  2849. }
  2850. /*-------------------------------------------------------------------------*/
  2851. /* work that cannot be done in interrupt context uses keventd.
  2852. *
  2853. * NOTE: with 2.5 we could do more of this using completion callbacks,
  2854. * especially now that control transfers can be queued.
  2855. */
  2856. static void
  2857. kevent (void *data)
  2858. {
  2859. struct usbnet *dev = data;
  2860. int status;
  2861. /* usb_clear_halt() needs a thread context */
  2862. if (test_bit (EVENT_TX_HALT, &dev->flags)) {
  2863. unlink_urbs (dev, &dev->txq);
  2864. status = usb_clear_halt (dev->udev, dev->out);
  2865. if (status < 0 && status != -EPIPE) {
  2866. if (netif_msg_tx_err (dev))
  2867. deverr (dev, "can't clear tx halt, status %d",
  2868. status);
  2869. } else {
  2870. clear_bit (EVENT_TX_HALT, &dev->flags);
  2871. netif_wake_queue (dev->net);
  2872. }
  2873. }
  2874. if (test_bit (EVENT_RX_HALT, &dev->flags)) {
  2875. unlink_urbs (dev, &dev->rxq);
  2876. status = usb_clear_halt (dev->udev, dev->in);
  2877. if (status < 0 && status != -EPIPE) {
  2878. if (netif_msg_rx_err (dev))
  2879. deverr (dev, "can't clear rx halt, status %d",
  2880. status);
  2881. } else {
  2882. clear_bit (EVENT_RX_HALT, &dev->flags);
  2883. tasklet_schedule (&dev->bh);
  2884. }
  2885. }
  2886. /* tasklet could resubmit itself forever if memory is tight */
  2887. if (test_bit (EVENT_RX_MEMORY, &dev->flags)) {
  2888. struct urb *urb = NULL;
  2889. if (netif_running (dev->net))
  2890. urb = usb_alloc_urb (0, GFP_KERNEL);
  2891. else
  2892. clear_bit (EVENT_RX_MEMORY, &dev->flags);
  2893. if (urb != NULL) {
  2894. clear_bit (EVENT_RX_MEMORY, &dev->flags);
  2895. rx_submit (dev, urb, GFP_KERNEL);
  2896. tasklet_schedule (&dev->bh);
  2897. }
  2898. }
  2899. if (test_bit (EVENT_LINK_RESET, &dev->flags)) {
  2900. struct driver_info *info = dev->driver_info;
  2901. int retval = 0;
  2902. clear_bit (EVENT_LINK_RESET, &dev->flags);
  2903. if(info->link_reset && (retval = info->link_reset(dev)) < 0) {
  2904. devinfo(dev, "link reset failed (%d) usbnet usb-%s-%s, %s",
  2905. retval,
  2906. dev->udev->bus->bus_name, dev->udev->devpath,
  2907. info->description);
  2908. }
  2909. }
  2910. if (dev->flags)
  2911. devdbg (dev, "kevent done, flags = 0x%lx",
  2912. dev->flags);
  2913. }
  2914. /*-------------------------------------------------------------------------*/
  2915. static void tx_complete (struct urb *urb, struct pt_regs *regs)
  2916. {
  2917. struct sk_buff *skb = (struct sk_buff *) urb->context;
  2918. struct skb_data *entry = (struct skb_data *) skb->cb;
  2919. struct usbnet *dev = entry->dev;
  2920. if (urb->status == 0) {
  2921. dev->stats.tx_packets++;
  2922. dev->stats.tx_bytes += entry->length;
  2923. } else {
  2924. dev->stats.tx_errors++;
  2925. switch (urb->status) {
  2926. case -EPIPE:
  2927. defer_kevent (dev, EVENT_TX_HALT);
  2928. break;
  2929. /* software-driven interface shutdown */
  2930. case -ECONNRESET: // async unlink
  2931. case -ESHUTDOWN: // hardware gone
  2932. break;
  2933. // like rx, tx gets controller i/o faults during khubd delays
  2934. // and so it uses the same throttling mechanism.
  2935. case -EPROTO: // ehci
  2936. case -ETIMEDOUT: // ohci
  2937. case -EILSEQ: // uhci
  2938. if (!timer_pending (&dev->delay)) {
  2939. mod_timer (&dev->delay,
  2940. jiffies + THROTTLE_JIFFIES);
  2941. if (netif_msg_link (dev))
  2942. devdbg (dev, "tx throttle %d",
  2943. urb->status);
  2944. }
  2945. netif_stop_queue (dev->net);
  2946. break;
  2947. default:
  2948. if (netif_msg_tx_err (dev))
  2949. devdbg (dev, "tx err %d", entry->urb->status);
  2950. break;
  2951. }
  2952. }
  2953. urb->dev = NULL;
  2954. entry->state = tx_done;
  2955. defer_bh (dev, skb);
  2956. }
  2957. /*-------------------------------------------------------------------------*/
  2958. static void usbnet_tx_timeout (struct net_device *net)
  2959. {
  2960. struct usbnet *dev = netdev_priv(net);
  2961. unlink_urbs (dev, &dev->txq);
  2962. tasklet_schedule (&dev->bh);
  2963. // FIXME: device recovery -- reset?
  2964. }
  2965. /*-------------------------------------------------------------------------*/
  2966. static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
  2967. {
  2968. struct usbnet *dev = netdev_priv(net);
  2969. int length;
  2970. int retval = NET_XMIT_SUCCESS;
  2971. struct urb *urb = NULL;
  2972. struct skb_data *entry;
  2973. struct driver_info *info = dev->driver_info;
  2974. unsigned long flags;
  2975. #ifdef CONFIG_USB_NET1080
  2976. struct nc_header *header = NULL;
  2977. struct nc_trailer *trailer = NULL;
  2978. #endif /* CONFIG_USB_NET1080 */
  2979. // some devices want funky USB-level framing, for
  2980. // win32 driver (usually) and/or hardware quirks
  2981. if (info->tx_fixup) {
  2982. skb = info->tx_fixup (dev, skb, GFP_ATOMIC);
  2983. if (!skb) {
  2984. if (netif_msg_tx_err (dev))
  2985. devdbg (dev, "can't tx_fixup skb");
  2986. goto drop;
  2987. }
  2988. }
  2989. length = skb->len;
  2990. if (!(urb = usb_alloc_urb (0, GFP_ATOMIC))) {
  2991. if (netif_msg_tx_err (dev))
  2992. devdbg (dev, "no urb");
  2993. goto drop;
  2994. }
  2995. entry = (struct skb_data *) skb->cb;
  2996. entry->urb = urb;
  2997. entry->dev = dev;
  2998. entry->state = tx_start;
  2999. entry->length = length;
  3000. // FIXME: reorganize a bit, so that fixup() fills out NetChip
  3001. // framing too. (Packet ID update needs the spinlock...)
  3002. // [ BETTER: we already own net->xmit_lock, that's enough ]
  3003. #ifdef CONFIG_USB_NET1080
  3004. if (info->flags & FLAG_FRAMING_NC) {
  3005. header = (struct nc_header *) skb_push (skb, sizeof *header);
  3006. header->hdr_len = cpu_to_le16 (sizeof (*header));
  3007. header->packet_len = cpu_to_le16 (length);
  3008. if (!((skb->len + sizeof *trailer) & 0x01))
  3009. *skb_put (skb, 1) = PAD_BYTE;
  3010. trailer = (struct nc_trailer *) skb_put (skb, sizeof *trailer);
  3011. }
  3012. #endif /* CONFIG_USB_NET1080 */
  3013. usb_fill_bulk_urb (urb, dev->udev, dev->out,
  3014. skb->data, skb->len, tx_complete, skb);
  3015. urb->transfer_flags |= URB_ASYNC_UNLINK;
  3016. /* don't assume the hardware handles USB_ZERO_PACKET
  3017. * NOTE: strictly conforming cdc-ether devices should expect
  3018. * the ZLP here, but ignore the one-byte packet.
  3019. *
  3020. * FIXME zero that byte, if it doesn't require a new skb.
  3021. */
  3022. if ((length % dev->maxpacket) == 0)
  3023. urb->transfer_buffer_length++;
  3024. spin_lock_irqsave (&dev->txq.lock, flags);
  3025. #ifdef CONFIG_USB_NET1080
  3026. if (info->flags & FLAG_FRAMING_NC) {
  3027. header->packet_id = cpu_to_le16 ((u16)dev->dev_packet_id++);
  3028. put_unaligned (header->packet_id, &trailer->packet_id);
  3029. #if 0
  3030. devdbg (dev, "frame >tx h %d p %d id %d",
  3031. header->hdr_len, header->packet_len,
  3032. header->packet_id);
  3033. #endif
  3034. }
  3035. #endif /* CONFIG_USB_NET1080 */
  3036. switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) {
  3037. case -EPIPE:
  3038. netif_stop_queue (net);
  3039. defer_kevent (dev, EVENT_TX_HALT);
  3040. break;
  3041. default:
  3042. if (netif_msg_tx_err (dev))
  3043. devdbg (dev, "tx: submit urb err %d", retval);
  3044. break;
  3045. case 0:
  3046. net->trans_start = jiffies;
  3047. __skb_queue_tail (&dev->txq, skb);
  3048. if (dev->txq.qlen >= TX_QLEN (dev))
  3049. netif_stop_queue (net);
  3050. }
  3051. spin_unlock_irqrestore (&dev->txq.lock, flags);
  3052. if (retval) {
  3053. if (netif_msg_tx_err (dev))
  3054. devdbg (dev, "drop, code %d", retval);
  3055. drop:
  3056. retval = NET_XMIT_SUCCESS;
  3057. dev->stats.tx_dropped++;
  3058. if (skb)
  3059. dev_kfree_skb_any (skb);
  3060. usb_free_urb (urb);
  3061. } else if (netif_msg_tx_queued (dev)) {
  3062. devdbg (dev, "> tx, len %d, type 0x%x",
  3063. length, skb->protocol);
  3064. }
  3065. return retval;
  3066. }
  3067. /*-------------------------------------------------------------------------*/
  3068. // tasklet (work deferred from completions, in_irq) or timer
  3069. static void usbnet_bh (unsigned long param)
  3070. {
  3071. struct usbnet *dev = (struct usbnet *) param;
  3072. struct sk_buff *skb;
  3073. struct skb_data *entry;
  3074. while ((skb = skb_dequeue (&dev->done))) {
  3075. entry = (struct skb_data *) skb->cb;
  3076. switch (entry->state) {
  3077. case rx_done:
  3078. entry->state = rx_cleanup;
  3079. rx_process (dev, skb);
  3080. continue;
  3081. case tx_done:
  3082. case rx_cleanup:
  3083. usb_free_urb (entry->urb);
  3084. dev_kfree_skb (skb);
  3085. continue;
  3086. default:
  3087. devdbg (dev, "bogus skb state %d", entry->state);
  3088. }
  3089. }
  3090. // waiting for all pending urbs to complete?
  3091. if (dev->wait) {
  3092. if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) {
  3093. wake_up (dev->wait);
  3094. }
  3095. // or are we maybe short a few urbs?
  3096. } else if (netif_running (dev->net)
  3097. && netif_device_present (dev->net)
  3098. && !timer_pending (&dev->delay)
  3099. && !test_bit (EVENT_RX_HALT, &dev->flags)) {
  3100. int temp = dev->rxq.qlen;
  3101. int qlen = RX_QLEN (dev);
  3102. if (temp < qlen) {
  3103. struct urb *urb;
  3104. int i;
  3105. // don't refill the queue all at once
  3106. for (i = 0; i < 10 && dev->rxq.qlen < qlen; i++) {
  3107. urb = usb_alloc_urb (0, GFP_ATOMIC);
  3108. if (urb != NULL)
  3109. rx_submit (dev, urb, GFP_ATOMIC);
  3110. }
  3111. if (temp != dev->rxq.qlen && netif_msg_link (dev))
  3112. devdbg (dev, "rxqlen %d --> %d",
  3113. temp, dev->rxq.qlen);
  3114. if (dev->rxq.qlen < qlen)
  3115. tasklet_schedule (&dev->bh);
  3116. }
  3117. if (dev->txq.qlen < TX_QLEN (dev))
  3118. netif_wake_queue (dev->net);
  3119. }
  3120. }
  3121. /*-------------------------------------------------------------------------
  3122. *
  3123. * USB Device Driver support
  3124. *
  3125. *-------------------------------------------------------------------------*/
  3126. // precondition: never called in_interrupt
  3127. static void usbnet_disconnect (struct usb_interface *intf)
  3128. {
  3129. struct usbnet *dev;
  3130. struct usb_device *xdev;
  3131. struct net_device *net;
  3132. dev = usb_get_intfdata(intf);
  3133. usb_set_intfdata(intf, NULL);
  3134. if (!dev)
  3135. return;
  3136. xdev = interface_to_usbdev (intf);
  3137. if (netif_msg_probe (dev))
  3138. devinfo (dev, "unregister usbnet usb-%s-%s, %s",
  3139. xdev->bus->bus_name, xdev->devpath,
  3140. dev->driver_info->description);
  3141. net = dev->net;
  3142. unregister_netdev (net);
  3143. /* we don't hold rtnl here ... */
  3144. flush_scheduled_work ();
  3145. if (dev->driver_info->unbind)
  3146. dev->driver_info->unbind (dev, intf);
  3147. free_netdev(net);
  3148. usb_put_dev (xdev);
  3149. }
  3150. /*-------------------------------------------------------------------------*/
  3151. static struct ethtool_ops usbnet_ethtool_ops;
  3152. // precondition: never called in_interrupt
  3153. static int
  3154. usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
  3155. {
  3156. struct usbnet *dev;
  3157. struct net_device *net;
  3158. struct usb_host_interface *interface;
  3159. struct driver_info *info;
  3160. struct usb_device *xdev;
  3161. int status;
  3162. info = (struct driver_info *) prod->driver_info;
  3163. if (!info) {
  3164. dev_dbg (&udev->dev, "blacklisted by %s\n", driver_name);
  3165. return -ENODEV;
  3166. }
  3167. xdev = interface_to_usbdev (udev);
  3168. interface = udev->cur_altsetting;
  3169. usb_get_dev (xdev);
  3170. status = -ENOMEM;
  3171. // set up our own records
  3172. net = alloc_etherdev(sizeof(*dev));
  3173. if (!net) {
  3174. dbg ("can't kmalloc dev");
  3175. goto out;
  3176. }
  3177. dev = netdev_priv(net);
  3178. dev->udev = xdev;
  3179. dev->driver_info = info;
  3180. dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV
  3181. | NETIF_MSG_PROBE | NETIF_MSG_LINK);
  3182. skb_queue_head_init (&dev->rxq);
  3183. skb_queue_head_init (&dev->txq);
  3184. skb_queue_head_init (&dev->done);
  3185. dev->bh.func = usbnet_bh;
  3186. dev->bh.data = (unsigned long) dev;
  3187. INIT_WORK (&dev->kevent, kevent, dev);
  3188. dev->delay.function = usbnet_bh;
  3189. dev->delay.data = (unsigned long) dev;
  3190. init_timer (&dev->delay);
  3191. SET_MODULE_OWNER (net);
  3192. dev->net = net;
  3193. strcpy (net->name, "usb%d");
  3194. memcpy (net->dev_addr, node_id, sizeof node_id);
  3195. #if 0
  3196. // dma_supported() is deeply broken on almost all architectures
  3197. // possible with some EHCI controllers
  3198. if (dma_supported (&udev->dev, DMA_64BIT_MASK))
  3199. net->features |= NETIF_F_HIGHDMA;
  3200. #endif
  3201. net->change_mtu = usbnet_change_mtu;
  3202. net->get_stats = usbnet_get_stats;
  3203. net->hard_start_xmit = usbnet_start_xmit;
  3204. net->open = usbnet_open;
  3205. net->stop = usbnet_stop;
  3206. net->watchdog_timeo = TX_TIMEOUT_JIFFIES;
  3207. net->tx_timeout = usbnet_tx_timeout;
  3208. net->do_ioctl = usbnet_ioctl;
  3209. net->ethtool_ops = &usbnet_ethtool_ops;
  3210. // allow device-specific bind/init procedures
  3211. // NOTE net->name still not usable ...
  3212. if (info->bind) {
  3213. status = info->bind (dev, udev);
  3214. // heuristic: "usb%d" for links we know are two-host,
  3215. // else "eth%d" when there's reasonable doubt. userspace
  3216. // can rename the link if it knows better.
  3217. if ((dev->driver_info->flags & FLAG_ETHER) != 0
  3218. && (net->dev_addr [0] & 0x02) == 0)
  3219. strcpy (net->name, "eth%d");
  3220. } else if (!info->in || info->out)
  3221. status = get_endpoints (dev, udev);
  3222. else {
  3223. dev->in = usb_rcvbulkpipe (xdev, info->in);
  3224. dev->out = usb_sndbulkpipe (xdev, info->out);
  3225. if (!(info->flags & FLAG_NO_SETINT))
  3226. status = usb_set_interface (xdev,
  3227. interface->desc.bInterfaceNumber,
  3228. interface->desc.bAlternateSetting);
  3229. else
  3230. status = 0;
  3231. }
  3232. if (status == 0 && dev->status)
  3233. status = init_status (dev, udev);
  3234. if (status < 0)
  3235. goto out1;
  3236. dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
  3237. SET_NETDEV_DEV(net, &udev->dev);
  3238. status = register_netdev (net);
  3239. if (status)
  3240. goto out3;
  3241. if (netif_msg_probe (dev))
  3242. devinfo (dev, "register usbnet at usb-%s-%s, %s, "
  3243. "%02x:%02x:%02x:%02x:%02x:%02x",
  3244. xdev->bus->bus_name, xdev->devpath,
  3245. dev->driver_info->description,
  3246. net->dev_addr [0], net->dev_addr [1],
  3247. net->dev_addr [2], net->dev_addr [3],
  3248. net->dev_addr [4], net->dev_addr [5]);
  3249. // ok, it's ready to go.
  3250. usb_set_intfdata (udev, dev);
  3251. // start as if the link is up
  3252. netif_device_attach (net);
  3253. return 0;
  3254. out3:
  3255. if (info->unbind)
  3256. info->unbind (dev, udev);
  3257. out1:
  3258. free_netdev(net);
  3259. out:
  3260. usb_put_dev(xdev);
  3261. return status;
  3262. }
  3263. /*-------------------------------------------------------------------------*/
  3264. #ifdef CONFIG_PM
  3265. static int usbnet_suspend (struct usb_interface *intf, pm_message_t message)
  3266. {
  3267. struct usbnet *dev = usb_get_intfdata(intf);
  3268. /* accelerate emptying of the rx and queues, to avoid
  3269. * having everything error out.
  3270. */
  3271. netif_device_detach (dev->net);
  3272. (void) unlink_urbs (dev, &dev->rxq);
  3273. (void) unlink_urbs (dev, &dev->txq);
  3274. intf->dev.power.power_state = PMSG_SUSPEND;
  3275. return 0;
  3276. }
  3277. static int usbnet_resume (struct usb_interface *intf)
  3278. {
  3279. struct usbnet *dev = usb_get_intfdata(intf);
  3280. intf->dev.power.power_state = PMSG_ON;
  3281. netif_device_attach (dev->net);
  3282. tasklet_schedule (&dev->bh);
  3283. return 0;
  3284. }
  3285. #else /* !CONFIG_PM */
  3286. #define usbnet_suspend NULL
  3287. #define usbnet_resume NULL
  3288. #endif /* CONFIG_PM */
  3289. /*-------------------------------------------------------------------------*/
  3290. #ifndef HAVE_HARDWARE
  3291. #error You need to configure some hardware for this driver
  3292. #endif
  3293. /*
  3294. * chip vendor names won't normally be on the cables, and
  3295. * may not be on the device.
  3296. */
  3297. static const struct usb_device_id products [] = {
  3298. #ifdef CONFIG_USB_ALI_M5632
  3299. {
  3300. USB_DEVICE (0x0402, 0x5632), // ALi defaults
  3301. .driver_info = (unsigned long) &ali_m5632_info,
  3302. },
  3303. #endif
  3304. #ifdef CONFIG_USB_AN2720
  3305. {
  3306. USB_DEVICE (0x0547, 0x2720), // AnchorChips defaults
  3307. .driver_info = (unsigned long) &an2720_info,
  3308. }, {
  3309. USB_DEVICE (0x0547, 0x2727), // Xircom PGUNET
  3310. .driver_info = (unsigned long) &an2720_info,
  3311. },
  3312. #endif
  3313. #ifdef CONFIG_USB_BELKIN
  3314. {
  3315. USB_DEVICE (0x050d, 0x0004), // Belkin
  3316. .driver_info = (unsigned long) &belkin_info,
  3317. }, {
  3318. USB_DEVICE (0x056c, 0x8100), // eTEK
  3319. .driver_info = (unsigned long) &belkin_info,
  3320. }, {
  3321. USB_DEVICE (0x0525, 0x9901), // Advance USBNET (eTEK)
  3322. .driver_info = (unsigned long) &belkin_info,
  3323. },
  3324. #endif
  3325. #ifdef CONFIG_USB_AX8817X
  3326. {
  3327. // Linksys USB200M
  3328. USB_DEVICE (0x077b, 0x2226),
  3329. .driver_info = (unsigned long) &ax8817x_info,
  3330. }, {
  3331. // Netgear FA120
  3332. USB_DEVICE (0x0846, 0x1040),
  3333. .driver_info = (unsigned long) &netgear_fa120_info,
  3334. }, {
  3335. // DLink DUB-E100
  3336. USB_DEVICE (0x2001, 0x1a00),
  3337. .driver_info = (unsigned long) &dlink_dub_e100_info,
  3338. }, {
  3339. // Intellinet, ST Lab USB Ethernet
  3340. USB_DEVICE (0x0b95, 0x1720),
  3341. .driver_info = (unsigned long) &ax8817x_info,
  3342. }, {
  3343. // Hawking UF200, TrendNet TU2-ET100
  3344. USB_DEVICE (0x07b8, 0x420a),
  3345. .driver_info = (unsigned long) &hawking_uf200_info,
  3346. }, {
  3347. // Billionton Systems, USB2AR
  3348. USB_DEVICE (0x08dd, 0x90ff),
  3349. .driver_info = (unsigned long) &ax8817x_info,
  3350. }, {
  3351. // ATEN UC210T
  3352. USB_DEVICE (0x0557, 0x2009),
  3353. .driver_info = (unsigned long) &ax8817x_info,
  3354. }, {
  3355. // Buffalo LUA-U2-KTX
  3356. USB_DEVICE (0x0411, 0x003d),
  3357. .driver_info = (unsigned long) &ax8817x_info,
  3358. }, {
  3359. // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter"
  3360. USB_DEVICE (0x6189, 0x182d),
  3361. .driver_info = (unsigned long) &ax8817x_info,
  3362. }, {
  3363. // corega FEther USB2-TX
  3364. USB_DEVICE (0x07aa, 0x0017),
  3365. .driver_info = (unsigned long) &ax8817x_info,
  3366. }, {
  3367. // Surecom EP-1427X-2
  3368. USB_DEVICE (0x1189, 0x0893),
  3369. .driver_info = (unsigned long) &ax8817x_info,
  3370. }, {
  3371. // goodway corp usb gwusb2e
  3372. USB_DEVICE (0x1631, 0x6200),
  3373. .driver_info = (unsigned long) &ax8817x_info,
  3374. }, {
  3375. // ASIX AX88772 10/100
  3376. USB_DEVICE (0x0b95, 0x7720),
  3377. .driver_info = (unsigned long) &ax88772_info,
  3378. },
  3379. #endif
  3380. #ifdef CONFIG_USB_EPSON2888
  3381. {
  3382. USB_DEVICE (0x0525, 0x2888), // EPSON USB client
  3383. .driver_info = (unsigned long) &epson2888_info,
  3384. },
  3385. #endif
  3386. #ifdef CONFIG_USB_GENESYS
  3387. {
  3388. USB_DEVICE (0x05e3, 0x0502), // GL620USB-A
  3389. .driver_info = (unsigned long) &genelink_info,
  3390. },
  3391. /* NOT: USB_DEVICE (0x05e3, 0x0501), // GL620USB
  3392. * that's half duplex, not currently supported
  3393. */
  3394. #endif
  3395. #ifdef CONFIG_USB_NET1080
  3396. {
  3397. USB_DEVICE (0x0525, 0x1080), // NetChip ref design
  3398. .driver_info = (unsigned long) &net1080_info,
  3399. }, {
  3400. USB_DEVICE (0x06D0, 0x0622), // Laplink Gold
  3401. .driver_info = (unsigned long) &net1080_info,
  3402. },
  3403. #endif
  3404. #ifdef CONFIG_USB_PL2301
  3405. {
  3406. USB_DEVICE (0x067b, 0x0000), // PL-2301
  3407. .driver_info = (unsigned long) &prolific_info,
  3408. }, {
  3409. USB_DEVICE (0x067b, 0x0001), // PL-2302
  3410. .driver_info = (unsigned long) &prolific_info,
  3411. },
  3412. #endif
  3413. #ifdef CONFIG_USB_KC2190
  3414. {
  3415. USB_DEVICE (0x050f, 0x0190), // KC-190
  3416. .driver_info = (unsigned long) &kc2190_info,
  3417. },
  3418. #endif
  3419. #ifdef CONFIG_USB_RNDIS
  3420. {
  3421. /* RNDIS is MSFT's un-official variant of CDC ACM */
  3422. USB_INTERFACE_INFO (USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
  3423. .driver_info = (unsigned long) &rndis_info,
  3424. },
  3425. #endif
  3426. #ifdef CONFIG_USB_ARMLINUX
  3427. /*
  3428. * SA-1100 using standard ARM Linux kernels, or compatible.
  3429. * Often used when talking to Linux PDAs (iPaq, Yopy, etc).
  3430. * The sa-1100 "usb-eth" driver handles the basic framing.
  3431. *
  3432. * PXA25x or PXA210 ... these use a "usb-eth" driver much like
  3433. * the sa1100 one, but hardware uses different endpoint numbers.
  3434. *
  3435. * Or the Linux "Ethernet" gadget on hardware that can't talk
  3436. * CDC Ethernet (e.g., no altsettings), in either of two modes:
  3437. * - acting just like the old "usb-eth" firmware, though
  3438. * the implementation is different
  3439. * - supporting RNDIS as the first/default configuration for
  3440. * MS-Windows interop; Linux needs to use the other config
  3441. */
  3442. {
  3443. // 1183 = 0x049F, both used as hex values?
  3444. // Compaq "Itsy" vendor/product id
  3445. USB_DEVICE (0x049F, 0x505A), // usb-eth, or compatible
  3446. .driver_info = (unsigned long) &linuxdev_info,
  3447. }, {
  3448. USB_DEVICE (0x0E7E, 0x1001), // G.Mate "Yopy"
  3449. .driver_info = (unsigned long) &yopy_info,
  3450. }, {
  3451. USB_DEVICE (0x8086, 0x07d3), // "blob" bootloader
  3452. .driver_info = (unsigned long) &blob_info,
  3453. }, {
  3454. USB_DEVICE (0x22b8, 0x600c), // USBNET Motorola E680
  3455. .driver_info = (unsigned long) &linuxdev_info,
  3456. }, {
  3457. // Linux Ethernet/RNDIS gadget on pxa210/25x/26x
  3458. // e.g. Gumstix, current OpenZaurus, ...
  3459. USB_DEVICE_VER (0x0525, 0xa4a2, 0x0203, 0x0203),
  3460. .driver_info = (unsigned long) &linuxdev_info,
  3461. },
  3462. #endif
  3463. #if defined(CONFIG_USB_ZAURUS) || defined(CONFIG_USB_CDCETHER)
  3464. /*
  3465. * SA-1100 based Sharp Zaurus ("collie"), or compatible.
  3466. * Same idea as above, but different framing.
  3467. *
  3468. * PXA-2xx based models are also lying-about-cdc.
  3469. * Some models don't even tell the same lies ...
  3470. *
  3471. * NOTE: OpenZaurus versions with 2.6 kernels won't use these entries,
  3472. * unlike the older ones with 2.4 "embedix" kernels.
  3473. *
  3474. * NOTE: These entries do double-duty, serving as blacklist entries
  3475. * whenever Zaurus support isn't enabled, but CDC Ethernet is.
  3476. */
  3477. #define ZAURUS_MASTER_INTERFACE \
  3478. .bInterfaceClass = USB_CLASS_COMM, \
  3479. .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \
  3480. .bInterfaceProtocol = USB_CDC_PROTO_NONE
  3481. {
  3482. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  3483. | USB_DEVICE_ID_MATCH_DEVICE,
  3484. .idVendor = 0x04DD,
  3485. .idProduct = 0x8004,
  3486. ZAURUS_MASTER_INTERFACE,
  3487. .driver_info = ZAURUS_STRONGARM_INFO,
  3488. }, {
  3489. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  3490. | USB_DEVICE_ID_MATCH_DEVICE,
  3491. .idVendor = 0x04DD,
  3492. .idProduct = 0x8005, /* A-300 */
  3493. ZAURUS_MASTER_INTERFACE,
  3494. .driver_info = ZAURUS_PXA_INFO,
  3495. }, {
  3496. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  3497. | USB_DEVICE_ID_MATCH_DEVICE,
  3498. .idVendor = 0x04DD,
  3499. .idProduct = 0x8006, /* B-500/SL-5600 */
  3500. ZAURUS_MASTER_INTERFACE,
  3501. .driver_info = ZAURUS_PXA_INFO,
  3502. }, {
  3503. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  3504. | USB_DEVICE_ID_MATCH_DEVICE,
  3505. .idVendor = 0x04DD,
  3506. .idProduct = 0x8007, /* C-700 */
  3507. ZAURUS_MASTER_INTERFACE,
  3508. .driver_info = ZAURUS_PXA_INFO,
  3509. }, {
  3510. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  3511. | USB_DEVICE_ID_MATCH_DEVICE,
  3512. .idVendor = 0x04DD,
  3513. .idProduct = 0x9031, /* C-750 C-760 */
  3514. ZAURUS_MASTER_INTERFACE,
  3515. .driver_info = ZAURUS_PXA_INFO,
  3516. }, {
  3517. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  3518. | USB_DEVICE_ID_MATCH_DEVICE,
  3519. .idVendor = 0x04DD,
  3520. .idProduct = 0x9032, /* SL-6000 */
  3521. ZAURUS_MASTER_INTERFACE,
  3522. .driver_info = ZAURUS_PXA_INFO,
  3523. }, {
  3524. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  3525. | USB_DEVICE_ID_MATCH_DEVICE,
  3526. .idVendor = 0x04DD,
  3527. /* reported with some C860 units */
  3528. .idProduct = 0x9050, /* C-860 */
  3529. ZAURUS_MASTER_INTERFACE,
  3530. .driver_info = ZAURUS_PXA_INFO,
  3531. },
  3532. #ifdef CONFIG_USB_ZAURUS
  3533. /* At least some (reports vary) PXA units have very different lies
  3534. * about their standards support: they claim to be cell phones with
  3535. * direct access to their radios. (They don't conform to CDC MDLM.)
  3536. */
  3537. {
  3538. USB_INTERFACE_INFO (USB_CLASS_COMM, USB_CDC_SUBCLASS_MDLM,
  3539. USB_CDC_PROTO_NONE),
  3540. .driver_info = (unsigned long) &bogus_mdlm_info,
  3541. },
  3542. #endif
  3543. /* Olympus has some models with a Zaurus-compatible option.
  3544. * R-1000 uses a FreeScale i.MXL cpu (ARMv4T)
  3545. */
  3546. {
  3547. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  3548. | USB_DEVICE_ID_MATCH_DEVICE,
  3549. .idVendor = 0x07B4,
  3550. .idProduct = 0x0F02, /* R-1000 */
  3551. ZAURUS_MASTER_INTERFACE,
  3552. .driver_info = OLYMPUS_MXL_INFO,
  3553. },
  3554. #endif
  3555. #ifdef CONFIG_USB_CDCETHER
  3556. {
  3557. /* CDC Ether uses two interfaces, not necessarily consecutive.
  3558. * We match the main interface, ignoring the optional device
  3559. * class so we could handle devices that aren't exclusively
  3560. * CDC ether.
  3561. *
  3562. * NOTE: this match must come AFTER entries working around
  3563. * bugs/quirks in a given product (like Zaurus, above).
  3564. */
  3565. USB_INTERFACE_INFO (USB_CLASS_COMM, USB_CDC_SUBCLASS_ETHERNET,
  3566. USB_CDC_PROTO_NONE),
  3567. .driver_info = (unsigned long) &cdc_info,
  3568. },
  3569. #endif
  3570. { }, // END
  3571. };
  3572. MODULE_DEVICE_TABLE (usb, products);
  3573. static struct usb_driver usbnet_driver = {
  3574. .owner = THIS_MODULE,
  3575. .name = driver_name,
  3576. .id_table = products,
  3577. .probe = usbnet_probe,
  3578. .disconnect = usbnet_disconnect,
  3579. .suspend = usbnet_suspend,
  3580. .resume = usbnet_resume,
  3581. };
  3582. /* Default ethtool_ops assigned. Devices can override in their bind() routine */
  3583. static struct ethtool_ops usbnet_ethtool_ops = {
  3584. .get_drvinfo = usbnet_get_drvinfo,
  3585. .get_link = usbnet_get_link,
  3586. .get_msglevel = usbnet_get_msglevel,
  3587. .set_msglevel = usbnet_set_msglevel,
  3588. };
  3589. /*-------------------------------------------------------------------------*/
  3590. static int __init usbnet_init (void)
  3591. {
  3592. // compiler should optimize these out
  3593. BUG_ON (sizeof (((struct sk_buff *)0)->cb)
  3594. < sizeof (struct skb_data));
  3595. #ifdef CONFIG_USB_CDCETHER
  3596. BUG_ON ((sizeof (((struct usbnet *)0)->data)
  3597. < sizeof (struct cdc_state)));
  3598. #endif
  3599. random_ether_addr(node_id);
  3600. return usb_register(&usbnet_driver);
  3601. }
  3602. module_init (usbnet_init);
  3603. static void __exit usbnet_exit (void)
  3604. {
  3605. usb_deregister (&usbnet_driver);
  3606. }
  3607. module_exit (usbnet_exit);
  3608. MODULE_AUTHOR ("David Brownell <dbrownell@users.sourceforge.net>");
  3609. MODULE_DESCRIPTION ("USB Host-to-Host Link Drivers (numerous vendors)");
  3610. MODULE_LICENSE ("GPL");