smsc95xx.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316
  1. /***************************************************************************
  2. *
  3. * Copyright (C) 2007-2008 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, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. *
  19. *****************************************************************************/
  20. #include <linux/module.h>
  21. #include <linux/kmod.h>
  22. #include <linux/init.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/etherdevice.h>
  25. #include <linux/ethtool.h>
  26. #include <linux/mii.h>
  27. #include <linux/usb.h>
  28. #include <linux/crc32.h>
  29. #include <linux/usb/usbnet.h>
  30. #include <linux/slab.h>
  31. #include "smsc95xx.h"
  32. #define SMSC_CHIPNAME "smsc95xx"
  33. #define SMSC_DRIVER_VERSION "1.0.4"
  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 (2048)
  40. #define LAN95XX_EEPROM_MAGIC (0x9500)
  41. #define EEPROM_MAC_OFFSET (0x01)
  42. #define DEFAULT_TX_CSUM_ENABLE (true)
  43. #define DEFAULT_RX_CSUM_ENABLE (true)
  44. #define SMSC95XX_INTERNAL_PHY_ID (1)
  45. #define SMSC95XX_TX_OVERHEAD (8)
  46. #define SMSC95XX_TX_OVERHEAD_CSUM (12)
  47. struct smsc95xx_priv {
  48. u32 mac_cr;
  49. u32 hash_hi;
  50. u32 hash_lo;
  51. spinlock_t mac_cr_lock;
  52. };
  53. struct usb_context {
  54. struct usb_ctrlrequest req;
  55. struct usbnet *dev;
  56. };
  57. static int turbo_mode = true;
  58. module_param(turbo_mode, bool, 0644);
  59. MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
  60. static int smsc95xx_read_reg(struct usbnet *dev, u32 index, u32 *data)
  61. {
  62. u32 *buf = kmalloc(4, GFP_KERNEL);
  63. int ret;
  64. BUG_ON(!dev);
  65. if (!buf)
  66. return -ENOMEM;
  67. ret = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
  68. USB_VENDOR_REQUEST_READ_REGISTER,
  69. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  70. 00, index, buf, 4, USB_CTRL_GET_TIMEOUT);
  71. if (unlikely(ret < 0))
  72. netdev_warn(dev->net, "Failed to read register index 0x%08x\n", index);
  73. le32_to_cpus(buf);
  74. *data = *buf;
  75. kfree(buf);
  76. return ret;
  77. }
  78. static int smsc95xx_write_reg(struct usbnet *dev, u32 index, u32 data)
  79. {
  80. u32 *buf = kmalloc(4, GFP_KERNEL);
  81. int ret;
  82. BUG_ON(!dev);
  83. if (!buf)
  84. return -ENOMEM;
  85. *buf = data;
  86. cpu_to_le32s(buf);
  87. ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
  88. USB_VENDOR_REQUEST_WRITE_REGISTER,
  89. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  90. 00, index, buf, 4, USB_CTRL_SET_TIMEOUT);
  91. if (unlikely(ret < 0))
  92. netdev_warn(dev->net, "Failed to write register index 0x%08x\n", index);
  93. kfree(buf);
  94. return ret;
  95. }
  96. /* Loop until the read is completed with timeout
  97. * called with phy_mutex held */
  98. static int smsc95xx_phy_wait_not_busy(struct usbnet *dev)
  99. {
  100. unsigned long start_time = jiffies;
  101. u32 val;
  102. do {
  103. smsc95xx_read_reg(dev, MII_ADDR, &val);
  104. if (!(val & MII_BUSY_))
  105. return 0;
  106. } while (!time_after(jiffies, start_time + HZ));
  107. return -EIO;
  108. }
  109. static int smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx)
  110. {
  111. struct usbnet *dev = netdev_priv(netdev);
  112. u32 val, addr;
  113. mutex_lock(&dev->phy_mutex);
  114. /* confirm MII not busy */
  115. if (smsc95xx_phy_wait_not_busy(dev)) {
  116. netdev_warn(dev->net, "MII is busy in smsc95xx_mdio_read\n");
  117. mutex_unlock(&dev->phy_mutex);
  118. return -EIO;
  119. }
  120. /* set the address, index & direction (read from PHY) */
  121. phy_id &= dev->mii.phy_id_mask;
  122. idx &= dev->mii.reg_num_mask;
  123. addr = (phy_id << 11) | (idx << 6) | MII_READ_;
  124. smsc95xx_write_reg(dev, MII_ADDR, addr);
  125. if (smsc95xx_phy_wait_not_busy(dev)) {
  126. netdev_warn(dev->net, "Timed out reading MII reg %02X\n", idx);
  127. mutex_unlock(&dev->phy_mutex);
  128. return -EIO;
  129. }
  130. smsc95xx_read_reg(dev, MII_DATA, &val);
  131. mutex_unlock(&dev->phy_mutex);
  132. return (u16)(val & 0xFFFF);
  133. }
  134. static void smsc95xx_mdio_write(struct net_device *netdev, int phy_id, int idx,
  135. int regval)
  136. {
  137. struct usbnet *dev = netdev_priv(netdev);
  138. u32 val, addr;
  139. mutex_lock(&dev->phy_mutex);
  140. /* confirm MII not busy */
  141. if (smsc95xx_phy_wait_not_busy(dev)) {
  142. netdev_warn(dev->net, "MII is busy in smsc95xx_mdio_write\n");
  143. mutex_unlock(&dev->phy_mutex);
  144. return;
  145. }
  146. val = regval;
  147. smsc95xx_write_reg(dev, MII_DATA, val);
  148. /* set the address, index & direction (write to PHY) */
  149. phy_id &= dev->mii.phy_id_mask;
  150. idx &= dev->mii.reg_num_mask;
  151. addr = (phy_id << 11) | (idx << 6) | MII_WRITE_;
  152. smsc95xx_write_reg(dev, MII_ADDR, addr);
  153. if (smsc95xx_phy_wait_not_busy(dev))
  154. netdev_warn(dev->net, "Timed out writing MII reg %02X\n", idx);
  155. mutex_unlock(&dev->phy_mutex);
  156. }
  157. static int smsc95xx_wait_eeprom(struct usbnet *dev)
  158. {
  159. unsigned long start_time = jiffies;
  160. u32 val;
  161. do {
  162. smsc95xx_read_reg(dev, E2P_CMD, &val);
  163. if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_))
  164. break;
  165. udelay(40);
  166. } while (!time_after(jiffies, start_time + HZ));
  167. if (val & (E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_)) {
  168. netdev_warn(dev->net, "EEPROM read operation timeout\n");
  169. return -EIO;
  170. }
  171. return 0;
  172. }
  173. static int smsc95xx_eeprom_confirm_not_busy(struct usbnet *dev)
  174. {
  175. unsigned long start_time = jiffies;
  176. u32 val;
  177. do {
  178. smsc95xx_read_reg(dev, E2P_CMD, &val);
  179. if (!(val & E2P_CMD_BUSY_))
  180. return 0;
  181. udelay(40);
  182. } while (!time_after(jiffies, start_time + HZ));
  183. netdev_warn(dev->net, "EEPROM is busy\n");
  184. return -EIO;
  185. }
  186. static int smsc95xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length,
  187. u8 *data)
  188. {
  189. u32 val;
  190. int i, ret;
  191. BUG_ON(!dev);
  192. BUG_ON(!data);
  193. ret = smsc95xx_eeprom_confirm_not_busy(dev);
  194. if (ret)
  195. return ret;
  196. for (i = 0; i < length; i++) {
  197. val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_);
  198. smsc95xx_write_reg(dev, E2P_CMD, val);
  199. ret = smsc95xx_wait_eeprom(dev);
  200. if (ret < 0)
  201. return ret;
  202. smsc95xx_read_reg(dev, E2P_DATA, &val);
  203. data[i] = val & 0xFF;
  204. offset++;
  205. }
  206. return 0;
  207. }
  208. static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length,
  209. u8 *data)
  210. {
  211. u32 val;
  212. int i, ret;
  213. BUG_ON(!dev);
  214. BUG_ON(!data);
  215. ret = smsc95xx_eeprom_confirm_not_busy(dev);
  216. if (ret)
  217. return ret;
  218. /* Issue write/erase enable command */
  219. val = E2P_CMD_BUSY_ | E2P_CMD_EWEN_;
  220. smsc95xx_write_reg(dev, E2P_CMD, val);
  221. ret = smsc95xx_wait_eeprom(dev);
  222. if (ret < 0)
  223. return ret;
  224. for (i = 0; i < length; i++) {
  225. /* Fill data register */
  226. val = data[i];
  227. smsc95xx_write_reg(dev, E2P_DATA, val);
  228. /* Send "write" command */
  229. val = E2P_CMD_BUSY_ | E2P_CMD_WRITE_ | (offset & E2P_CMD_ADDR_);
  230. smsc95xx_write_reg(dev, E2P_CMD, val);
  231. ret = smsc95xx_wait_eeprom(dev);
  232. if (ret < 0)
  233. return ret;
  234. offset++;
  235. }
  236. return 0;
  237. }
  238. static void smsc95xx_async_cmd_callback(struct urb *urb)
  239. {
  240. struct usb_context *usb_context = urb->context;
  241. struct usbnet *dev = usb_context->dev;
  242. int status = urb->status;
  243. if (status < 0)
  244. netdev_warn(dev->net, "async callback failed with %d\n", status);
  245. kfree(usb_context);
  246. usb_free_urb(urb);
  247. }
  248. static int smsc95xx_write_reg_async(struct usbnet *dev, u16 index, u32 *data)
  249. {
  250. struct usb_context *usb_context;
  251. int status;
  252. struct urb *urb;
  253. const u16 size = 4;
  254. urb = usb_alloc_urb(0, GFP_ATOMIC);
  255. if (!urb) {
  256. netdev_warn(dev->net, "Error allocating URB\n");
  257. return -ENOMEM;
  258. }
  259. usb_context = kmalloc(sizeof(struct usb_context), GFP_ATOMIC);
  260. if (usb_context == NULL) {
  261. netdev_warn(dev->net, "Error allocating control msg\n");
  262. usb_free_urb(urb);
  263. return -ENOMEM;
  264. }
  265. usb_context->req.bRequestType =
  266. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
  267. usb_context->req.bRequest = USB_VENDOR_REQUEST_WRITE_REGISTER;
  268. usb_context->req.wValue = 00;
  269. usb_context->req.wIndex = cpu_to_le16(index);
  270. usb_context->req.wLength = cpu_to_le16(size);
  271. usb_fill_control_urb(urb, dev->udev, usb_sndctrlpipe(dev->udev, 0),
  272. (void *)&usb_context->req, data, size,
  273. smsc95xx_async_cmd_callback,
  274. (void *)usb_context);
  275. status = usb_submit_urb(urb, GFP_ATOMIC);
  276. if (status < 0) {
  277. netdev_warn(dev->net, "Error submitting control msg, sts=%d\n",
  278. status);
  279. kfree(usb_context);
  280. usb_free_urb(urb);
  281. }
  282. return status;
  283. }
  284. /* returns hash bit number for given MAC address
  285. * example:
  286. * 01 00 5E 00 00 01 -> returns bit number 31 */
  287. static unsigned int smsc95xx_hash(char addr[ETH_ALEN])
  288. {
  289. return (ether_crc(ETH_ALEN, addr) >> 26) & 0x3f;
  290. }
  291. static void smsc95xx_set_multicast(struct net_device *netdev)
  292. {
  293. struct usbnet *dev = netdev_priv(netdev);
  294. struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
  295. unsigned long flags;
  296. pdata->hash_hi = 0;
  297. pdata->hash_lo = 0;
  298. spin_lock_irqsave(&pdata->mac_cr_lock, flags);
  299. if (dev->net->flags & IFF_PROMISC) {
  300. netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n");
  301. pdata->mac_cr |= MAC_CR_PRMS_;
  302. pdata->mac_cr &= ~(MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
  303. } else if (dev->net->flags & IFF_ALLMULTI) {
  304. netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n");
  305. pdata->mac_cr |= MAC_CR_MCPAS_;
  306. pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_HPFILT_);
  307. } else if (!netdev_mc_empty(dev->net)) {
  308. struct netdev_hw_addr *ha;
  309. pdata->mac_cr |= MAC_CR_HPFILT_;
  310. pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_);
  311. netdev_for_each_mc_addr(ha, netdev) {
  312. u32 bitnum = smsc95xx_hash(ha->addr);
  313. u32 mask = 0x01 << (bitnum & 0x1F);
  314. if (bitnum & 0x20)
  315. pdata->hash_hi |= mask;
  316. else
  317. pdata->hash_lo |= mask;
  318. }
  319. netif_dbg(dev, drv, dev->net, "HASHH=0x%08X, HASHL=0x%08X\n",
  320. pdata->hash_hi, pdata->hash_lo);
  321. } else {
  322. netif_dbg(dev, drv, dev->net, "receive own packets only\n");
  323. pdata->mac_cr &=
  324. ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
  325. }
  326. spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
  327. /* Initiate async writes, as we can't wait for completion here */
  328. smsc95xx_write_reg_async(dev, HASHH, &pdata->hash_hi);
  329. smsc95xx_write_reg_async(dev, HASHL, &pdata->hash_lo);
  330. smsc95xx_write_reg_async(dev, MAC_CR, &pdata->mac_cr);
  331. }
  332. static void smsc95xx_phy_update_flowcontrol(struct usbnet *dev, u8 duplex,
  333. u16 lcladv, u16 rmtadv)
  334. {
  335. u32 flow, afc_cfg = 0;
  336. int ret = smsc95xx_read_reg(dev, AFC_CFG, &afc_cfg);
  337. if (ret < 0) {
  338. netdev_warn(dev->net, "error reading AFC_CFG\n");
  339. return;
  340. }
  341. if (duplex == DUPLEX_FULL) {
  342. u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv);
  343. if (cap & FLOW_CTRL_RX)
  344. flow = 0xFFFF0002;
  345. else
  346. flow = 0;
  347. if (cap & FLOW_CTRL_TX)
  348. afc_cfg |= 0xF;
  349. else
  350. afc_cfg &= ~0xF;
  351. netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n",
  352. cap & FLOW_CTRL_RX ? "enabled" : "disabled",
  353. cap & FLOW_CTRL_TX ? "enabled" : "disabled");
  354. } else {
  355. netif_dbg(dev, link, dev->net, "half duplex\n");
  356. flow = 0;
  357. afc_cfg |= 0xF;
  358. }
  359. smsc95xx_write_reg(dev, FLOW, flow);
  360. smsc95xx_write_reg(dev, AFC_CFG, afc_cfg);
  361. }
  362. static int smsc95xx_link_reset(struct usbnet *dev)
  363. {
  364. struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
  365. struct mii_if_info *mii = &dev->mii;
  366. struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
  367. unsigned long flags;
  368. u16 lcladv, rmtadv;
  369. u32 intdata;
  370. /* clear interrupt status */
  371. smsc95xx_mdio_read(dev->net, mii->phy_id, PHY_INT_SRC);
  372. intdata = 0xFFFFFFFF;
  373. smsc95xx_write_reg(dev, INT_STS, intdata);
  374. mii_check_media(mii, 1, 1);
  375. mii_ethtool_gset(&dev->mii, &ecmd);
  376. lcladv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_ADVERTISE);
  377. rmtadv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_LPA);
  378. netif_dbg(dev, link, dev->net,
  379. "speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n",
  380. ethtool_cmd_speed(&ecmd), ecmd.duplex, lcladv, rmtadv);
  381. spin_lock_irqsave(&pdata->mac_cr_lock, flags);
  382. if (ecmd.duplex != DUPLEX_FULL) {
  383. pdata->mac_cr &= ~MAC_CR_FDPX_;
  384. pdata->mac_cr |= MAC_CR_RCVOWN_;
  385. } else {
  386. pdata->mac_cr &= ~MAC_CR_RCVOWN_;
  387. pdata->mac_cr |= MAC_CR_FDPX_;
  388. }
  389. spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
  390. smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
  391. smsc95xx_phy_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv);
  392. return 0;
  393. }
  394. static void smsc95xx_status(struct usbnet *dev, struct urb *urb)
  395. {
  396. u32 intdata;
  397. if (urb->actual_length != 4) {
  398. netdev_warn(dev->net, "unexpected urb length %d\n",
  399. urb->actual_length);
  400. return;
  401. }
  402. memcpy(&intdata, urb->transfer_buffer, 4);
  403. le32_to_cpus(&intdata);
  404. netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata);
  405. if (intdata & INT_ENP_PHY_INT_)
  406. usbnet_defer_kevent(dev, EVENT_LINK_RESET);
  407. else
  408. netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n",
  409. intdata);
  410. }
  411. /* Enable or disable Tx & Rx checksum offload engines */
  412. static int smsc95xx_set_features(struct net_device *netdev, u32 features)
  413. {
  414. struct usbnet *dev = netdev_priv(netdev);
  415. u32 read_buf;
  416. int ret;
  417. ret = smsc95xx_read_reg(dev, COE_CR, &read_buf);
  418. if (ret < 0) {
  419. netdev_warn(dev->net, "Failed to read COE_CR: %d\n", ret);
  420. return ret;
  421. }
  422. if (features & NETIF_F_HW_CSUM)
  423. read_buf |= Tx_COE_EN_;
  424. else
  425. read_buf &= ~Tx_COE_EN_;
  426. if (features & NETIF_F_RXCSUM)
  427. read_buf |= Rx_COE_EN_;
  428. else
  429. read_buf &= ~Rx_COE_EN_;
  430. ret = smsc95xx_write_reg(dev, COE_CR, read_buf);
  431. if (ret < 0) {
  432. netdev_warn(dev->net, "Failed to write COE_CR: %d\n", ret);
  433. return ret;
  434. }
  435. netif_dbg(dev, hw, dev->net, "COE_CR = 0x%08x\n", read_buf);
  436. return 0;
  437. }
  438. static int smsc95xx_ethtool_get_eeprom_len(struct net_device *net)
  439. {
  440. return MAX_EEPROM_SIZE;
  441. }
  442. static int smsc95xx_ethtool_get_eeprom(struct net_device *netdev,
  443. struct ethtool_eeprom *ee, u8 *data)
  444. {
  445. struct usbnet *dev = netdev_priv(netdev);
  446. ee->magic = LAN95XX_EEPROM_MAGIC;
  447. return smsc95xx_read_eeprom(dev, ee->offset, ee->len, data);
  448. }
  449. static int smsc95xx_ethtool_set_eeprom(struct net_device *netdev,
  450. struct ethtool_eeprom *ee, u8 *data)
  451. {
  452. struct usbnet *dev = netdev_priv(netdev);
  453. if (ee->magic != LAN95XX_EEPROM_MAGIC) {
  454. netdev_warn(dev->net, "EEPROM: magic value mismatch, magic = 0x%x\n",
  455. ee->magic);
  456. return -EINVAL;
  457. }
  458. return smsc95xx_write_eeprom(dev, ee->offset, ee->len, data);
  459. }
  460. static const struct ethtool_ops smsc95xx_ethtool_ops = {
  461. .get_link = usbnet_get_link,
  462. .nway_reset = usbnet_nway_reset,
  463. .get_drvinfo = usbnet_get_drvinfo,
  464. .get_msglevel = usbnet_get_msglevel,
  465. .set_msglevel = usbnet_set_msglevel,
  466. .get_settings = usbnet_get_settings,
  467. .set_settings = usbnet_set_settings,
  468. .get_eeprom_len = smsc95xx_ethtool_get_eeprom_len,
  469. .get_eeprom = smsc95xx_ethtool_get_eeprom,
  470. .set_eeprom = smsc95xx_ethtool_set_eeprom,
  471. };
  472. static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
  473. {
  474. struct usbnet *dev = netdev_priv(netdev);
  475. if (!netif_running(netdev))
  476. return -EINVAL;
  477. return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
  478. }
  479. static void smsc95xx_init_mac_address(struct usbnet *dev)
  480. {
  481. /* try reading mac address from EEPROM */
  482. if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
  483. dev->net->dev_addr) == 0) {
  484. if (is_valid_ether_addr(dev->net->dev_addr)) {
  485. /* eeprom values are valid so use them */
  486. netif_dbg(dev, ifup, dev->net, "MAC address read from EEPROM\n");
  487. return;
  488. }
  489. }
  490. /* no eeprom, or eeprom values are invalid. generate random MAC */
  491. random_ether_addr(dev->net->dev_addr);
  492. netif_dbg(dev, ifup, dev->net, "MAC address set to random_ether_addr\n");
  493. }
  494. static int smsc95xx_set_mac_address(struct usbnet *dev)
  495. {
  496. u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 |
  497. dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24;
  498. u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8;
  499. int ret;
  500. ret = smsc95xx_write_reg(dev, ADDRL, addr_lo);
  501. if (ret < 0) {
  502. netdev_warn(dev->net, "Failed to write ADDRL: %d\n", ret);
  503. return ret;
  504. }
  505. ret = smsc95xx_write_reg(dev, ADDRH, addr_hi);
  506. if (ret < 0) {
  507. netdev_warn(dev->net, "Failed to write ADDRH: %d\n", ret);
  508. return ret;
  509. }
  510. return 0;
  511. }
  512. /* starts the TX path */
  513. static void smsc95xx_start_tx_path(struct usbnet *dev)
  514. {
  515. struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
  516. unsigned long flags;
  517. u32 reg_val;
  518. /* Enable Tx at MAC */
  519. spin_lock_irqsave(&pdata->mac_cr_lock, flags);
  520. pdata->mac_cr |= MAC_CR_TXEN_;
  521. spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
  522. smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
  523. /* Enable Tx at SCSRs */
  524. reg_val = TX_CFG_ON_;
  525. smsc95xx_write_reg(dev, TX_CFG, reg_val);
  526. }
  527. /* Starts the Receive path */
  528. static void smsc95xx_start_rx_path(struct usbnet *dev)
  529. {
  530. struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
  531. unsigned long flags;
  532. spin_lock_irqsave(&pdata->mac_cr_lock, flags);
  533. pdata->mac_cr |= MAC_CR_RXEN_;
  534. spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
  535. smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
  536. }
  537. static int smsc95xx_phy_initialize(struct usbnet *dev)
  538. {
  539. int bmcr, timeout = 0;
  540. /* Initialize MII structure */
  541. dev->mii.dev = dev->net;
  542. dev->mii.mdio_read = smsc95xx_mdio_read;
  543. dev->mii.mdio_write = smsc95xx_mdio_write;
  544. dev->mii.phy_id_mask = 0x1f;
  545. dev->mii.reg_num_mask = 0x1f;
  546. dev->mii.phy_id = SMSC95XX_INTERNAL_PHY_ID;
  547. /* reset phy and wait for reset to complete */
  548. smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
  549. do {
  550. msleep(10);
  551. bmcr = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR);
  552. timeout++;
  553. } while ((bmcr & BMCR_RESET) && (timeout < 100));
  554. if (timeout >= 100) {
  555. netdev_warn(dev->net, "timeout on PHY Reset");
  556. return -EIO;
  557. }
  558. smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
  559. ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP |
  560. ADVERTISE_PAUSE_ASYM);
  561. /* read to clear */
  562. smsc95xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC);
  563. smsc95xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK,
  564. PHY_INT_MASK_DEFAULT_);
  565. mii_nway_restart(&dev->mii);
  566. netif_dbg(dev, ifup, dev->net, "phy initialised successfully\n");
  567. return 0;
  568. }
  569. static int smsc95xx_reset(struct usbnet *dev)
  570. {
  571. struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
  572. u32 read_buf, write_buf, burst_cap;
  573. int ret = 0, timeout;
  574. netif_dbg(dev, ifup, dev->net, "entering smsc95xx_reset\n");
  575. write_buf = HW_CFG_LRST_;
  576. ret = smsc95xx_write_reg(dev, HW_CFG, write_buf);
  577. if (ret < 0) {
  578. netdev_warn(dev->net, "Failed to write HW_CFG_LRST_ bit in HW_CFG register, ret = %d\n",
  579. ret);
  580. return ret;
  581. }
  582. timeout = 0;
  583. do {
  584. ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
  585. if (ret < 0) {
  586. netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
  587. return ret;
  588. }
  589. msleep(10);
  590. timeout++;
  591. } while ((read_buf & HW_CFG_LRST_) && (timeout < 100));
  592. if (timeout >= 100) {
  593. netdev_warn(dev->net, "timeout waiting for completion of Lite Reset\n");
  594. return ret;
  595. }
  596. write_buf = PM_CTL_PHY_RST_;
  597. ret = smsc95xx_write_reg(dev, PM_CTRL, write_buf);
  598. if (ret < 0) {
  599. netdev_warn(dev->net, "Failed to write PM_CTRL: %d\n", ret);
  600. return ret;
  601. }
  602. timeout = 0;
  603. do {
  604. ret = smsc95xx_read_reg(dev, PM_CTRL, &read_buf);
  605. if (ret < 0) {
  606. netdev_warn(dev->net, "Failed to read PM_CTRL: %d\n", ret);
  607. return ret;
  608. }
  609. msleep(10);
  610. timeout++;
  611. } while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100));
  612. if (timeout >= 100) {
  613. netdev_warn(dev->net, "timeout waiting for PHY Reset\n");
  614. return ret;
  615. }
  616. ret = smsc95xx_set_mac_address(dev);
  617. if (ret < 0)
  618. return ret;
  619. netif_dbg(dev, ifup, dev->net,
  620. "MAC Address: %pM\n", dev->net->dev_addr);
  621. ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
  622. if (ret < 0) {
  623. netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
  624. return ret;
  625. }
  626. netif_dbg(dev, ifup, dev->net,
  627. "Read Value from HW_CFG : 0x%08x\n", read_buf);
  628. read_buf |= HW_CFG_BIR_;
  629. ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
  630. if (ret < 0) {
  631. netdev_warn(dev->net, "Failed to write HW_CFG_BIR_ bit in HW_CFG register, ret = %d\n",
  632. ret);
  633. return ret;
  634. }
  635. ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
  636. if (ret < 0) {
  637. netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
  638. return ret;
  639. }
  640. netif_dbg(dev, ifup, dev->net,
  641. "Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x\n",
  642. read_buf);
  643. if (!turbo_mode) {
  644. burst_cap = 0;
  645. dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
  646. } else if (dev->udev->speed == USB_SPEED_HIGH) {
  647. burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE;
  648. dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE;
  649. } else {
  650. burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE;
  651. dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE;
  652. }
  653. netif_dbg(dev, ifup, dev->net,
  654. "rx_urb_size=%ld\n", (ulong)dev->rx_urb_size);
  655. ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap);
  656. if (ret < 0) {
  657. netdev_warn(dev->net, "Failed to write BURST_CAP: %d\n", ret);
  658. return ret;
  659. }
  660. ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf);
  661. if (ret < 0) {
  662. netdev_warn(dev->net, "Failed to read BURST_CAP: %d\n", ret);
  663. return ret;
  664. }
  665. netif_dbg(dev, ifup, dev->net,
  666. "Read Value from BURST_CAP after writing: 0x%08x\n",
  667. read_buf);
  668. read_buf = DEFAULT_BULK_IN_DELAY;
  669. ret = smsc95xx_write_reg(dev, BULK_IN_DLY, read_buf);
  670. if (ret < 0) {
  671. netdev_warn(dev->net, "ret = %d\n", ret);
  672. return ret;
  673. }
  674. ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf);
  675. if (ret < 0) {
  676. netdev_warn(dev->net, "Failed to read BULK_IN_DLY: %d\n", ret);
  677. return ret;
  678. }
  679. netif_dbg(dev, ifup, dev->net,
  680. "Read Value from BULK_IN_DLY after writing: 0x%08x\n",
  681. read_buf);
  682. ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
  683. if (ret < 0) {
  684. netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
  685. return ret;
  686. }
  687. netif_dbg(dev, ifup, dev->net,
  688. "Read Value from HW_CFG: 0x%08x\n", read_buf);
  689. if (turbo_mode)
  690. read_buf |= (HW_CFG_MEF_ | HW_CFG_BCE_);
  691. read_buf &= ~HW_CFG_RXDOFF_;
  692. /* set Rx data offset=2, Make IP header aligns on word boundary. */
  693. read_buf |= NET_IP_ALIGN << 9;
  694. ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
  695. if (ret < 0) {
  696. netdev_warn(dev->net, "Failed to write HW_CFG register, ret=%d\n",
  697. ret);
  698. return ret;
  699. }
  700. ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
  701. if (ret < 0) {
  702. netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
  703. return ret;
  704. }
  705. netif_dbg(dev, ifup, dev->net,
  706. "Read Value from HW_CFG after writing: 0x%08x\n", read_buf);
  707. write_buf = 0xFFFFFFFF;
  708. ret = smsc95xx_write_reg(dev, INT_STS, write_buf);
  709. if (ret < 0) {
  710. netdev_warn(dev->net, "Failed to write INT_STS register, ret=%d\n",
  711. ret);
  712. return ret;
  713. }
  714. ret = smsc95xx_read_reg(dev, ID_REV, &read_buf);
  715. if (ret < 0) {
  716. netdev_warn(dev->net, "Failed to read ID_REV: %d\n", ret);
  717. return ret;
  718. }
  719. netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", read_buf);
  720. /* Configure GPIO pins as LED outputs */
  721. write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED |
  722. LED_GPIO_CFG_FDX_LED;
  723. ret = smsc95xx_write_reg(dev, LED_GPIO_CFG, write_buf);
  724. if (ret < 0) {
  725. netdev_warn(dev->net, "Failed to write LED_GPIO_CFG register, ret=%d\n",
  726. ret);
  727. return ret;
  728. }
  729. /* Init Tx */
  730. write_buf = 0;
  731. ret = smsc95xx_write_reg(dev, FLOW, write_buf);
  732. if (ret < 0) {
  733. netdev_warn(dev->net, "Failed to write FLOW: %d\n", ret);
  734. return ret;
  735. }
  736. read_buf = AFC_CFG_DEFAULT;
  737. ret = smsc95xx_write_reg(dev, AFC_CFG, read_buf);
  738. if (ret < 0) {
  739. netdev_warn(dev->net, "Failed to write AFC_CFG: %d\n", ret);
  740. return ret;
  741. }
  742. /* Don't need mac_cr_lock during initialisation */
  743. ret = smsc95xx_read_reg(dev, MAC_CR, &pdata->mac_cr);
  744. if (ret < 0) {
  745. netdev_warn(dev->net, "Failed to read MAC_CR: %d\n", ret);
  746. return ret;
  747. }
  748. /* Init Rx */
  749. /* Set Vlan */
  750. write_buf = (u32)ETH_P_8021Q;
  751. ret = smsc95xx_write_reg(dev, VLAN1, write_buf);
  752. if (ret < 0) {
  753. netdev_warn(dev->net, "Failed to write VAN1: %d\n", ret);
  754. return ret;
  755. }
  756. /* Enable or disable checksum offload engines */
  757. smsc95xx_set_features(dev->net, dev->net->features);
  758. smsc95xx_set_multicast(dev->net);
  759. if (smsc95xx_phy_initialize(dev) < 0)
  760. return -EIO;
  761. ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf);
  762. if (ret < 0) {
  763. netdev_warn(dev->net, "Failed to read INT_EP_CTL: %d\n", ret);
  764. return ret;
  765. }
  766. /* enable PHY interrupts */
  767. read_buf |= INT_EP_CTL_PHY_INT_;
  768. ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf);
  769. if (ret < 0) {
  770. netdev_warn(dev->net, "Failed to write INT_EP_CTL: %d\n", ret);
  771. return ret;
  772. }
  773. smsc95xx_start_tx_path(dev);
  774. smsc95xx_start_rx_path(dev);
  775. netif_dbg(dev, ifup, dev->net, "smsc95xx_reset, return 0\n");
  776. return 0;
  777. }
  778. static const struct net_device_ops smsc95xx_netdev_ops = {
  779. .ndo_open = usbnet_open,
  780. .ndo_stop = usbnet_stop,
  781. .ndo_start_xmit = usbnet_start_xmit,
  782. .ndo_tx_timeout = usbnet_tx_timeout,
  783. .ndo_change_mtu = usbnet_change_mtu,
  784. .ndo_set_mac_address = eth_mac_addr,
  785. .ndo_validate_addr = eth_validate_addr,
  786. .ndo_do_ioctl = smsc95xx_ioctl,
  787. .ndo_set_multicast_list = smsc95xx_set_multicast,
  788. .ndo_set_features = smsc95xx_set_features,
  789. };
  790. static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)
  791. {
  792. struct smsc95xx_priv *pdata = NULL;
  793. int ret;
  794. printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n");
  795. ret = usbnet_get_endpoints(dev, intf);
  796. if (ret < 0) {
  797. netdev_warn(dev->net, "usbnet_get_endpoints failed: %d\n", ret);
  798. return ret;
  799. }
  800. dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc95xx_priv),
  801. GFP_KERNEL);
  802. pdata = (struct smsc95xx_priv *)(dev->data[0]);
  803. if (!pdata) {
  804. netdev_warn(dev->net, "Unable to allocate struct smsc95xx_priv\n");
  805. return -ENOMEM;
  806. }
  807. spin_lock_init(&pdata->mac_cr_lock);
  808. if (DEFAULT_TX_CSUM_ENABLE)
  809. dev->net->features |= NETIF_F_HW_CSUM;
  810. if (DEFAULT_RX_CSUM_ENABLE)
  811. dev->net->features |= NETIF_F_RXCSUM;
  812. dev->net->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM;
  813. smsc95xx_init_mac_address(dev);
  814. /* Init all registers */
  815. ret = smsc95xx_reset(dev);
  816. dev->net->netdev_ops = &smsc95xx_netdev_ops;
  817. dev->net->ethtool_ops = &smsc95xx_ethtool_ops;
  818. dev->net->flags |= IFF_MULTICAST;
  819. dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM;
  820. return 0;
  821. }
  822. static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf)
  823. {
  824. struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
  825. if (pdata) {
  826. netif_dbg(dev, ifdown, dev->net, "free pdata\n");
  827. kfree(pdata);
  828. pdata = NULL;
  829. dev->data[0] = 0;
  830. }
  831. }
  832. static void smsc95xx_rx_csum_offload(struct sk_buff *skb)
  833. {
  834. skb->csum = *(u16 *)(skb_tail_pointer(skb) - 2);
  835. skb->ip_summed = CHECKSUM_COMPLETE;
  836. skb_trim(skb, skb->len - 2);
  837. }
  838. static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
  839. {
  840. while (skb->len > 0) {
  841. u32 header, align_count;
  842. struct sk_buff *ax_skb;
  843. unsigned char *packet;
  844. u16 size;
  845. memcpy(&header, skb->data, sizeof(header));
  846. le32_to_cpus(&header);
  847. skb_pull(skb, 4 + NET_IP_ALIGN);
  848. packet = skb->data;
  849. /* get the packet length */
  850. size = (u16)((header & RX_STS_FL_) >> 16);
  851. align_count = (4 - ((size + NET_IP_ALIGN) % 4)) % 4;
  852. if (unlikely(header & RX_STS_ES_)) {
  853. netif_dbg(dev, rx_err, dev->net,
  854. "Error header=0x%08x\n", header);
  855. dev->net->stats.rx_errors++;
  856. dev->net->stats.rx_dropped++;
  857. if (header & RX_STS_CRC_) {
  858. dev->net->stats.rx_crc_errors++;
  859. } else {
  860. if (header & (RX_STS_TL_ | RX_STS_RF_))
  861. dev->net->stats.rx_frame_errors++;
  862. if ((header & RX_STS_LE_) &&
  863. (!(header & RX_STS_FT_)))
  864. dev->net->stats.rx_length_errors++;
  865. }
  866. } else {
  867. /* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */
  868. if (unlikely(size > (ETH_FRAME_LEN + 12))) {
  869. netif_dbg(dev, rx_err, dev->net,
  870. "size err header=0x%08x\n", header);
  871. return 0;
  872. }
  873. /* last frame in this batch */
  874. if (skb->len == size) {
  875. if (dev->net->features & NETIF_F_RXCSUM)
  876. smsc95xx_rx_csum_offload(skb);
  877. skb_trim(skb, skb->len - 4); /* remove fcs */
  878. skb->truesize = size + sizeof(struct sk_buff);
  879. return 1;
  880. }
  881. ax_skb = skb_clone(skb, GFP_ATOMIC);
  882. if (unlikely(!ax_skb)) {
  883. netdev_warn(dev->net, "Error allocating skb\n");
  884. return 0;
  885. }
  886. ax_skb->len = size;
  887. ax_skb->data = packet;
  888. skb_set_tail_pointer(ax_skb, size);
  889. if (dev->net->features & NETIF_F_RXCSUM)
  890. smsc95xx_rx_csum_offload(ax_skb);
  891. skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */
  892. ax_skb->truesize = size + sizeof(struct sk_buff);
  893. usbnet_skb_return(dev, ax_skb);
  894. }
  895. skb_pull(skb, size);
  896. /* padding bytes before the next frame starts */
  897. if (skb->len)
  898. skb_pull(skb, align_count);
  899. }
  900. if (unlikely(skb->len < 0)) {
  901. netdev_warn(dev->net, "invalid rx length<0 %d\n", skb->len);
  902. return 0;
  903. }
  904. return 1;
  905. }
  906. static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb)
  907. {
  908. u16 low_16 = (u16)skb_checksum_start_offset(skb);
  909. u16 high_16 = low_16 + skb->csum_offset;
  910. return (high_16 << 16) | low_16;
  911. }
  912. static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev,
  913. struct sk_buff *skb, gfp_t flags)
  914. {
  915. bool csum = skb->ip_summed == CHECKSUM_PARTIAL;
  916. int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD;
  917. u32 tx_cmd_a, tx_cmd_b;
  918. /* We do not advertise SG, so skbs should be already linearized */
  919. BUG_ON(skb_shinfo(skb)->nr_frags);
  920. if (skb_headroom(skb) < overhead) {
  921. struct sk_buff *skb2 = skb_copy_expand(skb,
  922. overhead, 0, flags);
  923. dev_kfree_skb_any(skb);
  924. skb = skb2;
  925. if (!skb)
  926. return NULL;
  927. }
  928. if (csum) {
  929. if (skb->len <= 45) {
  930. /* workaround - hardware tx checksum does not work
  931. * properly with extremely small packets */
  932. long csstart = skb_checksum_start_offset(skb);
  933. __wsum calc = csum_partial(skb->data + csstart,
  934. skb->len - csstart, 0);
  935. *((__sum16 *)(skb->data + csstart
  936. + skb->csum_offset)) = csum_fold(calc);
  937. csum = false;
  938. } else {
  939. u32 csum_preamble = smsc95xx_calc_csum_preamble(skb);
  940. skb_push(skb, 4);
  941. memcpy(skb->data, &csum_preamble, 4);
  942. }
  943. }
  944. skb_push(skb, 4);
  945. tx_cmd_b = (u32)(skb->len - 4);
  946. if (csum)
  947. tx_cmd_b |= TX_CMD_B_CSUM_ENABLE;
  948. cpu_to_le32s(&tx_cmd_b);
  949. memcpy(skb->data, &tx_cmd_b, 4);
  950. skb_push(skb, 4);
  951. tx_cmd_a = (u32)(skb->len - 8) | TX_CMD_A_FIRST_SEG_ |
  952. TX_CMD_A_LAST_SEG_;
  953. cpu_to_le32s(&tx_cmd_a);
  954. memcpy(skb->data, &tx_cmd_a, 4);
  955. return skb;
  956. }
  957. static const struct driver_info smsc95xx_info = {
  958. .description = "smsc95xx USB 2.0 Ethernet",
  959. .bind = smsc95xx_bind,
  960. .unbind = smsc95xx_unbind,
  961. .link_reset = smsc95xx_link_reset,
  962. .reset = smsc95xx_reset,
  963. .rx_fixup = smsc95xx_rx_fixup,
  964. .tx_fixup = smsc95xx_tx_fixup,
  965. .status = smsc95xx_status,
  966. .flags = FLAG_ETHER | FLAG_SEND_ZLP,
  967. };
  968. static const struct usb_device_id products[] = {
  969. {
  970. /* SMSC9500 USB Ethernet Device */
  971. USB_DEVICE(0x0424, 0x9500),
  972. .driver_info = (unsigned long) &smsc95xx_info,
  973. },
  974. {
  975. /* SMSC9505 USB Ethernet Device */
  976. USB_DEVICE(0x0424, 0x9505),
  977. .driver_info = (unsigned long) &smsc95xx_info,
  978. },
  979. {
  980. /* SMSC9500A USB Ethernet Device */
  981. USB_DEVICE(0x0424, 0x9E00),
  982. .driver_info = (unsigned long) &smsc95xx_info,
  983. },
  984. {
  985. /* SMSC9505A USB Ethernet Device */
  986. USB_DEVICE(0x0424, 0x9E01),
  987. .driver_info = (unsigned long) &smsc95xx_info,
  988. },
  989. {
  990. /* SMSC9512/9514 USB Hub & Ethernet Device */
  991. USB_DEVICE(0x0424, 0xec00),
  992. .driver_info = (unsigned long) &smsc95xx_info,
  993. },
  994. {
  995. /* SMSC9500 USB Ethernet Device (SAL10) */
  996. USB_DEVICE(0x0424, 0x9900),
  997. .driver_info = (unsigned long) &smsc95xx_info,
  998. },
  999. {
  1000. /* SMSC9505 USB Ethernet Device (SAL10) */
  1001. USB_DEVICE(0x0424, 0x9901),
  1002. .driver_info = (unsigned long) &smsc95xx_info,
  1003. },
  1004. {
  1005. /* SMSC9500A USB Ethernet Device (SAL10) */
  1006. USB_DEVICE(0x0424, 0x9902),
  1007. .driver_info = (unsigned long) &smsc95xx_info,
  1008. },
  1009. {
  1010. /* SMSC9505A USB Ethernet Device (SAL10) */
  1011. USB_DEVICE(0x0424, 0x9903),
  1012. .driver_info = (unsigned long) &smsc95xx_info,
  1013. },
  1014. {
  1015. /* SMSC9512/9514 USB Hub & Ethernet Device (SAL10) */
  1016. USB_DEVICE(0x0424, 0x9904),
  1017. .driver_info = (unsigned long) &smsc95xx_info,
  1018. },
  1019. {
  1020. /* SMSC9500A USB Ethernet Device (HAL) */
  1021. USB_DEVICE(0x0424, 0x9905),
  1022. .driver_info = (unsigned long) &smsc95xx_info,
  1023. },
  1024. {
  1025. /* SMSC9505A USB Ethernet Device (HAL) */
  1026. USB_DEVICE(0x0424, 0x9906),
  1027. .driver_info = (unsigned long) &smsc95xx_info,
  1028. },
  1029. {
  1030. /* SMSC9500 USB Ethernet Device (Alternate ID) */
  1031. USB_DEVICE(0x0424, 0x9907),
  1032. .driver_info = (unsigned long) &smsc95xx_info,
  1033. },
  1034. {
  1035. /* SMSC9500A USB Ethernet Device (Alternate ID) */
  1036. USB_DEVICE(0x0424, 0x9908),
  1037. .driver_info = (unsigned long) &smsc95xx_info,
  1038. },
  1039. {
  1040. /* SMSC9512/9514 USB Hub & Ethernet Device (Alternate ID) */
  1041. USB_DEVICE(0x0424, 0x9909),
  1042. .driver_info = (unsigned long) &smsc95xx_info,
  1043. },
  1044. {
  1045. /* SMSC LAN9530 USB Ethernet Device */
  1046. USB_DEVICE(0x0424, 0x9530),
  1047. .driver_info = (unsigned long) &smsc95xx_info,
  1048. },
  1049. {
  1050. /* SMSC LAN9730 USB Ethernet Device */
  1051. USB_DEVICE(0x0424, 0x9730),
  1052. .driver_info = (unsigned long) &smsc95xx_info,
  1053. },
  1054. {
  1055. /* SMSC LAN89530 USB Ethernet Device */
  1056. USB_DEVICE(0x0424, 0x9E08),
  1057. .driver_info = (unsigned long) &smsc95xx_info,
  1058. },
  1059. { }, /* END */
  1060. };
  1061. MODULE_DEVICE_TABLE(usb, products);
  1062. static struct usb_driver smsc95xx_driver = {
  1063. .name = "smsc95xx",
  1064. .id_table = products,
  1065. .probe = usbnet_probe,
  1066. .suspend = usbnet_suspend,
  1067. .resume = usbnet_resume,
  1068. .disconnect = usbnet_disconnect,
  1069. };
  1070. static int __init smsc95xx_init(void)
  1071. {
  1072. return usb_register(&smsc95xx_driver);
  1073. }
  1074. module_init(smsc95xx_init);
  1075. static void __exit smsc95xx_exit(void)
  1076. {
  1077. usb_deregister(&smsc95xx_driver);
  1078. }
  1079. module_exit(smsc95xx_exit);
  1080. MODULE_AUTHOR("Nancy Lin");
  1081. MODULE_AUTHOR("Steve Glendinning <steve.glendinning@smsc.com>");
  1082. MODULE_DESCRIPTION("SMSC95XX USB 2.0 Ethernet Devices");
  1083. MODULE_LICENSE("GPL");