smsc75xx.c 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344
  1. /***************************************************************************
  2. *
  3. * Copyright (C) 2007-2010 SMSC
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  17. *
  18. *****************************************************************************/
  19. #include <linux/module.h>
  20. #include <linux/kmod.h>
  21. #include <linux/netdevice.h>
  22. #include <linux/etherdevice.h>
  23. #include <linux/ethtool.h>
  24. #include <linux/mii.h>
  25. #include <linux/usb.h>
  26. #include <linux/bitrev.h>
  27. #include <linux/crc16.h>
  28. #include <linux/crc32.h>
  29. #include <linux/usb/usbnet.h>
  30. #include <linux/slab.h>
  31. #include "smsc75xx.h"
  32. #define SMSC_CHIPNAME "smsc75xx"
  33. #define SMSC_DRIVER_VERSION "1.0.0"
  34. #define HS_USB_PKT_SIZE (512)
  35. #define FS_USB_PKT_SIZE (64)
  36. #define DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * HS_USB_PKT_SIZE)
  37. #define DEFAULT_FS_BURST_CAP_SIZE (6 * 1024 + 33 * FS_USB_PKT_SIZE)
  38. #define DEFAULT_BULK_IN_DELAY (0x00002000)
  39. #define MAX_SINGLE_PACKET_SIZE (9000)
  40. #define LAN75XX_EEPROM_MAGIC (0x7500)
  41. #define EEPROM_MAC_OFFSET (0x01)
  42. #define DEFAULT_TX_CSUM_ENABLE (true)
  43. #define DEFAULT_RX_CSUM_ENABLE (true)
  44. #define SMSC75XX_INTERNAL_PHY_ID (1)
  45. #define SMSC75XX_TX_OVERHEAD (8)
  46. #define MAX_RX_FIFO_SIZE (20 * 1024)
  47. #define MAX_TX_FIFO_SIZE (12 * 1024)
  48. #define USB_VENDOR_ID_SMSC (0x0424)
  49. #define USB_PRODUCT_ID_LAN7500 (0x7500)
  50. #define USB_PRODUCT_ID_LAN7505 (0x7505)
  51. #define RXW_PADDING 2
  52. #define SUPPORTED_WAKE (WAKE_PHY | WAKE_UCAST | WAKE_BCAST | \
  53. WAKE_MCAST | WAKE_ARP | WAKE_MAGIC)
  54. #define SUSPEND_SUSPEND0 (0x01)
  55. #define SUSPEND_SUSPEND1 (0x02)
  56. #define SUSPEND_SUSPEND2 (0x04)
  57. #define SUSPEND_SUSPEND3 (0x08)
  58. #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
  59. SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
  60. struct smsc75xx_priv {
  61. struct usbnet *dev;
  62. u32 rfe_ctl;
  63. u32 wolopts;
  64. u32 multicast_hash_table[DP_SEL_VHF_HASH_LEN];
  65. struct mutex dataport_mutex;
  66. spinlock_t rfe_ctl_lock;
  67. struct work_struct set_multicast;
  68. u8 suspend_flags;
  69. };
  70. struct usb_context {
  71. struct usb_ctrlrequest req;
  72. struct usbnet *dev;
  73. };
  74. static bool turbo_mode = true;
  75. module_param(turbo_mode, bool, 0644);
  76. MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
  77. static int smsc75xx_link_ok_nopm(struct usbnet *dev);
  78. static int smsc75xx_phy_gig_workaround(struct usbnet *dev);
  79. static int __must_check __smsc75xx_read_reg(struct usbnet *dev, u32 index,
  80. u32 *data, int in_pm)
  81. {
  82. u32 buf;
  83. int ret;
  84. int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16);
  85. BUG_ON(!dev);
  86. if (!in_pm)
  87. fn = usbnet_read_cmd;
  88. else
  89. fn = usbnet_read_cmd_nopm;
  90. ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN
  91. | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  92. 0, index, &buf, 4);
  93. if (unlikely(ret < 0))
  94. netdev_warn(dev->net, "Failed to read reg index 0x%08x: %d\n",
  95. index, ret);
  96. le32_to_cpus(&buf);
  97. *data = buf;
  98. return ret;
  99. }
  100. static int __must_check __smsc75xx_write_reg(struct usbnet *dev, u32 index,
  101. u32 data, int in_pm)
  102. {
  103. u32 buf;
  104. int ret;
  105. int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16);
  106. BUG_ON(!dev);
  107. if (!in_pm)
  108. fn = usbnet_write_cmd;
  109. else
  110. fn = usbnet_write_cmd_nopm;
  111. buf = data;
  112. cpu_to_le32s(&buf);
  113. ret = fn(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, USB_DIR_OUT
  114. | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  115. 0, index, &buf, 4);
  116. if (unlikely(ret < 0))
  117. netdev_warn(dev->net, "Failed to write reg index 0x%08x: %d\n",
  118. index, ret);
  119. return ret;
  120. }
  121. static int __must_check smsc75xx_read_reg_nopm(struct usbnet *dev, u32 index,
  122. u32 *data)
  123. {
  124. return __smsc75xx_read_reg(dev, index, data, 1);
  125. }
  126. static int __must_check smsc75xx_write_reg_nopm(struct usbnet *dev, u32 index,
  127. u32 data)
  128. {
  129. return __smsc75xx_write_reg(dev, index, data, 1);
  130. }
  131. static int __must_check smsc75xx_read_reg(struct usbnet *dev, u32 index,
  132. u32 *data)
  133. {
  134. return __smsc75xx_read_reg(dev, index, data, 0);
  135. }
  136. static int __must_check smsc75xx_write_reg(struct usbnet *dev, u32 index,
  137. u32 data)
  138. {
  139. return __smsc75xx_write_reg(dev, index, data, 0);
  140. }
  141. /* Loop until the read is completed with timeout
  142. * called with phy_mutex held */
  143. static __must_check int __smsc75xx_phy_wait_not_busy(struct usbnet *dev,
  144. int in_pm)
  145. {
  146. unsigned long start_time = jiffies;
  147. u32 val;
  148. int ret;
  149. do {
  150. ret = __smsc75xx_read_reg(dev, MII_ACCESS, &val, in_pm);
  151. if (ret < 0) {
  152. netdev_warn(dev->net, "Error reading MII_ACCESS\n");
  153. return ret;
  154. }
  155. if (!(val & MII_ACCESS_BUSY))
  156. return 0;
  157. } while (!time_after(jiffies, start_time + HZ));
  158. return -EIO;
  159. }
  160. static int __smsc75xx_mdio_read(struct net_device *netdev, int phy_id, int idx,
  161. int in_pm)
  162. {
  163. struct usbnet *dev = netdev_priv(netdev);
  164. u32 val, addr;
  165. int ret;
  166. mutex_lock(&dev->phy_mutex);
  167. /* confirm MII not busy */
  168. ret = __smsc75xx_phy_wait_not_busy(dev, in_pm);
  169. if (ret < 0) {
  170. netdev_warn(dev->net, "MII is busy in smsc75xx_mdio_read\n");
  171. goto done;
  172. }
  173. /* set the address, index & direction (read from PHY) */
  174. phy_id &= dev->mii.phy_id_mask;
  175. idx &= dev->mii.reg_num_mask;
  176. addr = ((phy_id << MII_ACCESS_PHY_ADDR_SHIFT) & MII_ACCESS_PHY_ADDR)
  177. | ((idx << MII_ACCESS_REG_ADDR_SHIFT) & MII_ACCESS_REG_ADDR)
  178. | MII_ACCESS_READ | MII_ACCESS_BUSY;
  179. ret = __smsc75xx_write_reg(dev, MII_ACCESS, addr, in_pm);
  180. if (ret < 0) {
  181. netdev_warn(dev->net, "Error writing MII_ACCESS\n");
  182. goto done;
  183. }
  184. ret = __smsc75xx_phy_wait_not_busy(dev, in_pm);
  185. if (ret < 0) {
  186. netdev_warn(dev->net, "Timed out reading MII reg %02X\n", idx);
  187. goto done;
  188. }
  189. ret = __smsc75xx_read_reg(dev, MII_DATA, &val, in_pm);
  190. if (ret < 0) {
  191. netdev_warn(dev->net, "Error reading MII_DATA\n");
  192. goto done;
  193. }
  194. ret = (u16)(val & 0xFFFF);
  195. done:
  196. mutex_unlock(&dev->phy_mutex);
  197. return ret;
  198. }
  199. static void __smsc75xx_mdio_write(struct net_device *netdev, int phy_id,
  200. int idx, int regval, int in_pm)
  201. {
  202. struct usbnet *dev = netdev_priv(netdev);
  203. u32 val, addr;
  204. int ret;
  205. mutex_lock(&dev->phy_mutex);
  206. /* confirm MII not busy */
  207. ret = __smsc75xx_phy_wait_not_busy(dev, in_pm);
  208. if (ret < 0) {
  209. netdev_warn(dev->net, "MII is busy in smsc75xx_mdio_write\n");
  210. goto done;
  211. }
  212. val = regval;
  213. ret = __smsc75xx_write_reg(dev, MII_DATA, val, in_pm);
  214. if (ret < 0) {
  215. netdev_warn(dev->net, "Error writing MII_DATA\n");
  216. goto done;
  217. }
  218. /* set the address, index & direction (write to PHY) */
  219. phy_id &= dev->mii.phy_id_mask;
  220. idx &= dev->mii.reg_num_mask;
  221. addr = ((phy_id << MII_ACCESS_PHY_ADDR_SHIFT) & MII_ACCESS_PHY_ADDR)
  222. | ((idx << MII_ACCESS_REG_ADDR_SHIFT) & MII_ACCESS_REG_ADDR)
  223. | MII_ACCESS_WRITE | MII_ACCESS_BUSY;
  224. ret = __smsc75xx_write_reg(dev, MII_ACCESS, addr, in_pm);
  225. if (ret < 0) {
  226. netdev_warn(dev->net, "Error writing MII_ACCESS\n");
  227. goto done;
  228. }
  229. ret = __smsc75xx_phy_wait_not_busy(dev, in_pm);
  230. if (ret < 0) {
  231. netdev_warn(dev->net, "Timed out writing MII reg %02X\n", idx);
  232. goto done;
  233. }
  234. done:
  235. mutex_unlock(&dev->phy_mutex);
  236. }
  237. static int smsc75xx_mdio_read_nopm(struct net_device *netdev, int phy_id,
  238. int idx)
  239. {
  240. return __smsc75xx_mdio_read(netdev, phy_id, idx, 1);
  241. }
  242. static void smsc75xx_mdio_write_nopm(struct net_device *netdev, int phy_id,
  243. int idx, int regval)
  244. {
  245. __smsc75xx_mdio_write(netdev, phy_id, idx, regval, 1);
  246. }
  247. static int smsc75xx_mdio_read(struct net_device *netdev, int phy_id, int idx)
  248. {
  249. return __smsc75xx_mdio_read(netdev, phy_id, idx, 0);
  250. }
  251. static void smsc75xx_mdio_write(struct net_device *netdev, int phy_id, int idx,
  252. int regval)
  253. {
  254. __smsc75xx_mdio_write(netdev, phy_id, idx, regval, 0);
  255. }
  256. static int smsc75xx_wait_eeprom(struct usbnet *dev)
  257. {
  258. unsigned long start_time = jiffies;
  259. u32 val;
  260. int ret;
  261. do {
  262. ret = smsc75xx_read_reg(dev, E2P_CMD, &val);
  263. if (ret < 0) {
  264. netdev_warn(dev->net, "Error reading E2P_CMD\n");
  265. return ret;
  266. }
  267. if (!(val & E2P_CMD_BUSY) || (val & E2P_CMD_TIMEOUT))
  268. break;
  269. udelay(40);
  270. } while (!time_after(jiffies, start_time + HZ));
  271. if (val & (E2P_CMD_TIMEOUT | E2P_CMD_BUSY)) {
  272. netdev_warn(dev->net, "EEPROM read operation timeout\n");
  273. return -EIO;
  274. }
  275. return 0;
  276. }
  277. static int smsc75xx_eeprom_confirm_not_busy(struct usbnet *dev)
  278. {
  279. unsigned long start_time = jiffies;
  280. u32 val;
  281. int ret;
  282. do {
  283. ret = smsc75xx_read_reg(dev, E2P_CMD, &val);
  284. if (ret < 0) {
  285. netdev_warn(dev->net, "Error reading E2P_CMD\n");
  286. return ret;
  287. }
  288. if (!(val & E2P_CMD_BUSY))
  289. return 0;
  290. udelay(40);
  291. } while (!time_after(jiffies, start_time + HZ));
  292. netdev_warn(dev->net, "EEPROM is busy\n");
  293. return -EIO;
  294. }
  295. static int smsc75xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length,
  296. u8 *data)
  297. {
  298. u32 val;
  299. int i, ret;
  300. BUG_ON(!dev);
  301. BUG_ON(!data);
  302. ret = smsc75xx_eeprom_confirm_not_busy(dev);
  303. if (ret)
  304. return ret;
  305. for (i = 0; i < length; i++) {
  306. val = E2P_CMD_BUSY | E2P_CMD_READ | (offset & E2P_CMD_ADDR);
  307. ret = smsc75xx_write_reg(dev, E2P_CMD, val);
  308. if (ret < 0) {
  309. netdev_warn(dev->net, "Error writing E2P_CMD\n");
  310. return ret;
  311. }
  312. ret = smsc75xx_wait_eeprom(dev);
  313. if (ret < 0)
  314. return ret;
  315. ret = smsc75xx_read_reg(dev, E2P_DATA, &val);
  316. if (ret < 0) {
  317. netdev_warn(dev->net, "Error reading E2P_DATA\n");
  318. return ret;
  319. }
  320. data[i] = val & 0xFF;
  321. offset++;
  322. }
  323. return 0;
  324. }
  325. static int smsc75xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length,
  326. u8 *data)
  327. {
  328. u32 val;
  329. int i, ret;
  330. BUG_ON(!dev);
  331. BUG_ON(!data);
  332. ret = smsc75xx_eeprom_confirm_not_busy(dev);
  333. if (ret)
  334. return ret;
  335. /* Issue write/erase enable command */
  336. val = E2P_CMD_BUSY | E2P_CMD_EWEN;
  337. ret = smsc75xx_write_reg(dev, E2P_CMD, val);
  338. if (ret < 0) {
  339. netdev_warn(dev->net, "Error writing E2P_CMD\n");
  340. return ret;
  341. }
  342. ret = smsc75xx_wait_eeprom(dev);
  343. if (ret < 0)
  344. return ret;
  345. for (i = 0; i < length; i++) {
  346. /* Fill data register */
  347. val = data[i];
  348. ret = smsc75xx_write_reg(dev, E2P_DATA, val);
  349. if (ret < 0) {
  350. netdev_warn(dev->net, "Error writing E2P_DATA\n");
  351. return ret;
  352. }
  353. /* Send "write" command */
  354. val = E2P_CMD_BUSY | E2P_CMD_WRITE | (offset & E2P_CMD_ADDR);
  355. ret = smsc75xx_write_reg(dev, E2P_CMD, val);
  356. if (ret < 0) {
  357. netdev_warn(dev->net, "Error writing E2P_CMD\n");
  358. return ret;
  359. }
  360. ret = smsc75xx_wait_eeprom(dev);
  361. if (ret < 0)
  362. return ret;
  363. offset++;
  364. }
  365. return 0;
  366. }
  367. static int smsc75xx_dataport_wait_not_busy(struct usbnet *dev)
  368. {
  369. int i, ret;
  370. for (i = 0; i < 100; i++) {
  371. u32 dp_sel;
  372. ret = smsc75xx_read_reg(dev, DP_SEL, &dp_sel);
  373. if (ret < 0) {
  374. netdev_warn(dev->net, "Error reading DP_SEL\n");
  375. return ret;
  376. }
  377. if (dp_sel & DP_SEL_DPRDY)
  378. return 0;
  379. udelay(40);
  380. }
  381. netdev_warn(dev->net, "smsc75xx_dataport_wait_not_busy timed out\n");
  382. return -EIO;
  383. }
  384. static int smsc75xx_dataport_write(struct usbnet *dev, u32 ram_select, u32 addr,
  385. u32 length, u32 *buf)
  386. {
  387. struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
  388. u32 dp_sel;
  389. int i, ret;
  390. mutex_lock(&pdata->dataport_mutex);
  391. ret = smsc75xx_dataport_wait_not_busy(dev);
  392. if (ret < 0) {
  393. netdev_warn(dev->net, "smsc75xx_dataport_write busy on entry\n");
  394. goto done;
  395. }
  396. ret = smsc75xx_read_reg(dev, DP_SEL, &dp_sel);
  397. if (ret < 0) {
  398. netdev_warn(dev->net, "Error reading DP_SEL\n");
  399. goto done;
  400. }
  401. dp_sel &= ~DP_SEL_RSEL;
  402. dp_sel |= ram_select;
  403. ret = smsc75xx_write_reg(dev, DP_SEL, dp_sel);
  404. if (ret < 0) {
  405. netdev_warn(dev->net, "Error writing DP_SEL\n");
  406. goto done;
  407. }
  408. for (i = 0; i < length; i++) {
  409. ret = smsc75xx_write_reg(dev, DP_ADDR, addr + i);
  410. if (ret < 0) {
  411. netdev_warn(dev->net, "Error writing DP_ADDR\n");
  412. goto done;
  413. }
  414. ret = smsc75xx_write_reg(dev, DP_DATA, buf[i]);
  415. if (ret < 0) {
  416. netdev_warn(dev->net, "Error writing DP_DATA\n");
  417. goto done;
  418. }
  419. ret = smsc75xx_write_reg(dev, DP_CMD, DP_CMD_WRITE);
  420. if (ret < 0) {
  421. netdev_warn(dev->net, "Error writing DP_CMD\n");
  422. goto done;
  423. }
  424. ret = smsc75xx_dataport_wait_not_busy(dev);
  425. if (ret < 0) {
  426. netdev_warn(dev->net, "smsc75xx_dataport_write timeout\n");
  427. goto done;
  428. }
  429. }
  430. done:
  431. mutex_unlock(&pdata->dataport_mutex);
  432. return ret;
  433. }
  434. /* returns hash bit number for given MAC address */
  435. static u32 smsc75xx_hash(char addr[ETH_ALEN])
  436. {
  437. return (ether_crc(ETH_ALEN, addr) >> 23) & 0x1ff;
  438. }
  439. static void smsc75xx_deferred_multicast_write(struct work_struct *param)
  440. {
  441. struct smsc75xx_priv *pdata =
  442. container_of(param, struct smsc75xx_priv, set_multicast);
  443. struct usbnet *dev = pdata->dev;
  444. int ret;
  445. netif_dbg(dev, drv, dev->net, "deferred multicast write 0x%08x\n",
  446. pdata->rfe_ctl);
  447. smsc75xx_dataport_write(dev, DP_SEL_VHF, DP_SEL_VHF_VLAN_LEN,
  448. DP_SEL_VHF_HASH_LEN, pdata->multicast_hash_table);
  449. ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl);
  450. if (ret < 0)
  451. netdev_warn(dev->net, "Error writing RFE_CRL\n");
  452. }
  453. static void smsc75xx_set_multicast(struct net_device *netdev)
  454. {
  455. struct usbnet *dev = netdev_priv(netdev);
  456. struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
  457. unsigned long flags;
  458. int i;
  459. spin_lock_irqsave(&pdata->rfe_ctl_lock, flags);
  460. pdata->rfe_ctl &=
  461. ~(RFE_CTL_AU | RFE_CTL_AM | RFE_CTL_DPF | RFE_CTL_MHF);
  462. pdata->rfe_ctl |= RFE_CTL_AB;
  463. for (i = 0; i < DP_SEL_VHF_HASH_LEN; i++)
  464. pdata->multicast_hash_table[i] = 0;
  465. if (dev->net->flags & IFF_PROMISC) {
  466. netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n");
  467. pdata->rfe_ctl |= RFE_CTL_AM | RFE_CTL_AU;
  468. } else if (dev->net->flags & IFF_ALLMULTI) {
  469. netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n");
  470. pdata->rfe_ctl |= RFE_CTL_AM | RFE_CTL_DPF;
  471. } else if (!netdev_mc_empty(dev->net)) {
  472. struct netdev_hw_addr *ha;
  473. netif_dbg(dev, drv, dev->net, "receive multicast hash filter\n");
  474. pdata->rfe_ctl |= RFE_CTL_MHF | RFE_CTL_DPF;
  475. netdev_for_each_mc_addr(ha, netdev) {
  476. u32 bitnum = smsc75xx_hash(ha->addr);
  477. pdata->multicast_hash_table[bitnum / 32] |=
  478. (1 << (bitnum % 32));
  479. }
  480. } else {
  481. netif_dbg(dev, drv, dev->net, "receive own packets only\n");
  482. pdata->rfe_ctl |= RFE_CTL_DPF;
  483. }
  484. spin_unlock_irqrestore(&pdata->rfe_ctl_lock, flags);
  485. /* defer register writes to a sleepable context */
  486. schedule_work(&pdata->set_multicast);
  487. }
  488. static int smsc75xx_update_flowcontrol(struct usbnet *dev, u8 duplex,
  489. u16 lcladv, u16 rmtadv)
  490. {
  491. u32 flow = 0, fct_flow = 0;
  492. int ret;
  493. if (duplex == DUPLEX_FULL) {
  494. u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv);
  495. if (cap & FLOW_CTRL_TX) {
  496. flow = (FLOW_TX_FCEN | 0xFFFF);
  497. /* set fct_flow thresholds to 20% and 80% */
  498. fct_flow = (8 << 8) | 32;
  499. }
  500. if (cap & FLOW_CTRL_RX)
  501. flow |= FLOW_RX_FCEN;
  502. netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n",
  503. (cap & FLOW_CTRL_RX ? "enabled" : "disabled"),
  504. (cap & FLOW_CTRL_TX ? "enabled" : "disabled"));
  505. } else {
  506. netif_dbg(dev, link, dev->net, "half duplex\n");
  507. }
  508. ret = smsc75xx_write_reg(dev, FLOW, flow);
  509. if (ret < 0) {
  510. netdev_warn(dev->net, "Error writing FLOW\n");
  511. return ret;
  512. }
  513. ret = smsc75xx_write_reg(dev, FCT_FLOW, fct_flow);
  514. if (ret < 0) {
  515. netdev_warn(dev->net, "Error writing FCT_FLOW\n");
  516. return ret;
  517. }
  518. return 0;
  519. }
  520. static int smsc75xx_link_reset(struct usbnet *dev)
  521. {
  522. struct mii_if_info *mii = &dev->mii;
  523. struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
  524. u16 lcladv, rmtadv;
  525. int ret;
  526. /* write to clear phy interrupt status */
  527. smsc75xx_mdio_write(dev->net, mii->phy_id, PHY_INT_SRC,
  528. PHY_INT_SRC_CLEAR_ALL);
  529. ret = smsc75xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL);
  530. if (ret < 0) {
  531. netdev_warn(dev->net, "Error writing INT_STS\n");
  532. return ret;
  533. }
  534. mii_check_media(mii, 1, 1);
  535. mii_ethtool_gset(&dev->mii, &ecmd);
  536. lcladv = smsc75xx_mdio_read(dev->net, mii->phy_id, MII_ADVERTISE);
  537. rmtadv = smsc75xx_mdio_read(dev->net, mii->phy_id, MII_LPA);
  538. netif_dbg(dev, link, dev->net, "speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n",
  539. ethtool_cmd_speed(&ecmd), ecmd.duplex, lcladv, rmtadv);
  540. return smsc75xx_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv);
  541. }
  542. static void smsc75xx_status(struct usbnet *dev, struct urb *urb)
  543. {
  544. u32 intdata;
  545. if (urb->actual_length != 4) {
  546. netdev_warn(dev->net, "unexpected urb length %d\n",
  547. urb->actual_length);
  548. return;
  549. }
  550. memcpy(&intdata, urb->transfer_buffer, 4);
  551. le32_to_cpus(&intdata);
  552. netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata);
  553. if (intdata & INT_ENP_PHY_INT)
  554. usbnet_defer_kevent(dev, EVENT_LINK_RESET);
  555. else
  556. netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n",
  557. intdata);
  558. }
  559. static int smsc75xx_ethtool_get_eeprom_len(struct net_device *net)
  560. {
  561. return MAX_EEPROM_SIZE;
  562. }
  563. static int smsc75xx_ethtool_get_eeprom(struct net_device *netdev,
  564. struct ethtool_eeprom *ee, u8 *data)
  565. {
  566. struct usbnet *dev = netdev_priv(netdev);
  567. ee->magic = LAN75XX_EEPROM_MAGIC;
  568. return smsc75xx_read_eeprom(dev, ee->offset, ee->len, data);
  569. }
  570. static int smsc75xx_ethtool_set_eeprom(struct net_device *netdev,
  571. struct ethtool_eeprom *ee, u8 *data)
  572. {
  573. struct usbnet *dev = netdev_priv(netdev);
  574. if (ee->magic != LAN75XX_EEPROM_MAGIC) {
  575. netdev_warn(dev->net, "EEPROM: magic value mismatch: 0x%x\n",
  576. ee->magic);
  577. return -EINVAL;
  578. }
  579. return smsc75xx_write_eeprom(dev, ee->offset, ee->len, data);
  580. }
  581. static void smsc75xx_ethtool_get_wol(struct net_device *net,
  582. struct ethtool_wolinfo *wolinfo)
  583. {
  584. struct usbnet *dev = netdev_priv(net);
  585. struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
  586. wolinfo->supported = SUPPORTED_WAKE;
  587. wolinfo->wolopts = pdata->wolopts;
  588. }
  589. static int smsc75xx_ethtool_set_wol(struct net_device *net,
  590. struct ethtool_wolinfo *wolinfo)
  591. {
  592. struct usbnet *dev = netdev_priv(net);
  593. struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
  594. int ret;
  595. if (wolinfo->wolopts & ~SUPPORTED_WAKE)
  596. return -EINVAL;
  597. pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE;
  598. ret = device_set_wakeup_enable(&dev->udev->dev, pdata->wolopts);
  599. if (ret < 0)
  600. netdev_warn(dev->net, "device_set_wakeup_enable error %d\n", ret);
  601. return ret;
  602. }
  603. static const struct ethtool_ops smsc75xx_ethtool_ops = {
  604. .get_link = usbnet_get_link,
  605. .nway_reset = usbnet_nway_reset,
  606. .get_drvinfo = usbnet_get_drvinfo,
  607. .get_msglevel = usbnet_get_msglevel,
  608. .set_msglevel = usbnet_set_msglevel,
  609. .get_settings = usbnet_get_settings,
  610. .set_settings = usbnet_set_settings,
  611. .get_eeprom_len = smsc75xx_ethtool_get_eeprom_len,
  612. .get_eeprom = smsc75xx_ethtool_get_eeprom,
  613. .set_eeprom = smsc75xx_ethtool_set_eeprom,
  614. .get_wol = smsc75xx_ethtool_get_wol,
  615. .set_wol = smsc75xx_ethtool_set_wol,
  616. };
  617. static int smsc75xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
  618. {
  619. struct usbnet *dev = netdev_priv(netdev);
  620. if (!netif_running(netdev))
  621. return -EINVAL;
  622. return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
  623. }
  624. static void smsc75xx_init_mac_address(struct usbnet *dev)
  625. {
  626. /* try reading mac address from EEPROM */
  627. if (smsc75xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
  628. dev->net->dev_addr) == 0) {
  629. if (is_valid_ether_addr(dev->net->dev_addr)) {
  630. /* eeprom values are valid so use them */
  631. netif_dbg(dev, ifup, dev->net,
  632. "MAC address read from EEPROM\n");
  633. return;
  634. }
  635. }
  636. /* no eeprom, or eeprom values are invalid. generate random MAC */
  637. eth_hw_addr_random(dev->net);
  638. netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");
  639. }
  640. static int smsc75xx_set_mac_address(struct usbnet *dev)
  641. {
  642. u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 |
  643. dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24;
  644. u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8;
  645. int ret = smsc75xx_write_reg(dev, RX_ADDRH, addr_hi);
  646. if (ret < 0) {
  647. netdev_warn(dev->net, "Failed to write RX_ADDRH: %d\n", ret);
  648. return ret;
  649. }
  650. ret = smsc75xx_write_reg(dev, RX_ADDRL, addr_lo);
  651. if (ret < 0) {
  652. netdev_warn(dev->net, "Failed to write RX_ADDRL: %d\n", ret);
  653. return ret;
  654. }
  655. addr_hi |= ADDR_FILTX_FB_VALID;
  656. ret = smsc75xx_write_reg(dev, ADDR_FILTX, addr_hi);
  657. if (ret < 0) {
  658. netdev_warn(dev->net, "Failed to write ADDR_FILTX: %d\n", ret);
  659. return ret;
  660. }
  661. ret = smsc75xx_write_reg(dev, ADDR_FILTX + 4, addr_lo);
  662. if (ret < 0)
  663. netdev_warn(dev->net, "Failed to write ADDR_FILTX+4: %d\n", ret);
  664. return ret;
  665. }
  666. static int smsc75xx_phy_initialize(struct usbnet *dev)
  667. {
  668. int bmcr, ret, timeout = 0;
  669. /* Initialize MII structure */
  670. dev->mii.dev = dev->net;
  671. dev->mii.mdio_read = smsc75xx_mdio_read;
  672. dev->mii.mdio_write = smsc75xx_mdio_write;
  673. dev->mii.phy_id_mask = 0x1f;
  674. dev->mii.reg_num_mask = 0x1f;
  675. dev->mii.supports_gmii = 1;
  676. dev->mii.phy_id = SMSC75XX_INTERNAL_PHY_ID;
  677. /* reset phy and wait for reset to complete */
  678. smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
  679. do {
  680. msleep(10);
  681. bmcr = smsc75xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR);
  682. if (bmcr < 0) {
  683. netdev_warn(dev->net, "Error reading MII_BMCR\n");
  684. return bmcr;
  685. }
  686. timeout++;
  687. } while ((bmcr & BMCR_RESET) && (timeout < 100));
  688. if (timeout >= 100) {
  689. netdev_warn(dev->net, "timeout on PHY Reset\n");
  690. return -EIO;
  691. }
  692. /* phy workaround for gig link */
  693. smsc75xx_phy_gig_workaround(dev);
  694. smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
  695. ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP |
  696. ADVERTISE_PAUSE_ASYM);
  697. smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_CTRL1000,
  698. ADVERTISE_1000FULL);
  699. /* read and write to clear phy interrupt status */
  700. ret = smsc75xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC);
  701. if (ret < 0) {
  702. netdev_warn(dev->net, "Error reading PHY_INT_SRC\n");
  703. return ret;
  704. }
  705. smsc75xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_SRC, 0xffff);
  706. smsc75xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK,
  707. PHY_INT_MASK_DEFAULT);
  708. mii_nway_restart(&dev->mii);
  709. netif_dbg(dev, ifup, dev->net, "phy initialised successfully\n");
  710. return 0;
  711. }
  712. static int smsc75xx_set_rx_max_frame_length(struct usbnet *dev, int size)
  713. {
  714. int ret = 0;
  715. u32 buf;
  716. bool rxenabled;
  717. ret = smsc75xx_read_reg(dev, MAC_RX, &buf);
  718. if (ret < 0) {
  719. netdev_warn(dev->net, "Failed to read MAC_RX: %d\n", ret);
  720. return ret;
  721. }
  722. rxenabled = ((buf & MAC_RX_RXEN) != 0);
  723. if (rxenabled) {
  724. buf &= ~MAC_RX_RXEN;
  725. ret = smsc75xx_write_reg(dev, MAC_RX, buf);
  726. if (ret < 0) {
  727. netdev_warn(dev->net, "Failed to write MAC_RX: %d\n", ret);
  728. return ret;
  729. }
  730. }
  731. /* add 4 to size for FCS */
  732. buf &= ~MAC_RX_MAX_SIZE;
  733. buf |= (((size + 4) << MAC_RX_MAX_SIZE_SHIFT) & MAC_RX_MAX_SIZE);
  734. ret = smsc75xx_write_reg(dev, MAC_RX, buf);
  735. if (ret < 0) {
  736. netdev_warn(dev->net, "Failed to write MAC_RX: %d\n", ret);
  737. return ret;
  738. }
  739. if (rxenabled) {
  740. buf |= MAC_RX_RXEN;
  741. ret = smsc75xx_write_reg(dev, MAC_RX, buf);
  742. if (ret < 0) {
  743. netdev_warn(dev->net, "Failed to write MAC_RX: %d\n", ret);
  744. return ret;
  745. }
  746. }
  747. return 0;
  748. }
  749. static int smsc75xx_change_mtu(struct net_device *netdev, int new_mtu)
  750. {
  751. struct usbnet *dev = netdev_priv(netdev);
  752. int ret;
  753. if (new_mtu > MAX_SINGLE_PACKET_SIZE)
  754. return -EINVAL;
  755. ret = smsc75xx_set_rx_max_frame_length(dev, new_mtu + ETH_HLEN);
  756. if (ret < 0) {
  757. netdev_warn(dev->net, "Failed to set mac rx frame length\n");
  758. return ret;
  759. }
  760. return usbnet_change_mtu(netdev, new_mtu);
  761. }
  762. /* Enable or disable Rx checksum offload engine */
  763. static int smsc75xx_set_features(struct net_device *netdev,
  764. netdev_features_t features)
  765. {
  766. struct usbnet *dev = netdev_priv(netdev);
  767. struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
  768. unsigned long flags;
  769. int ret;
  770. spin_lock_irqsave(&pdata->rfe_ctl_lock, flags);
  771. if (features & NETIF_F_RXCSUM)
  772. pdata->rfe_ctl |= RFE_CTL_TCPUDP_CKM | RFE_CTL_IP_CKM;
  773. else
  774. pdata->rfe_ctl &= ~(RFE_CTL_TCPUDP_CKM | RFE_CTL_IP_CKM);
  775. spin_unlock_irqrestore(&pdata->rfe_ctl_lock, flags);
  776. /* it's racing here! */
  777. ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl);
  778. if (ret < 0) {
  779. netdev_warn(dev->net, "Error writing RFE_CTL\n");
  780. return ret;
  781. }
  782. return 0;
  783. }
  784. static int smsc75xx_wait_ready(struct usbnet *dev, int in_pm)
  785. {
  786. int timeout = 0;
  787. do {
  788. u32 buf;
  789. int ret;
  790. ret = __smsc75xx_read_reg(dev, PMT_CTL, &buf, in_pm);
  791. if (ret < 0) {
  792. netdev_warn(dev->net, "Failed to read PMT_CTL: %d\n", ret);
  793. return ret;
  794. }
  795. if (buf & PMT_CTL_DEV_RDY)
  796. return 0;
  797. msleep(10);
  798. timeout++;
  799. } while (timeout < 100);
  800. netdev_warn(dev->net, "timeout waiting for device ready\n");
  801. return -EIO;
  802. }
  803. static int smsc75xx_phy_gig_workaround(struct usbnet *dev)
  804. {
  805. struct mii_if_info *mii = &dev->mii;
  806. int ret = 0, timeout = 0;
  807. u32 buf, link_up = 0;
  808. /* Set the phy in Gig loopback */
  809. smsc75xx_mdio_write(dev->net, mii->phy_id, MII_BMCR, 0x4040);
  810. /* Wait for the link up */
  811. do {
  812. link_up = smsc75xx_link_ok_nopm(dev);
  813. usleep_range(10000, 20000);
  814. timeout++;
  815. } while ((!link_up) && (timeout < 1000));
  816. if (timeout >= 1000) {
  817. netdev_warn(dev->net, "Timeout waiting for PHY link up\n");
  818. return -EIO;
  819. }
  820. /* phy reset */
  821. ret = smsc75xx_read_reg(dev, PMT_CTL, &buf);
  822. if (ret < 0) {
  823. netdev_warn(dev->net, "Failed to read PMT_CTL: %d\n", ret);
  824. return ret;
  825. }
  826. buf |= PMT_CTL_PHY_RST;
  827. ret = smsc75xx_write_reg(dev, PMT_CTL, buf);
  828. if (ret < 0) {
  829. netdev_warn(dev->net, "Failed to write PMT_CTL: %d\n", ret);
  830. return ret;
  831. }
  832. timeout = 0;
  833. do {
  834. usleep_range(10000, 20000);
  835. ret = smsc75xx_read_reg(dev, PMT_CTL, &buf);
  836. if (ret < 0) {
  837. netdev_warn(dev->net, "Failed to read PMT_CTL: %d\n",
  838. ret);
  839. return ret;
  840. }
  841. timeout++;
  842. } while ((buf & PMT_CTL_PHY_RST) && (timeout < 100));
  843. if (timeout >= 100) {
  844. netdev_warn(dev->net, "timeout waiting for PHY Reset\n");
  845. return -EIO;
  846. }
  847. return 0;
  848. }
  849. static int smsc75xx_reset(struct usbnet *dev)
  850. {
  851. struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
  852. u32 buf;
  853. int ret = 0, timeout;
  854. netif_dbg(dev, ifup, dev->net, "entering smsc75xx_reset\n");
  855. ret = smsc75xx_wait_ready(dev, 0);
  856. if (ret < 0) {
  857. netdev_warn(dev->net, "device not ready in smsc75xx_reset\n");
  858. return ret;
  859. }
  860. ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
  861. if (ret < 0) {
  862. netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
  863. return ret;
  864. }
  865. buf |= HW_CFG_LRST;
  866. ret = smsc75xx_write_reg(dev, HW_CFG, buf);
  867. if (ret < 0) {
  868. netdev_warn(dev->net, "Failed to write HW_CFG: %d\n", ret);
  869. return ret;
  870. }
  871. timeout = 0;
  872. do {
  873. msleep(10);
  874. ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
  875. if (ret < 0) {
  876. netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
  877. return ret;
  878. }
  879. timeout++;
  880. } while ((buf & HW_CFG_LRST) && (timeout < 100));
  881. if (timeout >= 100) {
  882. netdev_warn(dev->net, "timeout on completion of Lite Reset\n");
  883. return -EIO;
  884. }
  885. netif_dbg(dev, ifup, dev->net, "Lite reset complete, resetting PHY\n");
  886. ret = smsc75xx_read_reg(dev, PMT_CTL, &buf);
  887. if (ret < 0) {
  888. netdev_warn(dev->net, "Failed to read PMT_CTL: %d\n", ret);
  889. return ret;
  890. }
  891. buf |= PMT_CTL_PHY_RST;
  892. ret = smsc75xx_write_reg(dev, PMT_CTL, buf);
  893. if (ret < 0) {
  894. netdev_warn(dev->net, "Failed to write PMT_CTL: %d\n", ret);
  895. return ret;
  896. }
  897. timeout = 0;
  898. do {
  899. msleep(10);
  900. ret = smsc75xx_read_reg(dev, PMT_CTL, &buf);
  901. if (ret < 0) {
  902. netdev_warn(dev->net, "Failed to read PMT_CTL: %d\n", ret);
  903. return ret;
  904. }
  905. timeout++;
  906. } while ((buf & PMT_CTL_PHY_RST) && (timeout < 100));
  907. if (timeout >= 100) {
  908. netdev_warn(dev->net, "timeout waiting for PHY Reset\n");
  909. return -EIO;
  910. }
  911. netif_dbg(dev, ifup, dev->net, "PHY reset complete\n");
  912. ret = smsc75xx_set_mac_address(dev);
  913. if (ret < 0) {
  914. netdev_warn(dev->net, "Failed to set mac address\n");
  915. return ret;
  916. }
  917. netif_dbg(dev, ifup, dev->net, "MAC Address: %pM\n",
  918. dev->net->dev_addr);
  919. ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
  920. if (ret < 0) {
  921. netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
  922. return ret;
  923. }
  924. netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG : 0x%08x\n",
  925. buf);
  926. buf |= HW_CFG_BIR;
  927. ret = smsc75xx_write_reg(dev, HW_CFG, buf);
  928. if (ret < 0) {
  929. netdev_warn(dev->net, "Failed to write HW_CFG: %d\n", ret);
  930. return ret;
  931. }
  932. ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
  933. if (ret < 0) {
  934. netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
  935. return ret;
  936. }
  937. netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG after writing HW_CFG_BIR: 0x%08x\n",
  938. buf);
  939. if (!turbo_mode) {
  940. buf = 0;
  941. dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
  942. } else if (dev->udev->speed == USB_SPEED_HIGH) {
  943. buf = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE;
  944. dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE;
  945. } else {
  946. buf = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE;
  947. dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE;
  948. }
  949. netif_dbg(dev, ifup, dev->net, "rx_urb_size=%ld\n",
  950. (ulong)dev->rx_urb_size);
  951. ret = smsc75xx_write_reg(dev, BURST_CAP, buf);
  952. if (ret < 0) {
  953. netdev_warn(dev->net, "Failed to write BURST_CAP: %d\n", ret);
  954. return ret;
  955. }
  956. ret = smsc75xx_read_reg(dev, BURST_CAP, &buf);
  957. if (ret < 0) {
  958. netdev_warn(dev->net, "Failed to read BURST_CAP: %d\n", ret);
  959. return ret;
  960. }
  961. netif_dbg(dev, ifup, dev->net,
  962. "Read Value from BURST_CAP after writing: 0x%08x\n", buf);
  963. ret = smsc75xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY);
  964. if (ret < 0) {
  965. netdev_warn(dev->net, "Failed to write BULK_IN_DLY: %d\n", ret);
  966. return ret;
  967. }
  968. ret = smsc75xx_read_reg(dev, BULK_IN_DLY, &buf);
  969. if (ret < 0) {
  970. netdev_warn(dev->net, "Failed to read BULK_IN_DLY: %d\n", ret);
  971. return ret;
  972. }
  973. netif_dbg(dev, ifup, dev->net,
  974. "Read Value from BULK_IN_DLY after writing: 0x%08x\n", buf);
  975. if (turbo_mode) {
  976. ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
  977. if (ret < 0) {
  978. netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
  979. return ret;
  980. }
  981. netif_dbg(dev, ifup, dev->net, "HW_CFG: 0x%08x\n", buf);
  982. buf |= (HW_CFG_MEF | HW_CFG_BCE);
  983. ret = smsc75xx_write_reg(dev, HW_CFG, buf);
  984. if (ret < 0) {
  985. netdev_warn(dev->net, "Failed to write HW_CFG: %d\n", ret);
  986. return ret;
  987. }
  988. ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
  989. if (ret < 0) {
  990. netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
  991. return ret;
  992. }
  993. netif_dbg(dev, ifup, dev->net, "HW_CFG: 0x%08x\n", buf);
  994. }
  995. /* set FIFO sizes */
  996. buf = (MAX_RX_FIFO_SIZE - 512) / 512;
  997. ret = smsc75xx_write_reg(dev, FCT_RX_FIFO_END, buf);
  998. if (ret < 0) {
  999. netdev_warn(dev->net, "Failed to write FCT_RX_FIFO_END: %d\n", ret);
  1000. return ret;
  1001. }
  1002. netif_dbg(dev, ifup, dev->net, "FCT_RX_FIFO_END set to 0x%08x\n", buf);
  1003. buf = (MAX_TX_FIFO_SIZE - 512) / 512;
  1004. ret = smsc75xx_write_reg(dev, FCT_TX_FIFO_END, buf);
  1005. if (ret < 0) {
  1006. netdev_warn(dev->net, "Failed to write FCT_TX_FIFO_END: %d\n", ret);
  1007. return ret;
  1008. }
  1009. netif_dbg(dev, ifup, dev->net, "FCT_TX_FIFO_END set to 0x%08x\n", buf);
  1010. ret = smsc75xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL);
  1011. if (ret < 0) {
  1012. netdev_warn(dev->net, "Failed to write INT_STS: %d\n", ret);
  1013. return ret;
  1014. }
  1015. ret = smsc75xx_read_reg(dev, ID_REV, &buf);
  1016. if (ret < 0) {
  1017. netdev_warn(dev->net, "Failed to read ID_REV: %d\n", ret);
  1018. return ret;
  1019. }
  1020. netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", buf);
  1021. ret = smsc75xx_read_reg(dev, E2P_CMD, &buf);
  1022. if (ret < 0) {
  1023. netdev_warn(dev->net, "Failed to read E2P_CMD: %d\n", ret);
  1024. return ret;
  1025. }
  1026. /* only set default GPIO/LED settings if no EEPROM is detected */
  1027. if (!(buf & E2P_CMD_LOADED)) {
  1028. ret = smsc75xx_read_reg(dev, LED_GPIO_CFG, &buf);
  1029. if (ret < 0) {
  1030. netdev_warn(dev->net, "Failed to read LED_GPIO_CFG: %d\n", ret);
  1031. return ret;
  1032. }
  1033. buf &= ~(LED_GPIO_CFG_LED2_FUN_SEL | LED_GPIO_CFG_LED10_FUN_SEL);
  1034. buf |= LED_GPIO_CFG_LEDGPIO_EN | LED_GPIO_CFG_LED2_FUN_SEL;
  1035. ret = smsc75xx_write_reg(dev, LED_GPIO_CFG, buf);
  1036. if (ret < 0) {
  1037. netdev_warn(dev->net, "Failed to write LED_GPIO_CFG: %d\n", ret);
  1038. return ret;
  1039. }
  1040. }
  1041. ret = smsc75xx_write_reg(dev, FLOW, 0);
  1042. if (ret < 0) {
  1043. netdev_warn(dev->net, "Failed to write FLOW: %d\n", ret);
  1044. return ret;
  1045. }
  1046. ret = smsc75xx_write_reg(dev, FCT_FLOW, 0);
  1047. if (ret < 0) {
  1048. netdev_warn(dev->net, "Failed to write FCT_FLOW: %d\n", ret);
  1049. return ret;
  1050. }
  1051. /* Don't need rfe_ctl_lock during initialisation */
  1052. ret = smsc75xx_read_reg(dev, RFE_CTL, &pdata->rfe_ctl);
  1053. if (ret < 0) {
  1054. netdev_warn(dev->net, "Failed to read RFE_CTL: %d\n", ret);
  1055. return ret;
  1056. }
  1057. pdata->rfe_ctl |= RFE_CTL_AB | RFE_CTL_DPF;
  1058. ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl);
  1059. if (ret < 0) {
  1060. netdev_warn(dev->net, "Failed to write RFE_CTL: %d\n", ret);
  1061. return ret;
  1062. }
  1063. ret = smsc75xx_read_reg(dev, RFE_CTL, &pdata->rfe_ctl);
  1064. if (ret < 0) {
  1065. netdev_warn(dev->net, "Failed to read RFE_CTL: %d\n", ret);
  1066. return ret;
  1067. }
  1068. netif_dbg(dev, ifup, dev->net, "RFE_CTL set to 0x%08x\n",
  1069. pdata->rfe_ctl);
  1070. /* Enable or disable checksum offload engines */
  1071. smsc75xx_set_features(dev->net, dev->net->features);
  1072. smsc75xx_set_multicast(dev->net);
  1073. ret = smsc75xx_phy_initialize(dev);
  1074. if (ret < 0) {
  1075. netdev_warn(dev->net, "Failed to initialize PHY: %d\n", ret);
  1076. return ret;
  1077. }
  1078. ret = smsc75xx_read_reg(dev, INT_EP_CTL, &buf);
  1079. if (ret < 0) {
  1080. netdev_warn(dev->net, "Failed to read INT_EP_CTL: %d\n", ret);
  1081. return ret;
  1082. }
  1083. /* enable PHY interrupts */
  1084. buf |= INT_ENP_PHY_INT;
  1085. ret = smsc75xx_write_reg(dev, INT_EP_CTL, buf);
  1086. if (ret < 0) {
  1087. netdev_warn(dev->net, "Failed to write INT_EP_CTL: %d\n", ret);
  1088. return ret;
  1089. }
  1090. /* allow mac to detect speed and duplex from phy */
  1091. ret = smsc75xx_read_reg(dev, MAC_CR, &buf);
  1092. if (ret < 0) {
  1093. netdev_warn(dev->net, "Failed to read MAC_CR: %d\n", ret);
  1094. return ret;
  1095. }
  1096. buf |= (MAC_CR_ADD | MAC_CR_ASD);
  1097. ret = smsc75xx_write_reg(dev, MAC_CR, buf);
  1098. if (ret < 0) {
  1099. netdev_warn(dev->net, "Failed to write MAC_CR: %d\n", ret);
  1100. return ret;
  1101. }
  1102. ret = smsc75xx_read_reg(dev, MAC_TX, &buf);
  1103. if (ret < 0) {
  1104. netdev_warn(dev->net, "Failed to read MAC_TX: %d\n", ret);
  1105. return ret;
  1106. }
  1107. buf |= MAC_TX_TXEN;
  1108. ret = smsc75xx_write_reg(dev, MAC_TX, buf);
  1109. if (ret < 0) {
  1110. netdev_warn(dev->net, "Failed to write MAC_TX: %d\n", ret);
  1111. return ret;
  1112. }
  1113. netif_dbg(dev, ifup, dev->net, "MAC_TX set to 0x%08x\n", buf);
  1114. ret = smsc75xx_read_reg(dev, FCT_TX_CTL, &buf);
  1115. if (ret < 0) {
  1116. netdev_warn(dev->net, "Failed to read FCT_TX_CTL: %d\n", ret);
  1117. return ret;
  1118. }
  1119. buf |= FCT_TX_CTL_EN;
  1120. ret = smsc75xx_write_reg(dev, FCT_TX_CTL, buf);
  1121. if (ret < 0) {
  1122. netdev_warn(dev->net, "Failed to write FCT_TX_CTL: %d\n", ret);
  1123. return ret;
  1124. }
  1125. netif_dbg(dev, ifup, dev->net, "FCT_TX_CTL set to 0x%08x\n", buf);
  1126. ret = smsc75xx_set_rx_max_frame_length(dev, dev->net->mtu + ETH_HLEN);
  1127. if (ret < 0) {
  1128. netdev_warn(dev->net, "Failed to set max rx frame length\n");
  1129. return ret;
  1130. }
  1131. ret = smsc75xx_read_reg(dev, MAC_RX, &buf);
  1132. if (ret < 0) {
  1133. netdev_warn(dev->net, "Failed to read MAC_RX: %d\n", ret);
  1134. return ret;
  1135. }
  1136. buf |= MAC_RX_RXEN;
  1137. ret = smsc75xx_write_reg(dev, MAC_RX, buf);
  1138. if (ret < 0) {
  1139. netdev_warn(dev->net, "Failed to write MAC_RX: %d\n", ret);
  1140. return ret;
  1141. }
  1142. netif_dbg(dev, ifup, dev->net, "MAC_RX set to 0x%08x\n", buf);
  1143. ret = smsc75xx_read_reg(dev, FCT_RX_CTL, &buf);
  1144. if (ret < 0) {
  1145. netdev_warn(dev->net, "Failed to read FCT_RX_CTL: %d\n", ret);
  1146. return ret;
  1147. }
  1148. buf |= FCT_RX_CTL_EN;
  1149. ret = smsc75xx_write_reg(dev, FCT_RX_CTL, buf);
  1150. if (ret < 0) {
  1151. netdev_warn(dev->net, "Failed to write FCT_RX_CTL: %d\n", ret);
  1152. return ret;
  1153. }
  1154. netif_dbg(dev, ifup, dev->net, "FCT_RX_CTL set to 0x%08x\n", buf);
  1155. netif_dbg(dev, ifup, dev->net, "smsc75xx_reset, return 0\n");
  1156. return 0;
  1157. }
  1158. static const struct net_device_ops smsc75xx_netdev_ops = {
  1159. .ndo_open = usbnet_open,
  1160. .ndo_stop = usbnet_stop,
  1161. .ndo_start_xmit = usbnet_start_xmit,
  1162. .ndo_tx_timeout = usbnet_tx_timeout,
  1163. .ndo_change_mtu = smsc75xx_change_mtu,
  1164. .ndo_set_mac_address = eth_mac_addr,
  1165. .ndo_validate_addr = eth_validate_addr,
  1166. .ndo_do_ioctl = smsc75xx_ioctl,
  1167. .ndo_set_rx_mode = smsc75xx_set_multicast,
  1168. .ndo_set_features = smsc75xx_set_features,
  1169. };
  1170. static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf)
  1171. {
  1172. struct smsc75xx_priv *pdata = NULL;
  1173. int ret;
  1174. printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n");
  1175. ret = usbnet_get_endpoints(dev, intf);
  1176. if (ret < 0) {
  1177. netdev_warn(dev->net, "usbnet_get_endpoints failed: %d\n", ret);
  1178. return ret;
  1179. }
  1180. dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc75xx_priv),
  1181. GFP_KERNEL);
  1182. pdata = (struct smsc75xx_priv *)(dev->data[0]);
  1183. if (!pdata)
  1184. return -ENOMEM;
  1185. pdata->dev = dev;
  1186. spin_lock_init(&pdata->rfe_ctl_lock);
  1187. mutex_init(&pdata->dataport_mutex);
  1188. INIT_WORK(&pdata->set_multicast, smsc75xx_deferred_multicast_write);
  1189. if (DEFAULT_TX_CSUM_ENABLE)
  1190. dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
  1191. if (DEFAULT_RX_CSUM_ENABLE)
  1192. dev->net->features |= NETIF_F_RXCSUM;
  1193. dev->net->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  1194. NETIF_F_RXCSUM;
  1195. ret = smsc75xx_wait_ready(dev, 0);
  1196. if (ret < 0) {
  1197. netdev_warn(dev->net, "device not ready in smsc75xx_bind\n");
  1198. return ret;
  1199. }
  1200. smsc75xx_init_mac_address(dev);
  1201. /* Init all registers */
  1202. ret = smsc75xx_reset(dev);
  1203. if (ret < 0) {
  1204. netdev_warn(dev->net, "smsc75xx_reset error %d\n", ret);
  1205. return ret;
  1206. }
  1207. dev->net->netdev_ops = &smsc75xx_netdev_ops;
  1208. dev->net->ethtool_ops = &smsc75xx_ethtool_ops;
  1209. dev->net->flags |= IFF_MULTICAST;
  1210. dev->net->hard_header_len += SMSC75XX_TX_OVERHEAD;
  1211. dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
  1212. return 0;
  1213. }
  1214. static void smsc75xx_unbind(struct usbnet *dev, struct usb_interface *intf)
  1215. {
  1216. struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
  1217. if (pdata) {
  1218. cancel_work_sync(&pdata->set_multicast);
  1219. netif_dbg(dev, ifdown, dev->net, "free pdata\n");
  1220. kfree(pdata);
  1221. pdata = NULL;
  1222. dev->data[0] = 0;
  1223. }
  1224. }
  1225. static u16 smsc_crc(const u8 *buffer, size_t len)
  1226. {
  1227. return bitrev16(crc16(0xFFFF, buffer, len));
  1228. }
  1229. static int smsc75xx_write_wuff(struct usbnet *dev, int filter, u32 wuf_cfg,
  1230. u32 wuf_mask1)
  1231. {
  1232. int cfg_base = WUF_CFGX + filter * 4;
  1233. int mask_base = WUF_MASKX + filter * 16;
  1234. int ret;
  1235. ret = smsc75xx_write_reg(dev, cfg_base, wuf_cfg);
  1236. if (ret < 0) {
  1237. netdev_warn(dev->net, "Error writing WUF_CFGX\n");
  1238. return ret;
  1239. }
  1240. ret = smsc75xx_write_reg(dev, mask_base, wuf_mask1);
  1241. if (ret < 0) {
  1242. netdev_warn(dev->net, "Error writing WUF_MASKX\n");
  1243. return ret;
  1244. }
  1245. ret = smsc75xx_write_reg(dev, mask_base + 4, 0);
  1246. if (ret < 0) {
  1247. netdev_warn(dev->net, "Error writing WUF_MASKX\n");
  1248. return ret;
  1249. }
  1250. ret = smsc75xx_write_reg(dev, mask_base + 8, 0);
  1251. if (ret < 0) {
  1252. netdev_warn(dev->net, "Error writing WUF_MASKX\n");
  1253. return ret;
  1254. }
  1255. ret = smsc75xx_write_reg(dev, mask_base + 12, 0);
  1256. if (ret < 0) {
  1257. netdev_warn(dev->net, "Error writing WUF_MASKX\n");
  1258. return ret;
  1259. }
  1260. return 0;
  1261. }
  1262. static int smsc75xx_enter_suspend0(struct usbnet *dev)
  1263. {
  1264. struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
  1265. u32 val;
  1266. int ret;
  1267. ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
  1268. if (ret < 0) {
  1269. netdev_warn(dev->net, "Error reading PMT_CTL\n");
  1270. return ret;
  1271. }
  1272. val &= (~(PMT_CTL_SUS_MODE | PMT_CTL_PHY_RST));
  1273. val |= PMT_CTL_SUS_MODE_0 | PMT_CTL_WOL_EN | PMT_CTL_WUPS;
  1274. ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
  1275. if (ret < 0) {
  1276. netdev_warn(dev->net, "Error writing PMT_CTL\n");
  1277. return ret;
  1278. }
  1279. pdata->suspend_flags |= SUSPEND_SUSPEND0;
  1280. return 0;
  1281. }
  1282. static int smsc75xx_enter_suspend1(struct usbnet *dev)
  1283. {
  1284. struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
  1285. u32 val;
  1286. int ret;
  1287. ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
  1288. if (ret < 0) {
  1289. netdev_warn(dev->net, "Error reading PMT_CTL\n");
  1290. return ret;
  1291. }
  1292. val &= ~(PMT_CTL_SUS_MODE | PMT_CTL_WUPS | PMT_CTL_PHY_RST);
  1293. val |= PMT_CTL_SUS_MODE_1;
  1294. ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
  1295. if (ret < 0) {
  1296. netdev_warn(dev->net, "Error writing PMT_CTL\n");
  1297. return ret;
  1298. }
  1299. /* clear wol status, enable energy detection */
  1300. val &= ~PMT_CTL_WUPS;
  1301. val |= (PMT_CTL_WUPS_ED | PMT_CTL_ED_EN);
  1302. ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
  1303. if (ret < 0) {
  1304. netdev_warn(dev->net, "Error writing PMT_CTL\n");
  1305. return ret;
  1306. }
  1307. pdata->suspend_flags |= SUSPEND_SUSPEND1;
  1308. return 0;
  1309. }
  1310. static int smsc75xx_enter_suspend2(struct usbnet *dev)
  1311. {
  1312. struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
  1313. u32 val;
  1314. int ret;
  1315. ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
  1316. if (ret < 0) {
  1317. netdev_warn(dev->net, "Error reading PMT_CTL\n");
  1318. return ret;
  1319. }
  1320. val &= ~(PMT_CTL_SUS_MODE | PMT_CTL_WUPS | PMT_CTL_PHY_RST);
  1321. val |= PMT_CTL_SUS_MODE_2;
  1322. ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
  1323. if (ret < 0) {
  1324. netdev_warn(dev->net, "Error writing PMT_CTL\n");
  1325. return ret;
  1326. }
  1327. pdata->suspend_flags |= SUSPEND_SUSPEND2;
  1328. return 0;
  1329. }
  1330. static int smsc75xx_enter_suspend3(struct usbnet *dev)
  1331. {
  1332. struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
  1333. u32 val;
  1334. int ret;
  1335. ret = smsc75xx_read_reg_nopm(dev, FCT_RX_CTL, &val);
  1336. if (ret < 0) {
  1337. netdev_warn(dev->net, "Error reading FCT_RX_CTL\n");
  1338. return ret;
  1339. }
  1340. if (val & FCT_RX_CTL_RXUSED) {
  1341. netdev_dbg(dev->net, "rx fifo not empty in autosuspend\n");
  1342. return -EBUSY;
  1343. }
  1344. ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
  1345. if (ret < 0) {
  1346. netdev_warn(dev->net, "Error reading PMT_CTL\n");
  1347. return ret;
  1348. }
  1349. val &= ~(PMT_CTL_SUS_MODE | PMT_CTL_WUPS | PMT_CTL_PHY_RST);
  1350. val |= PMT_CTL_SUS_MODE_3 | PMT_CTL_RES_CLR_WKP_EN;
  1351. ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
  1352. if (ret < 0) {
  1353. netdev_warn(dev->net, "Error writing PMT_CTL\n");
  1354. return ret;
  1355. }
  1356. /* clear wol status */
  1357. val &= ~PMT_CTL_WUPS;
  1358. val |= PMT_CTL_WUPS_WOL;
  1359. ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
  1360. if (ret < 0) {
  1361. netdev_warn(dev->net, "Error writing PMT_CTL\n");
  1362. return ret;
  1363. }
  1364. pdata->suspend_flags |= SUSPEND_SUSPEND3;
  1365. return 0;
  1366. }
  1367. static int smsc75xx_enable_phy_wakeup_interrupts(struct usbnet *dev, u16 mask)
  1368. {
  1369. struct mii_if_info *mii = &dev->mii;
  1370. int ret;
  1371. netdev_dbg(dev->net, "enabling PHY wakeup interrupts\n");
  1372. /* read to clear */
  1373. ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_SRC);
  1374. if (ret < 0) {
  1375. netdev_warn(dev->net, "Error reading PHY_INT_SRC\n");
  1376. return ret;
  1377. }
  1378. /* enable interrupt source */
  1379. ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_MASK);
  1380. if (ret < 0) {
  1381. netdev_warn(dev->net, "Error reading PHY_INT_MASK\n");
  1382. return ret;
  1383. }
  1384. ret |= mask;
  1385. smsc75xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_INT_MASK, ret);
  1386. return 0;
  1387. }
  1388. static int smsc75xx_link_ok_nopm(struct usbnet *dev)
  1389. {
  1390. struct mii_if_info *mii = &dev->mii;
  1391. int ret;
  1392. /* first, a dummy read, needed to latch some MII phys */
  1393. ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR);
  1394. if (ret < 0) {
  1395. netdev_warn(dev->net, "Error reading MII_BMSR\n");
  1396. return ret;
  1397. }
  1398. ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR);
  1399. if (ret < 0) {
  1400. netdev_warn(dev->net, "Error reading MII_BMSR\n");
  1401. return ret;
  1402. }
  1403. return !!(ret & BMSR_LSTATUS);
  1404. }
  1405. static int smsc75xx_autosuspend(struct usbnet *dev, u32 link_up)
  1406. {
  1407. int ret;
  1408. if (!netif_running(dev->net)) {
  1409. /* interface is ifconfig down so fully power down hw */
  1410. netdev_dbg(dev->net, "autosuspend entering SUSPEND2\n");
  1411. return smsc75xx_enter_suspend2(dev);
  1412. }
  1413. if (!link_up) {
  1414. /* link is down so enter EDPD mode */
  1415. netdev_dbg(dev->net, "autosuspend entering SUSPEND1\n");
  1416. /* enable PHY wakeup events for if cable is attached */
  1417. ret = smsc75xx_enable_phy_wakeup_interrupts(dev,
  1418. PHY_INT_MASK_ANEG_COMP);
  1419. if (ret < 0) {
  1420. netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
  1421. return ret;
  1422. }
  1423. netdev_info(dev->net, "entering SUSPEND1 mode\n");
  1424. return smsc75xx_enter_suspend1(dev);
  1425. }
  1426. /* enable PHY wakeup events so we remote wakeup if cable is pulled */
  1427. ret = smsc75xx_enable_phy_wakeup_interrupts(dev,
  1428. PHY_INT_MASK_LINK_DOWN);
  1429. if (ret < 0) {
  1430. netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
  1431. return ret;
  1432. }
  1433. netdev_dbg(dev->net, "autosuspend entering SUSPEND3\n");
  1434. return smsc75xx_enter_suspend3(dev);
  1435. }
  1436. static int smsc75xx_suspend(struct usb_interface *intf, pm_message_t message)
  1437. {
  1438. struct usbnet *dev = usb_get_intfdata(intf);
  1439. struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
  1440. u32 val, link_up;
  1441. int ret;
  1442. ret = usbnet_suspend(intf, message);
  1443. if (ret < 0) {
  1444. netdev_warn(dev->net, "usbnet_suspend error\n");
  1445. return ret;
  1446. }
  1447. if (pdata->suspend_flags) {
  1448. netdev_warn(dev->net, "error during last resume\n");
  1449. pdata->suspend_flags = 0;
  1450. }
  1451. /* determine if link is up using only _nopm functions */
  1452. link_up = smsc75xx_link_ok_nopm(dev);
  1453. if (message.event == PM_EVENT_AUTO_SUSPEND) {
  1454. ret = smsc75xx_autosuspend(dev, link_up);
  1455. goto done;
  1456. }
  1457. /* if we get this far we're not autosuspending */
  1458. /* if no wol options set, or if link is down and we're not waking on
  1459. * PHY activity, enter lowest power SUSPEND2 mode
  1460. */
  1461. if (!(pdata->wolopts & SUPPORTED_WAKE) ||
  1462. !(link_up || (pdata->wolopts & WAKE_PHY))) {
  1463. netdev_info(dev->net, "entering SUSPEND2 mode\n");
  1464. /* disable energy detect (link up) & wake up events */
  1465. ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
  1466. if (ret < 0) {
  1467. netdev_warn(dev->net, "Error reading WUCSR\n");
  1468. goto done;
  1469. }
  1470. val &= ~(WUCSR_MPEN | WUCSR_WUEN);
  1471. ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
  1472. if (ret < 0) {
  1473. netdev_warn(dev->net, "Error writing WUCSR\n");
  1474. goto done;
  1475. }
  1476. ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
  1477. if (ret < 0) {
  1478. netdev_warn(dev->net, "Error reading PMT_CTL\n");
  1479. goto done;
  1480. }
  1481. val &= ~(PMT_CTL_ED_EN | PMT_CTL_WOL_EN);
  1482. ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
  1483. if (ret < 0) {
  1484. netdev_warn(dev->net, "Error writing PMT_CTL\n");
  1485. goto done;
  1486. }
  1487. ret = smsc75xx_enter_suspend2(dev);
  1488. goto done;
  1489. }
  1490. if (pdata->wolopts & WAKE_PHY) {
  1491. ret = smsc75xx_enable_phy_wakeup_interrupts(dev,
  1492. (PHY_INT_MASK_ANEG_COMP | PHY_INT_MASK_LINK_DOWN));
  1493. if (ret < 0) {
  1494. netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
  1495. goto done;
  1496. }
  1497. /* if link is down then configure EDPD and enter SUSPEND1,
  1498. * otherwise enter SUSPEND0 below
  1499. */
  1500. if (!link_up) {
  1501. struct mii_if_info *mii = &dev->mii;
  1502. netdev_info(dev->net, "entering SUSPEND1 mode\n");
  1503. /* enable energy detect power-down mode */
  1504. ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id,
  1505. PHY_MODE_CTRL_STS);
  1506. if (ret < 0) {
  1507. netdev_warn(dev->net, "Error reading PHY_MODE_CTRL_STS\n");
  1508. goto done;
  1509. }
  1510. ret |= MODE_CTRL_STS_EDPWRDOWN;
  1511. smsc75xx_mdio_write_nopm(dev->net, mii->phy_id,
  1512. PHY_MODE_CTRL_STS, ret);
  1513. /* enter SUSPEND1 mode */
  1514. ret = smsc75xx_enter_suspend1(dev);
  1515. goto done;
  1516. }
  1517. }
  1518. if (pdata->wolopts & (WAKE_MCAST | WAKE_ARP)) {
  1519. int i, filter = 0;
  1520. /* disable all filters */
  1521. for (i = 0; i < WUF_NUM; i++) {
  1522. ret = smsc75xx_write_reg_nopm(dev, WUF_CFGX + i * 4, 0);
  1523. if (ret < 0) {
  1524. netdev_warn(dev->net, "Error writing WUF_CFGX\n");
  1525. goto done;
  1526. }
  1527. }
  1528. if (pdata->wolopts & WAKE_MCAST) {
  1529. const u8 mcast[] = {0x01, 0x00, 0x5E};
  1530. netdev_info(dev->net, "enabling multicast detection\n");
  1531. val = WUF_CFGX_EN | WUF_CFGX_ATYPE_MULTICAST
  1532. | smsc_crc(mcast, 3);
  1533. ret = smsc75xx_write_wuff(dev, filter++, val, 0x0007);
  1534. if (ret < 0) {
  1535. netdev_warn(dev->net, "Error writing wakeup filter\n");
  1536. goto done;
  1537. }
  1538. }
  1539. if (pdata->wolopts & WAKE_ARP) {
  1540. const u8 arp[] = {0x08, 0x06};
  1541. netdev_info(dev->net, "enabling ARP detection\n");
  1542. val = WUF_CFGX_EN | WUF_CFGX_ATYPE_ALL | (0x0C << 16)
  1543. | smsc_crc(arp, 2);
  1544. ret = smsc75xx_write_wuff(dev, filter++, val, 0x0003);
  1545. if (ret < 0) {
  1546. netdev_warn(dev->net, "Error writing wakeup filter\n");
  1547. goto done;
  1548. }
  1549. }
  1550. /* clear any pending pattern match packet status */
  1551. ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
  1552. if (ret < 0) {
  1553. netdev_warn(dev->net, "Error reading WUCSR\n");
  1554. goto done;
  1555. }
  1556. val |= WUCSR_WUFR;
  1557. ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
  1558. if (ret < 0) {
  1559. netdev_warn(dev->net, "Error writing WUCSR\n");
  1560. goto done;
  1561. }
  1562. netdev_info(dev->net, "enabling packet match detection\n");
  1563. ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
  1564. if (ret < 0) {
  1565. netdev_warn(dev->net, "Error reading WUCSR\n");
  1566. goto done;
  1567. }
  1568. val |= WUCSR_WUEN;
  1569. ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
  1570. if (ret < 0) {
  1571. netdev_warn(dev->net, "Error writing WUCSR\n");
  1572. goto done;
  1573. }
  1574. } else {
  1575. netdev_info(dev->net, "disabling packet match detection\n");
  1576. ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
  1577. if (ret < 0) {
  1578. netdev_warn(dev->net, "Error reading WUCSR\n");
  1579. goto done;
  1580. }
  1581. val &= ~WUCSR_WUEN;
  1582. ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
  1583. if (ret < 0) {
  1584. netdev_warn(dev->net, "Error writing WUCSR\n");
  1585. goto done;
  1586. }
  1587. }
  1588. /* disable magic, bcast & unicast wakeup sources */
  1589. ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
  1590. if (ret < 0) {
  1591. netdev_warn(dev->net, "Error reading WUCSR\n");
  1592. goto done;
  1593. }
  1594. val &= ~(WUCSR_MPEN | WUCSR_BCST_EN | WUCSR_PFDA_EN);
  1595. ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
  1596. if (ret < 0) {
  1597. netdev_warn(dev->net, "Error writing WUCSR\n");
  1598. goto done;
  1599. }
  1600. if (pdata->wolopts & WAKE_PHY) {
  1601. netdev_info(dev->net, "enabling PHY wakeup\n");
  1602. ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
  1603. if (ret < 0) {
  1604. netdev_warn(dev->net, "Error reading PMT_CTL\n");
  1605. goto done;
  1606. }
  1607. /* clear wol status, enable energy detection */
  1608. val &= ~PMT_CTL_WUPS;
  1609. val |= (PMT_CTL_WUPS_ED | PMT_CTL_ED_EN);
  1610. ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
  1611. if (ret < 0) {
  1612. netdev_warn(dev->net, "Error writing PMT_CTL\n");
  1613. goto done;
  1614. }
  1615. }
  1616. if (pdata->wolopts & WAKE_MAGIC) {
  1617. netdev_info(dev->net, "enabling magic packet wakeup\n");
  1618. ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
  1619. if (ret < 0) {
  1620. netdev_warn(dev->net, "Error reading WUCSR\n");
  1621. goto done;
  1622. }
  1623. /* clear any pending magic packet status */
  1624. val |= WUCSR_MPR | WUCSR_MPEN;
  1625. ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
  1626. if (ret < 0) {
  1627. netdev_warn(dev->net, "Error writing WUCSR\n");
  1628. goto done;
  1629. }
  1630. }
  1631. if (pdata->wolopts & WAKE_BCAST) {
  1632. netdev_info(dev->net, "enabling broadcast detection\n");
  1633. ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
  1634. if (ret < 0) {
  1635. netdev_warn(dev->net, "Error reading WUCSR\n");
  1636. goto done;
  1637. }
  1638. val |= WUCSR_BCAST_FR | WUCSR_BCST_EN;
  1639. ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
  1640. if (ret < 0) {
  1641. netdev_warn(dev->net, "Error writing WUCSR\n");
  1642. goto done;
  1643. }
  1644. }
  1645. if (pdata->wolopts & WAKE_UCAST) {
  1646. netdev_info(dev->net, "enabling unicast detection\n");
  1647. ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
  1648. if (ret < 0) {
  1649. netdev_warn(dev->net, "Error reading WUCSR\n");
  1650. goto done;
  1651. }
  1652. val |= WUCSR_WUFR | WUCSR_PFDA_EN;
  1653. ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
  1654. if (ret < 0) {
  1655. netdev_warn(dev->net, "Error writing WUCSR\n");
  1656. goto done;
  1657. }
  1658. }
  1659. /* enable receiver to enable frame reception */
  1660. ret = smsc75xx_read_reg_nopm(dev, MAC_RX, &val);
  1661. if (ret < 0) {
  1662. netdev_warn(dev->net, "Failed to read MAC_RX: %d\n", ret);
  1663. goto done;
  1664. }
  1665. val |= MAC_RX_RXEN;
  1666. ret = smsc75xx_write_reg_nopm(dev, MAC_RX, val);
  1667. if (ret < 0) {
  1668. netdev_warn(dev->net, "Failed to write MAC_RX: %d\n", ret);
  1669. goto done;
  1670. }
  1671. /* some wol options are enabled, so enter SUSPEND0 */
  1672. netdev_info(dev->net, "entering SUSPEND0 mode\n");
  1673. ret = smsc75xx_enter_suspend0(dev);
  1674. done:
  1675. /*
  1676. * TODO: resume() might need to handle the suspend failure
  1677. * in system sleep
  1678. */
  1679. if (ret && PMSG_IS_AUTO(message))
  1680. usbnet_resume(intf);
  1681. return ret;
  1682. }
  1683. static int smsc75xx_resume(struct usb_interface *intf)
  1684. {
  1685. struct usbnet *dev = usb_get_intfdata(intf);
  1686. struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
  1687. u8 suspend_flags = pdata->suspend_flags;
  1688. int ret;
  1689. u32 val;
  1690. netdev_dbg(dev->net, "resume suspend_flags=0x%02x\n", suspend_flags);
  1691. /* do this first to ensure it's cleared even in error case */
  1692. pdata->suspend_flags = 0;
  1693. if (suspend_flags & SUSPEND_ALLMODES) {
  1694. /* Disable wakeup sources */
  1695. ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
  1696. if (ret < 0) {
  1697. netdev_warn(dev->net, "Error reading WUCSR\n");
  1698. return ret;
  1699. }
  1700. val &= ~(WUCSR_WUEN | WUCSR_MPEN | WUCSR_PFDA_EN
  1701. | WUCSR_BCST_EN);
  1702. ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
  1703. if (ret < 0) {
  1704. netdev_warn(dev->net, "Error writing WUCSR\n");
  1705. return ret;
  1706. }
  1707. /* clear wake-up status */
  1708. ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
  1709. if (ret < 0) {
  1710. netdev_warn(dev->net, "Error reading PMT_CTL\n");
  1711. return ret;
  1712. }
  1713. val &= ~PMT_CTL_WOL_EN;
  1714. val |= PMT_CTL_WUPS;
  1715. ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
  1716. if (ret < 0) {
  1717. netdev_warn(dev->net, "Error writing PMT_CTL\n");
  1718. return ret;
  1719. }
  1720. }
  1721. if (suspend_flags & SUSPEND_SUSPEND2) {
  1722. netdev_info(dev->net, "resuming from SUSPEND2\n");
  1723. ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
  1724. if (ret < 0) {
  1725. netdev_warn(dev->net, "Error reading PMT_CTL\n");
  1726. return ret;
  1727. }
  1728. val |= PMT_CTL_PHY_PWRUP;
  1729. ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
  1730. if (ret < 0) {
  1731. netdev_warn(dev->net, "Error writing PMT_CTL\n");
  1732. return ret;
  1733. }
  1734. }
  1735. ret = smsc75xx_wait_ready(dev, 1);
  1736. if (ret < 0) {
  1737. netdev_warn(dev->net, "device not ready in smsc75xx_resume\n");
  1738. return ret;
  1739. }
  1740. return usbnet_resume(intf);
  1741. }
  1742. static void smsc75xx_rx_csum_offload(struct usbnet *dev, struct sk_buff *skb,
  1743. u32 rx_cmd_a, u32 rx_cmd_b)
  1744. {
  1745. if (!(dev->net->features & NETIF_F_RXCSUM) ||
  1746. unlikely(rx_cmd_a & RX_CMD_A_LCSM)) {
  1747. skb->ip_summed = CHECKSUM_NONE;
  1748. } else {
  1749. skb->csum = ntohs((u16)(rx_cmd_b >> RX_CMD_B_CSUM_SHIFT));
  1750. skb->ip_summed = CHECKSUM_COMPLETE;
  1751. }
  1752. }
  1753. static int smsc75xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
  1754. {
  1755. /* This check is no longer done by usbnet */
  1756. if (skb->len < dev->net->hard_header_len)
  1757. return 0;
  1758. while (skb->len > 0) {
  1759. u32 rx_cmd_a, rx_cmd_b, align_count, size;
  1760. struct sk_buff *ax_skb;
  1761. unsigned char *packet;
  1762. memcpy(&rx_cmd_a, skb->data, sizeof(rx_cmd_a));
  1763. le32_to_cpus(&rx_cmd_a);
  1764. skb_pull(skb, 4);
  1765. memcpy(&rx_cmd_b, skb->data, sizeof(rx_cmd_b));
  1766. le32_to_cpus(&rx_cmd_b);
  1767. skb_pull(skb, 4 + RXW_PADDING);
  1768. packet = skb->data;
  1769. /* get the packet length */
  1770. size = (rx_cmd_a & RX_CMD_A_LEN) - RXW_PADDING;
  1771. align_count = (4 - ((size + RXW_PADDING) % 4)) % 4;
  1772. if (unlikely(rx_cmd_a & RX_CMD_A_RED)) {
  1773. netif_dbg(dev, rx_err, dev->net,
  1774. "Error rx_cmd_a=0x%08x\n", rx_cmd_a);
  1775. dev->net->stats.rx_errors++;
  1776. dev->net->stats.rx_dropped++;
  1777. if (rx_cmd_a & RX_CMD_A_FCS)
  1778. dev->net->stats.rx_crc_errors++;
  1779. else if (rx_cmd_a & (RX_CMD_A_LONG | RX_CMD_A_RUNT))
  1780. dev->net->stats.rx_frame_errors++;
  1781. } else {
  1782. /* MAX_SINGLE_PACKET_SIZE + 4(CRC) + 2(COE) + 4(Vlan) */
  1783. if (unlikely(size > (MAX_SINGLE_PACKET_SIZE + ETH_HLEN + 12))) {
  1784. netif_dbg(dev, rx_err, dev->net,
  1785. "size err rx_cmd_a=0x%08x\n",
  1786. rx_cmd_a);
  1787. return 0;
  1788. }
  1789. /* last frame in this batch */
  1790. if (skb->len == size) {
  1791. smsc75xx_rx_csum_offload(dev, skb, rx_cmd_a,
  1792. rx_cmd_b);
  1793. skb_trim(skb, skb->len - 4); /* remove fcs */
  1794. skb->truesize = size + sizeof(struct sk_buff);
  1795. return 1;
  1796. }
  1797. ax_skb = skb_clone(skb, GFP_ATOMIC);
  1798. if (unlikely(!ax_skb)) {
  1799. netdev_warn(dev->net, "Error allocating skb\n");
  1800. return 0;
  1801. }
  1802. ax_skb->len = size;
  1803. ax_skb->data = packet;
  1804. skb_set_tail_pointer(ax_skb, size);
  1805. smsc75xx_rx_csum_offload(dev, ax_skb, rx_cmd_a,
  1806. rx_cmd_b);
  1807. skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */
  1808. ax_skb->truesize = size + sizeof(struct sk_buff);
  1809. usbnet_skb_return(dev, ax_skb);
  1810. }
  1811. skb_pull(skb, size);
  1812. /* padding bytes before the next frame starts */
  1813. if (skb->len)
  1814. skb_pull(skb, align_count);
  1815. }
  1816. return 1;
  1817. }
  1818. static struct sk_buff *smsc75xx_tx_fixup(struct usbnet *dev,
  1819. struct sk_buff *skb, gfp_t flags)
  1820. {
  1821. u32 tx_cmd_a, tx_cmd_b;
  1822. if (skb_cow_head(skb, SMSC75XX_TX_OVERHEAD)) {
  1823. dev_kfree_skb_any(skb);
  1824. return NULL;
  1825. }
  1826. tx_cmd_a = (u32)(skb->len & TX_CMD_A_LEN) | TX_CMD_A_FCS;
  1827. if (skb->ip_summed == CHECKSUM_PARTIAL)
  1828. tx_cmd_a |= TX_CMD_A_IPE | TX_CMD_A_TPE;
  1829. if (skb_is_gso(skb)) {
  1830. u16 mss = max(skb_shinfo(skb)->gso_size, TX_MSS_MIN);
  1831. tx_cmd_b = (mss << TX_CMD_B_MSS_SHIFT) & TX_CMD_B_MSS;
  1832. tx_cmd_a |= TX_CMD_A_LSO;
  1833. } else {
  1834. tx_cmd_b = 0;
  1835. }
  1836. skb_push(skb, 4);
  1837. cpu_to_le32s(&tx_cmd_b);
  1838. memcpy(skb->data, &tx_cmd_b, 4);
  1839. skb_push(skb, 4);
  1840. cpu_to_le32s(&tx_cmd_a);
  1841. memcpy(skb->data, &tx_cmd_a, 4);
  1842. return skb;
  1843. }
  1844. static int smsc75xx_manage_power(struct usbnet *dev, int on)
  1845. {
  1846. dev->intf->needs_remote_wakeup = on;
  1847. return 0;
  1848. }
  1849. static const struct driver_info smsc75xx_info = {
  1850. .description = "smsc75xx USB 2.0 Gigabit Ethernet",
  1851. .bind = smsc75xx_bind,
  1852. .unbind = smsc75xx_unbind,
  1853. .link_reset = smsc75xx_link_reset,
  1854. .reset = smsc75xx_reset,
  1855. .rx_fixup = smsc75xx_rx_fixup,
  1856. .tx_fixup = smsc75xx_tx_fixup,
  1857. .status = smsc75xx_status,
  1858. .manage_power = smsc75xx_manage_power,
  1859. .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR,
  1860. };
  1861. static const struct usb_device_id products[] = {
  1862. {
  1863. /* SMSC7500 USB Gigabit Ethernet Device */
  1864. USB_DEVICE(USB_VENDOR_ID_SMSC, USB_PRODUCT_ID_LAN7500),
  1865. .driver_info = (unsigned long) &smsc75xx_info,
  1866. },
  1867. {
  1868. /* SMSC7500 USB Gigabit Ethernet Device */
  1869. USB_DEVICE(USB_VENDOR_ID_SMSC, USB_PRODUCT_ID_LAN7505),
  1870. .driver_info = (unsigned long) &smsc75xx_info,
  1871. },
  1872. { }, /* END */
  1873. };
  1874. MODULE_DEVICE_TABLE(usb, products);
  1875. static struct usb_driver smsc75xx_driver = {
  1876. .name = SMSC_CHIPNAME,
  1877. .id_table = products,
  1878. .probe = usbnet_probe,
  1879. .suspend = smsc75xx_suspend,
  1880. .resume = smsc75xx_resume,
  1881. .reset_resume = smsc75xx_resume,
  1882. .disconnect = usbnet_disconnect,
  1883. .disable_hub_initiated_lpm = 1,
  1884. .supports_autosuspend = 1,
  1885. };
  1886. module_usb_driver(smsc75xx_driver);
  1887. MODULE_AUTHOR("Nancy Lin");
  1888. MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>");
  1889. MODULE_DESCRIPTION("SMSC75XX USB 2.0 Gigabit Ethernet Devices");
  1890. MODULE_LICENSE("GPL");