dl2k.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767
  1. /* D-Link DL2000-based Gigabit Ethernet Adapter Linux driver */
  2. /*
  3. Copyright (c) 2001, 2002 by D-Link Corporation
  4. Written by Edward Peng.<edward_peng@dlink.com.tw>
  5. Created 03-May-2001, base on Linux' sundance.c.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. */
  11. #define DRV_NAME "DL2000/TC902x-based linux driver"
  12. #define DRV_VERSION "v1.19"
  13. #define DRV_RELDATE "2007/08/12"
  14. #include "dl2k.h"
  15. #include <linux/dma-mapping.h>
  16. #define dw32(reg, val) iowrite32(val, ioaddr + (reg))
  17. #define dw16(reg, val) iowrite16(val, ioaddr + (reg))
  18. #define dw8(reg, val) iowrite8(val, ioaddr + (reg))
  19. #define dr32(reg) ioread32(ioaddr + (reg))
  20. #define dr16(reg) ioread16(ioaddr + (reg))
  21. #define dr8(reg) ioread8(ioaddr + (reg))
  22. static char version[] =
  23. KERN_INFO DRV_NAME " " DRV_VERSION " " DRV_RELDATE "\n";
  24. #define MAX_UNITS 8
  25. static int mtu[MAX_UNITS];
  26. static int vlan[MAX_UNITS];
  27. static int jumbo[MAX_UNITS];
  28. static char *media[MAX_UNITS];
  29. static int tx_flow=-1;
  30. static int rx_flow=-1;
  31. static int copy_thresh;
  32. static int rx_coalesce=10; /* Rx frame count each interrupt */
  33. static int rx_timeout=200; /* Rx DMA wait time in 640ns increments */
  34. static int tx_coalesce=16; /* HW xmit count each TxDMAComplete */
  35. MODULE_AUTHOR ("Edward Peng");
  36. MODULE_DESCRIPTION ("D-Link DL2000-based Gigabit Ethernet Adapter");
  37. MODULE_LICENSE("GPL");
  38. module_param_array(mtu, int, NULL, 0);
  39. module_param_array(media, charp, NULL, 0);
  40. module_param_array(vlan, int, NULL, 0);
  41. module_param_array(jumbo, int, NULL, 0);
  42. module_param(tx_flow, int, 0);
  43. module_param(rx_flow, int, 0);
  44. module_param(copy_thresh, int, 0);
  45. module_param(rx_coalesce, int, 0); /* Rx frame count each interrupt */
  46. module_param(rx_timeout, int, 0); /* Rx DMA wait time in 64ns increments */
  47. module_param(tx_coalesce, int, 0); /* HW xmit count each TxDMAComplete */
  48. /* Enable the default interrupts */
  49. #define DEFAULT_INTR (RxDMAComplete | HostError | IntRequested | TxDMAComplete| \
  50. UpdateStats | LinkEvent)
  51. static void dl2k_enable_int(struct netdev_private *np)
  52. {
  53. void __iomem *ioaddr = np->ioaddr;
  54. dw16(IntEnable, DEFAULT_INTR);
  55. }
  56. static const int max_intrloop = 50;
  57. static const int multicast_filter_limit = 0x40;
  58. static int rio_open (struct net_device *dev);
  59. static void rio_timer (unsigned long data);
  60. static void rio_tx_timeout (struct net_device *dev);
  61. static void alloc_list (struct net_device *dev);
  62. static netdev_tx_t start_xmit (struct sk_buff *skb, struct net_device *dev);
  63. static irqreturn_t rio_interrupt (int irq, void *dev_instance);
  64. static void rio_free_tx (struct net_device *dev, int irq);
  65. static void tx_error (struct net_device *dev, int tx_status);
  66. static int receive_packet (struct net_device *dev);
  67. static void rio_error (struct net_device *dev, int int_status);
  68. static int change_mtu (struct net_device *dev, int new_mtu);
  69. static void set_multicast (struct net_device *dev);
  70. static struct net_device_stats *get_stats (struct net_device *dev);
  71. static int clear_stats (struct net_device *dev);
  72. static int rio_ioctl (struct net_device *dev, struct ifreq *rq, int cmd);
  73. static int rio_close (struct net_device *dev);
  74. static int find_miiphy (struct net_device *dev);
  75. static int parse_eeprom (struct net_device *dev);
  76. static int read_eeprom (struct netdev_private *, int eep_addr);
  77. static int mii_wait_link (struct net_device *dev, int wait);
  78. static int mii_set_media (struct net_device *dev);
  79. static int mii_get_media (struct net_device *dev);
  80. static int mii_set_media_pcs (struct net_device *dev);
  81. static int mii_get_media_pcs (struct net_device *dev);
  82. static int mii_read (struct net_device *dev, int phy_addr, int reg_num);
  83. static int mii_write (struct net_device *dev, int phy_addr, int reg_num,
  84. u16 data);
  85. static const struct ethtool_ops ethtool_ops;
  86. static const struct net_device_ops netdev_ops = {
  87. .ndo_open = rio_open,
  88. .ndo_start_xmit = start_xmit,
  89. .ndo_stop = rio_close,
  90. .ndo_get_stats = get_stats,
  91. .ndo_validate_addr = eth_validate_addr,
  92. .ndo_set_mac_address = eth_mac_addr,
  93. .ndo_set_rx_mode = set_multicast,
  94. .ndo_do_ioctl = rio_ioctl,
  95. .ndo_tx_timeout = rio_tx_timeout,
  96. .ndo_change_mtu = change_mtu,
  97. };
  98. static int
  99. rio_probe1 (struct pci_dev *pdev, const struct pci_device_id *ent)
  100. {
  101. struct net_device *dev;
  102. struct netdev_private *np;
  103. static int card_idx;
  104. int chip_idx = ent->driver_data;
  105. int err, irq;
  106. void __iomem *ioaddr;
  107. static int version_printed;
  108. void *ring_space;
  109. dma_addr_t ring_dma;
  110. if (!version_printed++)
  111. printk ("%s", version);
  112. err = pci_enable_device (pdev);
  113. if (err)
  114. return err;
  115. irq = pdev->irq;
  116. err = pci_request_regions (pdev, "dl2k");
  117. if (err)
  118. goto err_out_disable;
  119. pci_set_master (pdev);
  120. err = -ENOMEM;
  121. dev = alloc_etherdev (sizeof (*np));
  122. if (!dev)
  123. goto err_out_res;
  124. SET_NETDEV_DEV(dev, &pdev->dev);
  125. np = netdev_priv(dev);
  126. /* IO registers range. */
  127. ioaddr = pci_iomap(pdev, 0, 0);
  128. if (!ioaddr)
  129. goto err_out_dev;
  130. np->eeprom_addr = ioaddr;
  131. #ifdef MEM_MAPPING
  132. /* MM registers range. */
  133. ioaddr = pci_iomap(pdev, 1, 0);
  134. if (!ioaddr)
  135. goto err_out_iounmap;
  136. #endif
  137. np->ioaddr = ioaddr;
  138. np->chip_id = chip_idx;
  139. np->pdev = pdev;
  140. spin_lock_init (&np->tx_lock);
  141. spin_lock_init (&np->rx_lock);
  142. /* Parse manual configuration */
  143. np->an_enable = 1;
  144. np->tx_coalesce = 1;
  145. if (card_idx < MAX_UNITS) {
  146. if (media[card_idx] != NULL) {
  147. np->an_enable = 0;
  148. if (strcmp (media[card_idx], "auto") == 0 ||
  149. strcmp (media[card_idx], "autosense") == 0 ||
  150. strcmp (media[card_idx], "0") == 0 ) {
  151. np->an_enable = 2;
  152. } else if (strcmp (media[card_idx], "100mbps_fd") == 0 ||
  153. strcmp (media[card_idx], "4") == 0) {
  154. np->speed = 100;
  155. np->full_duplex = 1;
  156. } else if (strcmp (media[card_idx], "100mbps_hd") == 0 ||
  157. strcmp (media[card_idx], "3") == 0) {
  158. np->speed = 100;
  159. np->full_duplex = 0;
  160. } else if (strcmp (media[card_idx], "10mbps_fd") == 0 ||
  161. strcmp (media[card_idx], "2") == 0) {
  162. np->speed = 10;
  163. np->full_duplex = 1;
  164. } else if (strcmp (media[card_idx], "10mbps_hd") == 0 ||
  165. strcmp (media[card_idx], "1") == 0) {
  166. np->speed = 10;
  167. np->full_duplex = 0;
  168. } else if (strcmp (media[card_idx], "1000mbps_fd") == 0 ||
  169. strcmp (media[card_idx], "6") == 0) {
  170. np->speed=1000;
  171. np->full_duplex=1;
  172. } else if (strcmp (media[card_idx], "1000mbps_hd") == 0 ||
  173. strcmp (media[card_idx], "5") == 0) {
  174. np->speed = 1000;
  175. np->full_duplex = 0;
  176. } else {
  177. np->an_enable = 1;
  178. }
  179. }
  180. if (jumbo[card_idx] != 0) {
  181. np->jumbo = 1;
  182. dev->mtu = MAX_JUMBO;
  183. } else {
  184. np->jumbo = 0;
  185. if (mtu[card_idx] > 0 && mtu[card_idx] < PACKET_SIZE)
  186. dev->mtu = mtu[card_idx];
  187. }
  188. np->vlan = (vlan[card_idx] > 0 && vlan[card_idx] < 4096) ?
  189. vlan[card_idx] : 0;
  190. if (rx_coalesce > 0 && rx_timeout > 0) {
  191. np->rx_coalesce = rx_coalesce;
  192. np->rx_timeout = rx_timeout;
  193. np->coalesce = 1;
  194. }
  195. np->tx_flow = (tx_flow == 0) ? 0 : 1;
  196. np->rx_flow = (rx_flow == 0) ? 0 : 1;
  197. if (tx_coalesce < 1)
  198. tx_coalesce = 1;
  199. else if (tx_coalesce > TX_RING_SIZE-1)
  200. tx_coalesce = TX_RING_SIZE - 1;
  201. }
  202. dev->netdev_ops = &netdev_ops;
  203. dev->watchdog_timeo = TX_TIMEOUT;
  204. dev->ethtool_ops = &ethtool_ops;
  205. #if 0
  206. dev->features = NETIF_F_IP_CSUM;
  207. #endif
  208. pci_set_drvdata (pdev, dev);
  209. ring_space = pci_alloc_consistent (pdev, TX_TOTAL_SIZE, &ring_dma);
  210. if (!ring_space)
  211. goto err_out_iounmap;
  212. np->tx_ring = ring_space;
  213. np->tx_ring_dma = ring_dma;
  214. ring_space = pci_alloc_consistent (pdev, RX_TOTAL_SIZE, &ring_dma);
  215. if (!ring_space)
  216. goto err_out_unmap_tx;
  217. np->rx_ring = ring_space;
  218. np->rx_ring_dma = ring_dma;
  219. /* Parse eeprom data */
  220. parse_eeprom (dev);
  221. /* Find PHY address */
  222. err = find_miiphy (dev);
  223. if (err)
  224. goto err_out_unmap_rx;
  225. /* Fiber device? */
  226. np->phy_media = (dr16(ASICCtrl) & PhyMedia) ? 1 : 0;
  227. np->link_status = 0;
  228. /* Set media and reset PHY */
  229. if (np->phy_media) {
  230. /* default Auto-Negotiation for fiber deivices */
  231. if (np->an_enable == 2) {
  232. np->an_enable = 1;
  233. }
  234. mii_set_media_pcs (dev);
  235. } else {
  236. /* Auto-Negotiation is mandatory for 1000BASE-T,
  237. IEEE 802.3ab Annex 28D page 14 */
  238. if (np->speed == 1000)
  239. np->an_enable = 1;
  240. mii_set_media (dev);
  241. }
  242. err = register_netdev (dev);
  243. if (err)
  244. goto err_out_unmap_rx;
  245. card_idx++;
  246. printk (KERN_INFO "%s: %s, %pM, IRQ %d\n",
  247. dev->name, np->name, dev->dev_addr, irq);
  248. if (tx_coalesce > 1)
  249. printk(KERN_INFO "tx_coalesce:\t%d packets\n",
  250. tx_coalesce);
  251. if (np->coalesce)
  252. printk(KERN_INFO
  253. "rx_coalesce:\t%d packets\n"
  254. "rx_timeout: \t%d ns\n",
  255. np->rx_coalesce, np->rx_timeout*640);
  256. if (np->vlan)
  257. printk(KERN_INFO "vlan(id):\t%d\n", np->vlan);
  258. return 0;
  259. err_out_unmap_rx:
  260. pci_free_consistent (pdev, RX_TOTAL_SIZE, np->rx_ring, np->rx_ring_dma);
  261. err_out_unmap_tx:
  262. pci_free_consistent (pdev, TX_TOTAL_SIZE, np->tx_ring, np->tx_ring_dma);
  263. err_out_iounmap:
  264. #ifdef MEM_MAPPING
  265. pci_iounmap(pdev, np->ioaddr);
  266. #endif
  267. pci_iounmap(pdev, np->eeprom_addr);
  268. err_out_dev:
  269. free_netdev (dev);
  270. err_out_res:
  271. pci_release_regions (pdev);
  272. err_out_disable:
  273. pci_disable_device (pdev);
  274. return err;
  275. }
  276. static int
  277. find_miiphy (struct net_device *dev)
  278. {
  279. struct netdev_private *np = netdev_priv(dev);
  280. int i, phy_found = 0;
  281. np = netdev_priv(dev);
  282. np->phy_addr = 1;
  283. for (i = 31; i >= 0; i--) {
  284. int mii_status = mii_read (dev, i, 1);
  285. if (mii_status != 0xffff && mii_status != 0x0000) {
  286. np->phy_addr = i;
  287. phy_found++;
  288. }
  289. }
  290. if (!phy_found) {
  291. printk (KERN_ERR "%s: No MII PHY found!\n", dev->name);
  292. return -ENODEV;
  293. }
  294. return 0;
  295. }
  296. static int
  297. parse_eeprom (struct net_device *dev)
  298. {
  299. struct netdev_private *np = netdev_priv(dev);
  300. void __iomem *ioaddr = np->ioaddr;
  301. int i, j;
  302. u8 sromdata[256];
  303. u8 *psib;
  304. u32 crc;
  305. PSROM_t psrom = (PSROM_t) sromdata;
  306. int cid, next;
  307. for (i = 0; i < 128; i++)
  308. ((__le16 *) sromdata)[i] = cpu_to_le16(read_eeprom(np, i));
  309. if (np->pdev->vendor == PCI_VENDOR_ID_DLINK) { /* D-Link Only */
  310. /* Check CRC */
  311. crc = ~ether_crc_le (256 - 4, sromdata);
  312. if (psrom->crc != cpu_to_le32(crc)) {
  313. printk (KERN_ERR "%s: EEPROM data CRC error.\n",
  314. dev->name);
  315. return -1;
  316. }
  317. }
  318. /* Set MAC address */
  319. for (i = 0; i < 6; i++)
  320. dev->dev_addr[i] = psrom->mac_addr[i];
  321. if (np->pdev->vendor != PCI_VENDOR_ID_DLINK) {
  322. return 0;
  323. }
  324. /* Parse Software Information Block */
  325. i = 0x30;
  326. psib = (u8 *) sromdata;
  327. do {
  328. cid = psib[i++];
  329. next = psib[i++];
  330. if ((cid == 0 && next == 0) || (cid == 0xff && next == 0xff)) {
  331. printk (KERN_ERR "Cell data error\n");
  332. return -1;
  333. }
  334. switch (cid) {
  335. case 0: /* Format version */
  336. break;
  337. case 1: /* End of cell */
  338. return 0;
  339. case 2: /* Duplex Polarity */
  340. np->duplex_polarity = psib[i];
  341. dw8(PhyCtrl, dr8(PhyCtrl) | psib[i]);
  342. break;
  343. case 3: /* Wake Polarity */
  344. np->wake_polarity = psib[i];
  345. break;
  346. case 9: /* Adapter description */
  347. j = (next - i > 255) ? 255 : next - i;
  348. memcpy (np->name, &(psib[i]), j);
  349. break;
  350. case 4:
  351. case 5:
  352. case 6:
  353. case 7:
  354. case 8: /* Reversed */
  355. break;
  356. default: /* Unknown cell */
  357. return -1;
  358. }
  359. i = next;
  360. } while (1);
  361. return 0;
  362. }
  363. static int
  364. rio_open (struct net_device *dev)
  365. {
  366. struct netdev_private *np = netdev_priv(dev);
  367. void __iomem *ioaddr = np->ioaddr;
  368. const int irq = np->pdev->irq;
  369. int i;
  370. u16 macctrl;
  371. i = request_irq(irq, rio_interrupt, IRQF_SHARED, dev->name, dev);
  372. if (i)
  373. return i;
  374. /* Reset all logic functions */
  375. dw16(ASICCtrl + 2,
  376. GlobalReset | DMAReset | FIFOReset | NetworkReset | HostReset);
  377. mdelay(10);
  378. /* DebugCtrl bit 4, 5, 9 must set */
  379. dw32(DebugCtrl, dr32(DebugCtrl) | 0x0230);
  380. /* Jumbo frame */
  381. if (np->jumbo != 0)
  382. dw16(MaxFrameSize, MAX_JUMBO+14);
  383. alloc_list (dev);
  384. /* Get station address */
  385. for (i = 0; i < 6; i++)
  386. dw8(StationAddr0 + i, dev->dev_addr[i]);
  387. set_multicast (dev);
  388. if (np->coalesce) {
  389. dw32(RxDMAIntCtrl, np->rx_coalesce | np->rx_timeout << 16);
  390. }
  391. /* Set RIO to poll every N*320nsec. */
  392. dw8(RxDMAPollPeriod, 0x20);
  393. dw8(TxDMAPollPeriod, 0xff);
  394. dw8(RxDMABurstThresh, 0x30);
  395. dw8(RxDMAUrgentThresh, 0x30);
  396. dw32(RmonStatMask, 0x0007ffff);
  397. /* clear statistics */
  398. clear_stats (dev);
  399. /* VLAN supported */
  400. if (np->vlan) {
  401. /* priority field in RxDMAIntCtrl */
  402. dw32(RxDMAIntCtrl, dr32(RxDMAIntCtrl) | 0x7 << 10);
  403. /* VLANId */
  404. dw16(VLANId, np->vlan);
  405. /* Length/Type should be 0x8100 */
  406. dw32(VLANTag, 0x8100 << 16 | np->vlan);
  407. /* Enable AutoVLANuntagging, but disable AutoVLANtagging.
  408. VLAN information tagged by TFC' VID, CFI fields. */
  409. dw32(MACCtrl, dr32(MACCtrl) | AutoVLANuntagging);
  410. }
  411. setup_timer(&np->timer, rio_timer, (unsigned long)dev);
  412. np->timer.expires = jiffies + 1*HZ;
  413. add_timer (&np->timer);
  414. /* Start Tx/Rx */
  415. dw32(MACCtrl, dr32(MACCtrl) | StatsEnable | RxEnable | TxEnable);
  416. macctrl = 0;
  417. macctrl |= (np->vlan) ? AutoVLANuntagging : 0;
  418. macctrl |= (np->full_duplex) ? DuplexSelect : 0;
  419. macctrl |= (np->tx_flow) ? TxFlowControlEnable : 0;
  420. macctrl |= (np->rx_flow) ? RxFlowControlEnable : 0;
  421. dw16(MACCtrl, macctrl);
  422. netif_start_queue (dev);
  423. dl2k_enable_int(np);
  424. return 0;
  425. }
  426. static void
  427. rio_timer (unsigned long data)
  428. {
  429. struct net_device *dev = (struct net_device *)data;
  430. struct netdev_private *np = netdev_priv(dev);
  431. unsigned int entry;
  432. int next_tick = 1*HZ;
  433. unsigned long flags;
  434. spin_lock_irqsave(&np->rx_lock, flags);
  435. /* Recover rx ring exhausted error */
  436. if (np->cur_rx - np->old_rx >= RX_RING_SIZE) {
  437. printk(KERN_INFO "Try to recover rx ring exhausted...\n");
  438. /* Re-allocate skbuffs to fill the descriptor ring */
  439. for (; np->cur_rx - np->old_rx > 0; np->old_rx++) {
  440. struct sk_buff *skb;
  441. entry = np->old_rx % RX_RING_SIZE;
  442. /* Dropped packets don't need to re-allocate */
  443. if (np->rx_skbuff[entry] == NULL) {
  444. skb = netdev_alloc_skb_ip_align(dev,
  445. np->rx_buf_sz);
  446. if (skb == NULL) {
  447. np->rx_ring[entry].fraginfo = 0;
  448. printk (KERN_INFO
  449. "%s: Still unable to re-allocate Rx skbuff.#%d\n",
  450. dev->name, entry);
  451. break;
  452. }
  453. np->rx_skbuff[entry] = skb;
  454. np->rx_ring[entry].fraginfo =
  455. cpu_to_le64 (pci_map_single
  456. (np->pdev, skb->data, np->rx_buf_sz,
  457. PCI_DMA_FROMDEVICE));
  458. }
  459. np->rx_ring[entry].fraginfo |=
  460. cpu_to_le64((u64)np->rx_buf_sz << 48);
  461. np->rx_ring[entry].status = 0;
  462. } /* end for */
  463. } /* end if */
  464. spin_unlock_irqrestore (&np->rx_lock, flags);
  465. np->timer.expires = jiffies + next_tick;
  466. add_timer(&np->timer);
  467. }
  468. static void
  469. rio_tx_timeout (struct net_device *dev)
  470. {
  471. struct netdev_private *np = netdev_priv(dev);
  472. void __iomem *ioaddr = np->ioaddr;
  473. printk (KERN_INFO "%s: Tx timed out (%4.4x), is buffer full?\n",
  474. dev->name, dr32(TxStatus));
  475. rio_free_tx(dev, 0);
  476. dev->if_port = 0;
  477. dev->trans_start = jiffies; /* prevent tx timeout */
  478. }
  479. /* allocate and initialize Tx and Rx descriptors */
  480. static void
  481. alloc_list (struct net_device *dev)
  482. {
  483. struct netdev_private *np = netdev_priv(dev);
  484. void __iomem *ioaddr = np->ioaddr;
  485. int i;
  486. np->cur_rx = np->cur_tx = 0;
  487. np->old_rx = np->old_tx = 0;
  488. np->rx_buf_sz = (dev->mtu <= 1500 ? PACKET_SIZE : dev->mtu + 32);
  489. /* Initialize Tx descriptors, TFDListPtr leaves in start_xmit(). */
  490. for (i = 0; i < TX_RING_SIZE; i++) {
  491. np->tx_skbuff[i] = NULL;
  492. np->tx_ring[i].status = cpu_to_le64 (TFDDone);
  493. np->tx_ring[i].next_desc = cpu_to_le64 (np->tx_ring_dma +
  494. ((i+1)%TX_RING_SIZE) *
  495. sizeof (struct netdev_desc));
  496. }
  497. /* Initialize Rx descriptors */
  498. for (i = 0; i < RX_RING_SIZE; i++) {
  499. np->rx_ring[i].next_desc = cpu_to_le64 (np->rx_ring_dma +
  500. ((i + 1) % RX_RING_SIZE) *
  501. sizeof (struct netdev_desc));
  502. np->rx_ring[i].status = 0;
  503. np->rx_ring[i].fraginfo = 0;
  504. np->rx_skbuff[i] = NULL;
  505. }
  506. /* Allocate the rx buffers */
  507. for (i = 0; i < RX_RING_SIZE; i++) {
  508. /* Allocated fixed size of skbuff */
  509. struct sk_buff *skb;
  510. skb = netdev_alloc_skb_ip_align(dev, np->rx_buf_sz);
  511. np->rx_skbuff[i] = skb;
  512. if (skb == NULL)
  513. break;
  514. /* Rubicon now supports 40 bits of addressing space. */
  515. np->rx_ring[i].fraginfo =
  516. cpu_to_le64 ( pci_map_single (
  517. np->pdev, skb->data, np->rx_buf_sz,
  518. PCI_DMA_FROMDEVICE));
  519. np->rx_ring[i].fraginfo |= cpu_to_le64((u64)np->rx_buf_sz << 48);
  520. }
  521. /* Set RFDListPtr */
  522. dw32(RFDListPtr0, np->rx_ring_dma);
  523. dw32(RFDListPtr1, 0);
  524. }
  525. static netdev_tx_t
  526. start_xmit (struct sk_buff *skb, struct net_device *dev)
  527. {
  528. struct netdev_private *np = netdev_priv(dev);
  529. void __iomem *ioaddr = np->ioaddr;
  530. struct netdev_desc *txdesc;
  531. unsigned entry;
  532. u64 tfc_vlan_tag = 0;
  533. if (np->link_status == 0) { /* Link Down */
  534. dev_kfree_skb(skb);
  535. return NETDEV_TX_OK;
  536. }
  537. entry = np->cur_tx % TX_RING_SIZE;
  538. np->tx_skbuff[entry] = skb;
  539. txdesc = &np->tx_ring[entry];
  540. #if 0
  541. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  542. txdesc->status |=
  543. cpu_to_le64 (TCPChecksumEnable | UDPChecksumEnable |
  544. IPChecksumEnable);
  545. }
  546. #endif
  547. if (np->vlan) {
  548. tfc_vlan_tag = VLANTagInsert |
  549. ((u64)np->vlan << 32) |
  550. ((u64)skb->priority << 45);
  551. }
  552. txdesc->fraginfo = cpu_to_le64 (pci_map_single (np->pdev, skb->data,
  553. skb->len,
  554. PCI_DMA_TODEVICE));
  555. txdesc->fraginfo |= cpu_to_le64((u64)skb->len << 48);
  556. /* DL2K bug: DMA fails to get next descriptor ptr in 10Mbps mode
  557. * Work around: Always use 1 descriptor in 10Mbps mode */
  558. if (entry % np->tx_coalesce == 0 || np->speed == 10)
  559. txdesc->status = cpu_to_le64 (entry | tfc_vlan_tag |
  560. WordAlignDisable |
  561. TxDMAIndicate |
  562. (1 << FragCountShift));
  563. else
  564. txdesc->status = cpu_to_le64 (entry | tfc_vlan_tag |
  565. WordAlignDisable |
  566. (1 << FragCountShift));
  567. /* TxDMAPollNow */
  568. dw32(DMACtrl, dr32(DMACtrl) | 0x00001000);
  569. /* Schedule ISR */
  570. dw32(CountDown, 10000);
  571. np->cur_tx = (np->cur_tx + 1) % TX_RING_SIZE;
  572. if ((np->cur_tx - np->old_tx + TX_RING_SIZE) % TX_RING_SIZE
  573. < TX_QUEUE_LEN - 1 && np->speed != 10) {
  574. /* do nothing */
  575. } else if (!netif_queue_stopped(dev)) {
  576. netif_stop_queue (dev);
  577. }
  578. /* The first TFDListPtr */
  579. if (!dr32(TFDListPtr0)) {
  580. dw32(TFDListPtr0, np->tx_ring_dma +
  581. entry * sizeof (struct netdev_desc));
  582. dw32(TFDListPtr1, 0);
  583. }
  584. return NETDEV_TX_OK;
  585. }
  586. static irqreturn_t
  587. rio_interrupt (int irq, void *dev_instance)
  588. {
  589. struct net_device *dev = dev_instance;
  590. struct netdev_private *np = netdev_priv(dev);
  591. void __iomem *ioaddr = np->ioaddr;
  592. unsigned int_status;
  593. int cnt = max_intrloop;
  594. int handled = 0;
  595. while (1) {
  596. int_status = dr16(IntStatus);
  597. dw16(IntStatus, int_status);
  598. int_status &= DEFAULT_INTR;
  599. if (int_status == 0 || --cnt < 0)
  600. break;
  601. handled = 1;
  602. /* Processing received packets */
  603. if (int_status & RxDMAComplete)
  604. receive_packet (dev);
  605. /* TxDMAComplete interrupt */
  606. if ((int_status & (TxDMAComplete|IntRequested))) {
  607. int tx_status;
  608. tx_status = dr32(TxStatus);
  609. if (tx_status & 0x01)
  610. tx_error (dev, tx_status);
  611. /* Free used tx skbuffs */
  612. rio_free_tx (dev, 1);
  613. }
  614. /* Handle uncommon events */
  615. if (int_status &
  616. (HostError | LinkEvent | UpdateStats))
  617. rio_error (dev, int_status);
  618. }
  619. if (np->cur_tx != np->old_tx)
  620. dw32(CountDown, 100);
  621. return IRQ_RETVAL(handled);
  622. }
  623. static inline dma_addr_t desc_to_dma(struct netdev_desc *desc)
  624. {
  625. return le64_to_cpu(desc->fraginfo) & DMA_BIT_MASK(48);
  626. }
  627. static void
  628. rio_free_tx (struct net_device *dev, int irq)
  629. {
  630. struct netdev_private *np = netdev_priv(dev);
  631. int entry = np->old_tx % TX_RING_SIZE;
  632. int tx_use = 0;
  633. unsigned long flag = 0;
  634. if (irq)
  635. spin_lock(&np->tx_lock);
  636. else
  637. spin_lock_irqsave(&np->tx_lock, flag);
  638. /* Free used tx skbuffs */
  639. while (entry != np->cur_tx) {
  640. struct sk_buff *skb;
  641. if (!(np->tx_ring[entry].status & cpu_to_le64(TFDDone)))
  642. break;
  643. skb = np->tx_skbuff[entry];
  644. pci_unmap_single (np->pdev,
  645. desc_to_dma(&np->tx_ring[entry]),
  646. skb->len, PCI_DMA_TODEVICE);
  647. if (irq)
  648. dev_kfree_skb_irq (skb);
  649. else
  650. dev_kfree_skb (skb);
  651. np->tx_skbuff[entry] = NULL;
  652. entry = (entry + 1) % TX_RING_SIZE;
  653. tx_use++;
  654. }
  655. if (irq)
  656. spin_unlock(&np->tx_lock);
  657. else
  658. spin_unlock_irqrestore(&np->tx_lock, flag);
  659. np->old_tx = entry;
  660. /* If the ring is no longer full, clear tx_full and
  661. call netif_wake_queue() */
  662. if (netif_queue_stopped(dev) &&
  663. ((np->cur_tx - np->old_tx + TX_RING_SIZE) % TX_RING_SIZE
  664. < TX_QUEUE_LEN - 1 || np->speed == 10)) {
  665. netif_wake_queue (dev);
  666. }
  667. }
  668. static void
  669. tx_error (struct net_device *dev, int tx_status)
  670. {
  671. struct netdev_private *np = netdev_priv(dev);
  672. void __iomem *ioaddr = np->ioaddr;
  673. int frame_id;
  674. int i;
  675. frame_id = (tx_status & 0xffff0000);
  676. printk (KERN_ERR "%s: Transmit error, TxStatus %4.4x, FrameId %d.\n",
  677. dev->name, tx_status, frame_id);
  678. np->stats.tx_errors++;
  679. /* Ttransmit Underrun */
  680. if (tx_status & 0x10) {
  681. np->stats.tx_fifo_errors++;
  682. dw16(TxStartThresh, dr16(TxStartThresh) + 0x10);
  683. /* Transmit Underrun need to set TxReset, DMARest, FIFOReset */
  684. dw16(ASICCtrl + 2,
  685. TxReset | DMAReset | FIFOReset | NetworkReset);
  686. /* Wait for ResetBusy bit clear */
  687. for (i = 50; i > 0; i--) {
  688. if (!(dr16(ASICCtrl + 2) & ResetBusy))
  689. break;
  690. mdelay (1);
  691. }
  692. rio_free_tx (dev, 1);
  693. /* Reset TFDListPtr */
  694. dw32(TFDListPtr0, np->tx_ring_dma +
  695. np->old_tx * sizeof (struct netdev_desc));
  696. dw32(TFDListPtr1, 0);
  697. /* Let TxStartThresh stay default value */
  698. }
  699. /* Late Collision */
  700. if (tx_status & 0x04) {
  701. np->stats.tx_fifo_errors++;
  702. /* TxReset and clear FIFO */
  703. dw16(ASICCtrl + 2, TxReset | FIFOReset);
  704. /* Wait reset done */
  705. for (i = 50; i > 0; i--) {
  706. if (!(dr16(ASICCtrl + 2) & ResetBusy))
  707. break;
  708. mdelay (1);
  709. }
  710. /* Let TxStartThresh stay default value */
  711. }
  712. /* Maximum Collisions */
  713. #ifdef ETHER_STATS
  714. if (tx_status & 0x08)
  715. np->stats.collisions16++;
  716. #else
  717. if (tx_status & 0x08)
  718. np->stats.collisions++;
  719. #endif
  720. /* Restart the Tx */
  721. dw32(MACCtrl, dr16(MACCtrl) | TxEnable);
  722. }
  723. static int
  724. receive_packet (struct net_device *dev)
  725. {
  726. struct netdev_private *np = netdev_priv(dev);
  727. int entry = np->cur_rx % RX_RING_SIZE;
  728. int cnt = 30;
  729. /* If RFDDone, FrameStart and FrameEnd set, there is a new packet in. */
  730. while (1) {
  731. struct netdev_desc *desc = &np->rx_ring[entry];
  732. int pkt_len;
  733. u64 frame_status;
  734. if (!(desc->status & cpu_to_le64(RFDDone)) ||
  735. !(desc->status & cpu_to_le64(FrameStart)) ||
  736. !(desc->status & cpu_to_le64(FrameEnd)))
  737. break;
  738. /* Chip omits the CRC. */
  739. frame_status = le64_to_cpu(desc->status);
  740. pkt_len = frame_status & 0xffff;
  741. if (--cnt < 0)
  742. break;
  743. /* Update rx error statistics, drop packet. */
  744. if (frame_status & RFS_Errors) {
  745. np->stats.rx_errors++;
  746. if (frame_status & (RxRuntFrame | RxLengthError))
  747. np->stats.rx_length_errors++;
  748. if (frame_status & RxFCSError)
  749. np->stats.rx_crc_errors++;
  750. if (frame_status & RxAlignmentError && np->speed != 1000)
  751. np->stats.rx_frame_errors++;
  752. if (frame_status & RxFIFOOverrun)
  753. np->stats.rx_fifo_errors++;
  754. } else {
  755. struct sk_buff *skb;
  756. /* Small skbuffs for short packets */
  757. if (pkt_len > copy_thresh) {
  758. pci_unmap_single (np->pdev,
  759. desc_to_dma(desc),
  760. np->rx_buf_sz,
  761. PCI_DMA_FROMDEVICE);
  762. skb_put (skb = np->rx_skbuff[entry], pkt_len);
  763. np->rx_skbuff[entry] = NULL;
  764. } else if ((skb = netdev_alloc_skb_ip_align(dev, pkt_len))) {
  765. pci_dma_sync_single_for_cpu(np->pdev,
  766. desc_to_dma(desc),
  767. np->rx_buf_sz,
  768. PCI_DMA_FROMDEVICE);
  769. skb_copy_to_linear_data (skb,
  770. np->rx_skbuff[entry]->data,
  771. pkt_len);
  772. skb_put (skb, pkt_len);
  773. pci_dma_sync_single_for_device(np->pdev,
  774. desc_to_dma(desc),
  775. np->rx_buf_sz,
  776. PCI_DMA_FROMDEVICE);
  777. }
  778. skb->protocol = eth_type_trans (skb, dev);
  779. #if 0
  780. /* Checksum done by hw, but csum value unavailable. */
  781. if (np->pdev->pci_rev_id >= 0x0c &&
  782. !(frame_status & (TCPError | UDPError | IPError))) {
  783. skb->ip_summed = CHECKSUM_UNNECESSARY;
  784. }
  785. #endif
  786. netif_rx (skb);
  787. }
  788. entry = (entry + 1) % RX_RING_SIZE;
  789. }
  790. spin_lock(&np->rx_lock);
  791. np->cur_rx = entry;
  792. /* Re-allocate skbuffs to fill the descriptor ring */
  793. entry = np->old_rx;
  794. while (entry != np->cur_rx) {
  795. struct sk_buff *skb;
  796. /* Dropped packets don't need to re-allocate */
  797. if (np->rx_skbuff[entry] == NULL) {
  798. skb = netdev_alloc_skb_ip_align(dev, np->rx_buf_sz);
  799. if (skb == NULL) {
  800. np->rx_ring[entry].fraginfo = 0;
  801. printk (KERN_INFO
  802. "%s: receive_packet: "
  803. "Unable to re-allocate Rx skbuff.#%d\n",
  804. dev->name, entry);
  805. break;
  806. }
  807. np->rx_skbuff[entry] = skb;
  808. np->rx_ring[entry].fraginfo =
  809. cpu_to_le64 (pci_map_single
  810. (np->pdev, skb->data, np->rx_buf_sz,
  811. PCI_DMA_FROMDEVICE));
  812. }
  813. np->rx_ring[entry].fraginfo |=
  814. cpu_to_le64((u64)np->rx_buf_sz << 48);
  815. np->rx_ring[entry].status = 0;
  816. entry = (entry + 1) % RX_RING_SIZE;
  817. }
  818. np->old_rx = entry;
  819. spin_unlock(&np->rx_lock);
  820. return 0;
  821. }
  822. static void
  823. rio_error (struct net_device *dev, int int_status)
  824. {
  825. struct netdev_private *np = netdev_priv(dev);
  826. void __iomem *ioaddr = np->ioaddr;
  827. u16 macctrl;
  828. /* Link change event */
  829. if (int_status & LinkEvent) {
  830. if (mii_wait_link (dev, 10) == 0) {
  831. printk (KERN_INFO "%s: Link up\n", dev->name);
  832. if (np->phy_media)
  833. mii_get_media_pcs (dev);
  834. else
  835. mii_get_media (dev);
  836. if (np->speed == 1000)
  837. np->tx_coalesce = tx_coalesce;
  838. else
  839. np->tx_coalesce = 1;
  840. macctrl = 0;
  841. macctrl |= (np->vlan) ? AutoVLANuntagging : 0;
  842. macctrl |= (np->full_duplex) ? DuplexSelect : 0;
  843. macctrl |= (np->tx_flow) ?
  844. TxFlowControlEnable : 0;
  845. macctrl |= (np->rx_flow) ?
  846. RxFlowControlEnable : 0;
  847. dw16(MACCtrl, macctrl);
  848. np->link_status = 1;
  849. netif_carrier_on(dev);
  850. } else {
  851. printk (KERN_INFO "%s: Link off\n", dev->name);
  852. np->link_status = 0;
  853. netif_carrier_off(dev);
  854. }
  855. }
  856. /* UpdateStats statistics registers */
  857. if (int_status & UpdateStats) {
  858. get_stats (dev);
  859. }
  860. /* PCI Error, a catastronphic error related to the bus interface
  861. occurs, set GlobalReset and HostReset to reset. */
  862. if (int_status & HostError) {
  863. printk (KERN_ERR "%s: HostError! IntStatus %4.4x.\n",
  864. dev->name, int_status);
  865. dw16(ASICCtrl + 2, GlobalReset | HostReset);
  866. mdelay (500);
  867. }
  868. }
  869. static struct net_device_stats *
  870. get_stats (struct net_device *dev)
  871. {
  872. struct netdev_private *np = netdev_priv(dev);
  873. void __iomem *ioaddr = np->ioaddr;
  874. #ifdef MEM_MAPPING
  875. int i;
  876. #endif
  877. unsigned int stat_reg;
  878. /* All statistics registers need to be acknowledged,
  879. else statistic overflow could cause problems */
  880. np->stats.rx_packets += dr32(FramesRcvOk);
  881. np->stats.tx_packets += dr32(FramesXmtOk);
  882. np->stats.rx_bytes += dr32(OctetRcvOk);
  883. np->stats.tx_bytes += dr32(OctetXmtOk);
  884. np->stats.multicast = dr32(McstFramesRcvdOk);
  885. np->stats.collisions += dr32(SingleColFrames)
  886. + dr32(MultiColFrames);
  887. /* detailed tx errors */
  888. stat_reg = dr16(FramesAbortXSColls);
  889. np->stats.tx_aborted_errors += stat_reg;
  890. np->stats.tx_errors += stat_reg;
  891. stat_reg = dr16(CarrierSenseErrors);
  892. np->stats.tx_carrier_errors += stat_reg;
  893. np->stats.tx_errors += stat_reg;
  894. /* Clear all other statistic register. */
  895. dr32(McstOctetXmtOk);
  896. dr16(BcstFramesXmtdOk);
  897. dr32(McstFramesXmtdOk);
  898. dr16(BcstFramesRcvdOk);
  899. dr16(MacControlFramesRcvd);
  900. dr16(FrameTooLongErrors);
  901. dr16(InRangeLengthErrors);
  902. dr16(FramesCheckSeqErrors);
  903. dr16(FramesLostRxErrors);
  904. dr32(McstOctetXmtOk);
  905. dr32(BcstOctetXmtOk);
  906. dr32(McstFramesXmtdOk);
  907. dr32(FramesWDeferredXmt);
  908. dr32(LateCollisions);
  909. dr16(BcstFramesXmtdOk);
  910. dr16(MacControlFramesXmtd);
  911. dr16(FramesWEXDeferal);
  912. #ifdef MEM_MAPPING
  913. for (i = 0x100; i <= 0x150; i += 4)
  914. dr32(i);
  915. #endif
  916. dr16(TxJumboFrames);
  917. dr16(RxJumboFrames);
  918. dr16(TCPCheckSumErrors);
  919. dr16(UDPCheckSumErrors);
  920. dr16(IPCheckSumErrors);
  921. return &np->stats;
  922. }
  923. static int
  924. clear_stats (struct net_device *dev)
  925. {
  926. struct netdev_private *np = netdev_priv(dev);
  927. void __iomem *ioaddr = np->ioaddr;
  928. #ifdef MEM_MAPPING
  929. int i;
  930. #endif
  931. /* All statistics registers need to be acknowledged,
  932. else statistic overflow could cause problems */
  933. dr32(FramesRcvOk);
  934. dr32(FramesXmtOk);
  935. dr32(OctetRcvOk);
  936. dr32(OctetXmtOk);
  937. dr32(McstFramesRcvdOk);
  938. dr32(SingleColFrames);
  939. dr32(MultiColFrames);
  940. dr32(LateCollisions);
  941. /* detailed rx errors */
  942. dr16(FrameTooLongErrors);
  943. dr16(InRangeLengthErrors);
  944. dr16(FramesCheckSeqErrors);
  945. dr16(FramesLostRxErrors);
  946. /* detailed tx errors */
  947. dr16(FramesAbortXSColls);
  948. dr16(CarrierSenseErrors);
  949. /* Clear all other statistic register. */
  950. dr32(McstOctetXmtOk);
  951. dr16(BcstFramesXmtdOk);
  952. dr32(McstFramesXmtdOk);
  953. dr16(BcstFramesRcvdOk);
  954. dr16(MacControlFramesRcvd);
  955. dr32(McstOctetXmtOk);
  956. dr32(BcstOctetXmtOk);
  957. dr32(McstFramesXmtdOk);
  958. dr32(FramesWDeferredXmt);
  959. dr16(BcstFramesXmtdOk);
  960. dr16(MacControlFramesXmtd);
  961. dr16(FramesWEXDeferal);
  962. #ifdef MEM_MAPPING
  963. for (i = 0x100; i <= 0x150; i += 4)
  964. dr32(i);
  965. #endif
  966. dr16(TxJumboFrames);
  967. dr16(RxJumboFrames);
  968. dr16(TCPCheckSumErrors);
  969. dr16(UDPCheckSumErrors);
  970. dr16(IPCheckSumErrors);
  971. return 0;
  972. }
  973. static int
  974. change_mtu (struct net_device *dev, int new_mtu)
  975. {
  976. struct netdev_private *np = netdev_priv(dev);
  977. int max = (np->jumbo) ? MAX_JUMBO : 1536;
  978. if ((new_mtu < 68) || (new_mtu > max)) {
  979. return -EINVAL;
  980. }
  981. dev->mtu = new_mtu;
  982. return 0;
  983. }
  984. static void
  985. set_multicast (struct net_device *dev)
  986. {
  987. struct netdev_private *np = netdev_priv(dev);
  988. void __iomem *ioaddr = np->ioaddr;
  989. u32 hash_table[2];
  990. u16 rx_mode = 0;
  991. hash_table[0] = hash_table[1] = 0;
  992. /* RxFlowcontrol DA: 01-80-C2-00-00-01. Hash index=0x39 */
  993. hash_table[1] |= 0x02000000;
  994. if (dev->flags & IFF_PROMISC) {
  995. /* Receive all frames promiscuously. */
  996. rx_mode = ReceiveAllFrames;
  997. } else if ((dev->flags & IFF_ALLMULTI) ||
  998. (netdev_mc_count(dev) > multicast_filter_limit)) {
  999. /* Receive broadcast and multicast frames */
  1000. rx_mode = ReceiveBroadcast | ReceiveMulticast | ReceiveUnicast;
  1001. } else if (!netdev_mc_empty(dev)) {
  1002. struct netdev_hw_addr *ha;
  1003. /* Receive broadcast frames and multicast frames filtering
  1004. by Hashtable */
  1005. rx_mode =
  1006. ReceiveBroadcast | ReceiveMulticastHash | ReceiveUnicast;
  1007. netdev_for_each_mc_addr(ha, dev) {
  1008. int bit, index = 0;
  1009. int crc = ether_crc_le(ETH_ALEN, ha->addr);
  1010. /* The inverted high significant 6 bits of CRC are
  1011. used as an index to hashtable */
  1012. for (bit = 0; bit < 6; bit++)
  1013. if (crc & (1 << (31 - bit)))
  1014. index |= (1 << bit);
  1015. hash_table[index / 32] |= (1 << (index % 32));
  1016. }
  1017. } else {
  1018. rx_mode = ReceiveBroadcast | ReceiveUnicast;
  1019. }
  1020. if (np->vlan) {
  1021. /* ReceiveVLANMatch field in ReceiveMode */
  1022. rx_mode |= ReceiveVLANMatch;
  1023. }
  1024. dw32(HashTable0, hash_table[0]);
  1025. dw32(HashTable1, hash_table[1]);
  1026. dw16(ReceiveMode, rx_mode);
  1027. }
  1028. static void rio_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  1029. {
  1030. struct netdev_private *np = netdev_priv(dev);
  1031. strlcpy(info->driver, "dl2k", sizeof(info->driver));
  1032. strlcpy(info->version, DRV_VERSION, sizeof(info->version));
  1033. strlcpy(info->bus_info, pci_name(np->pdev), sizeof(info->bus_info));
  1034. }
  1035. static int rio_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1036. {
  1037. struct netdev_private *np = netdev_priv(dev);
  1038. if (np->phy_media) {
  1039. /* fiber device */
  1040. cmd->supported = SUPPORTED_Autoneg | SUPPORTED_FIBRE;
  1041. cmd->advertising= ADVERTISED_Autoneg | ADVERTISED_FIBRE;
  1042. cmd->port = PORT_FIBRE;
  1043. cmd->transceiver = XCVR_INTERNAL;
  1044. } else {
  1045. /* copper device */
  1046. cmd->supported = SUPPORTED_10baseT_Half |
  1047. SUPPORTED_10baseT_Full | SUPPORTED_100baseT_Half
  1048. | SUPPORTED_100baseT_Full | SUPPORTED_1000baseT_Full |
  1049. SUPPORTED_Autoneg | SUPPORTED_MII;
  1050. cmd->advertising = ADVERTISED_10baseT_Half |
  1051. ADVERTISED_10baseT_Full | ADVERTISED_100baseT_Half |
  1052. ADVERTISED_100baseT_Full | ADVERTISED_1000baseT_Full|
  1053. ADVERTISED_Autoneg | ADVERTISED_MII;
  1054. cmd->port = PORT_MII;
  1055. cmd->transceiver = XCVR_INTERNAL;
  1056. }
  1057. if ( np->link_status ) {
  1058. ethtool_cmd_speed_set(cmd, np->speed);
  1059. cmd->duplex = np->full_duplex ? DUPLEX_FULL : DUPLEX_HALF;
  1060. } else {
  1061. ethtool_cmd_speed_set(cmd, SPEED_UNKNOWN);
  1062. cmd->duplex = DUPLEX_UNKNOWN;
  1063. }
  1064. if ( np->an_enable)
  1065. cmd->autoneg = AUTONEG_ENABLE;
  1066. else
  1067. cmd->autoneg = AUTONEG_DISABLE;
  1068. cmd->phy_address = np->phy_addr;
  1069. return 0;
  1070. }
  1071. static int rio_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1072. {
  1073. struct netdev_private *np = netdev_priv(dev);
  1074. netif_carrier_off(dev);
  1075. if (cmd->autoneg == AUTONEG_ENABLE) {
  1076. if (np->an_enable)
  1077. return 0;
  1078. else {
  1079. np->an_enable = 1;
  1080. mii_set_media(dev);
  1081. return 0;
  1082. }
  1083. } else {
  1084. np->an_enable = 0;
  1085. if (np->speed == 1000) {
  1086. ethtool_cmd_speed_set(cmd, SPEED_100);
  1087. cmd->duplex = DUPLEX_FULL;
  1088. printk("Warning!! Can't disable Auto negotiation in 1000Mbps, change to Manual 100Mbps, Full duplex.\n");
  1089. }
  1090. switch (ethtool_cmd_speed(cmd)) {
  1091. case SPEED_10:
  1092. np->speed = 10;
  1093. np->full_duplex = (cmd->duplex == DUPLEX_FULL);
  1094. break;
  1095. case SPEED_100:
  1096. np->speed = 100;
  1097. np->full_duplex = (cmd->duplex == DUPLEX_FULL);
  1098. break;
  1099. case SPEED_1000: /* not supported */
  1100. default:
  1101. return -EINVAL;
  1102. }
  1103. mii_set_media(dev);
  1104. }
  1105. return 0;
  1106. }
  1107. static u32 rio_get_link(struct net_device *dev)
  1108. {
  1109. struct netdev_private *np = netdev_priv(dev);
  1110. return np->link_status;
  1111. }
  1112. static const struct ethtool_ops ethtool_ops = {
  1113. .get_drvinfo = rio_get_drvinfo,
  1114. .get_settings = rio_get_settings,
  1115. .set_settings = rio_set_settings,
  1116. .get_link = rio_get_link,
  1117. };
  1118. static int
  1119. rio_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
  1120. {
  1121. int phy_addr;
  1122. struct netdev_private *np = netdev_priv(dev);
  1123. struct mii_ioctl_data *miidata = if_mii(rq);
  1124. phy_addr = np->phy_addr;
  1125. switch (cmd) {
  1126. case SIOCGMIIPHY:
  1127. miidata->phy_id = phy_addr;
  1128. break;
  1129. case SIOCGMIIREG:
  1130. miidata->val_out = mii_read (dev, phy_addr, miidata->reg_num);
  1131. break;
  1132. case SIOCSMIIREG:
  1133. if (!capable(CAP_NET_ADMIN))
  1134. return -EPERM;
  1135. mii_write (dev, phy_addr, miidata->reg_num, miidata->val_in);
  1136. break;
  1137. default:
  1138. return -EOPNOTSUPP;
  1139. }
  1140. return 0;
  1141. }
  1142. #define EEP_READ 0x0200
  1143. #define EEP_BUSY 0x8000
  1144. /* Read the EEPROM word */
  1145. /* We use I/O instruction to read/write eeprom to avoid fail on some machines */
  1146. static int read_eeprom(struct netdev_private *np, int eep_addr)
  1147. {
  1148. void __iomem *ioaddr = np->eeprom_addr;
  1149. int i = 1000;
  1150. dw16(EepromCtrl, EEP_READ | (eep_addr & 0xff));
  1151. while (i-- > 0) {
  1152. if (!(dr16(EepromCtrl) & EEP_BUSY))
  1153. return dr16(EepromData);
  1154. }
  1155. return 0;
  1156. }
  1157. enum phy_ctrl_bits {
  1158. MII_READ = 0x00, MII_CLK = 0x01, MII_DATA1 = 0x02, MII_WRITE = 0x04,
  1159. MII_DUPLEX = 0x08,
  1160. };
  1161. #define mii_delay() dr8(PhyCtrl)
  1162. static void
  1163. mii_sendbit (struct net_device *dev, u32 data)
  1164. {
  1165. struct netdev_private *np = netdev_priv(dev);
  1166. void __iomem *ioaddr = np->ioaddr;
  1167. data = ((data) ? MII_DATA1 : 0) | (dr8(PhyCtrl) & 0xf8) | MII_WRITE;
  1168. dw8(PhyCtrl, data);
  1169. mii_delay ();
  1170. dw8(PhyCtrl, data | MII_CLK);
  1171. mii_delay ();
  1172. }
  1173. static int
  1174. mii_getbit (struct net_device *dev)
  1175. {
  1176. struct netdev_private *np = netdev_priv(dev);
  1177. void __iomem *ioaddr = np->ioaddr;
  1178. u8 data;
  1179. data = (dr8(PhyCtrl) & 0xf8) | MII_READ;
  1180. dw8(PhyCtrl, data);
  1181. mii_delay ();
  1182. dw8(PhyCtrl, data | MII_CLK);
  1183. mii_delay ();
  1184. return (dr8(PhyCtrl) >> 1) & 1;
  1185. }
  1186. static void
  1187. mii_send_bits (struct net_device *dev, u32 data, int len)
  1188. {
  1189. int i;
  1190. for (i = len - 1; i >= 0; i--) {
  1191. mii_sendbit (dev, data & (1 << i));
  1192. }
  1193. }
  1194. static int
  1195. mii_read (struct net_device *dev, int phy_addr, int reg_num)
  1196. {
  1197. u32 cmd;
  1198. int i;
  1199. u32 retval = 0;
  1200. /* Preamble */
  1201. mii_send_bits (dev, 0xffffffff, 32);
  1202. /* ST(2), OP(2), ADDR(5), REG#(5), TA(2), Data(16) total 32 bits */
  1203. /* ST,OP = 0110'b for read operation */
  1204. cmd = (0x06 << 10 | phy_addr << 5 | reg_num);
  1205. mii_send_bits (dev, cmd, 14);
  1206. /* Turnaround */
  1207. if (mii_getbit (dev))
  1208. goto err_out;
  1209. /* Read data */
  1210. for (i = 0; i < 16; i++) {
  1211. retval |= mii_getbit (dev);
  1212. retval <<= 1;
  1213. }
  1214. /* End cycle */
  1215. mii_getbit (dev);
  1216. return (retval >> 1) & 0xffff;
  1217. err_out:
  1218. return 0;
  1219. }
  1220. static int
  1221. mii_write (struct net_device *dev, int phy_addr, int reg_num, u16 data)
  1222. {
  1223. u32 cmd;
  1224. /* Preamble */
  1225. mii_send_bits (dev, 0xffffffff, 32);
  1226. /* ST(2), OP(2), ADDR(5), REG#(5), TA(2), Data(16) total 32 bits */
  1227. /* ST,OP,AAAAA,RRRRR,TA = 0101xxxxxxxxxx10'b = 0x5002 for write */
  1228. cmd = (0x5002 << 16) | (phy_addr << 23) | (reg_num << 18) | data;
  1229. mii_send_bits (dev, cmd, 32);
  1230. /* End cycle */
  1231. mii_getbit (dev);
  1232. return 0;
  1233. }
  1234. static int
  1235. mii_wait_link (struct net_device *dev, int wait)
  1236. {
  1237. __u16 bmsr;
  1238. int phy_addr;
  1239. struct netdev_private *np;
  1240. np = netdev_priv(dev);
  1241. phy_addr = np->phy_addr;
  1242. do {
  1243. bmsr = mii_read (dev, phy_addr, MII_BMSR);
  1244. if (bmsr & BMSR_LSTATUS)
  1245. return 0;
  1246. mdelay (1);
  1247. } while (--wait > 0);
  1248. return -1;
  1249. }
  1250. static int
  1251. mii_get_media (struct net_device *dev)
  1252. {
  1253. __u16 negotiate;
  1254. __u16 bmsr;
  1255. __u16 mscr;
  1256. __u16 mssr;
  1257. int phy_addr;
  1258. struct netdev_private *np;
  1259. np = netdev_priv(dev);
  1260. phy_addr = np->phy_addr;
  1261. bmsr = mii_read (dev, phy_addr, MII_BMSR);
  1262. if (np->an_enable) {
  1263. if (!(bmsr & BMSR_ANEGCOMPLETE)) {
  1264. /* Auto-Negotiation not completed */
  1265. return -1;
  1266. }
  1267. negotiate = mii_read (dev, phy_addr, MII_ADVERTISE) &
  1268. mii_read (dev, phy_addr, MII_LPA);
  1269. mscr = mii_read (dev, phy_addr, MII_CTRL1000);
  1270. mssr = mii_read (dev, phy_addr, MII_STAT1000);
  1271. if (mscr & ADVERTISE_1000FULL && mssr & LPA_1000FULL) {
  1272. np->speed = 1000;
  1273. np->full_duplex = 1;
  1274. printk (KERN_INFO "Auto 1000 Mbps, Full duplex\n");
  1275. } else if (mscr & ADVERTISE_1000HALF && mssr & LPA_1000HALF) {
  1276. np->speed = 1000;
  1277. np->full_duplex = 0;
  1278. printk (KERN_INFO "Auto 1000 Mbps, Half duplex\n");
  1279. } else if (negotiate & ADVERTISE_100FULL) {
  1280. np->speed = 100;
  1281. np->full_duplex = 1;
  1282. printk (KERN_INFO "Auto 100 Mbps, Full duplex\n");
  1283. } else if (negotiate & ADVERTISE_100HALF) {
  1284. np->speed = 100;
  1285. np->full_duplex = 0;
  1286. printk (KERN_INFO "Auto 100 Mbps, Half duplex\n");
  1287. } else if (negotiate & ADVERTISE_10FULL) {
  1288. np->speed = 10;
  1289. np->full_duplex = 1;
  1290. printk (KERN_INFO "Auto 10 Mbps, Full duplex\n");
  1291. } else if (negotiate & ADVERTISE_10HALF) {
  1292. np->speed = 10;
  1293. np->full_duplex = 0;
  1294. printk (KERN_INFO "Auto 10 Mbps, Half duplex\n");
  1295. }
  1296. if (negotiate & ADVERTISE_PAUSE_CAP) {
  1297. np->tx_flow &= 1;
  1298. np->rx_flow &= 1;
  1299. } else if (negotiate & ADVERTISE_PAUSE_ASYM) {
  1300. np->tx_flow = 0;
  1301. np->rx_flow &= 1;
  1302. }
  1303. /* else tx_flow, rx_flow = user select */
  1304. } else {
  1305. __u16 bmcr = mii_read (dev, phy_addr, MII_BMCR);
  1306. switch (bmcr & (BMCR_SPEED100 | BMCR_SPEED1000)) {
  1307. case BMCR_SPEED1000:
  1308. printk (KERN_INFO "Operating at 1000 Mbps, ");
  1309. break;
  1310. case BMCR_SPEED100:
  1311. printk (KERN_INFO "Operating at 100 Mbps, ");
  1312. break;
  1313. case 0:
  1314. printk (KERN_INFO "Operating at 10 Mbps, ");
  1315. }
  1316. if (bmcr & BMCR_FULLDPLX) {
  1317. printk (KERN_CONT "Full duplex\n");
  1318. } else {
  1319. printk (KERN_CONT "Half duplex\n");
  1320. }
  1321. }
  1322. if (np->tx_flow)
  1323. printk(KERN_INFO "Enable Tx Flow Control\n");
  1324. else
  1325. printk(KERN_INFO "Disable Tx Flow Control\n");
  1326. if (np->rx_flow)
  1327. printk(KERN_INFO "Enable Rx Flow Control\n");
  1328. else
  1329. printk(KERN_INFO "Disable Rx Flow Control\n");
  1330. return 0;
  1331. }
  1332. static int
  1333. mii_set_media (struct net_device *dev)
  1334. {
  1335. __u16 pscr;
  1336. __u16 bmcr;
  1337. __u16 bmsr;
  1338. __u16 anar;
  1339. int phy_addr;
  1340. struct netdev_private *np;
  1341. np = netdev_priv(dev);
  1342. phy_addr = np->phy_addr;
  1343. /* Does user set speed? */
  1344. if (np->an_enable) {
  1345. /* Advertise capabilities */
  1346. bmsr = mii_read (dev, phy_addr, MII_BMSR);
  1347. anar = mii_read (dev, phy_addr, MII_ADVERTISE) &
  1348. ~(ADVERTISE_100FULL | ADVERTISE_10FULL |
  1349. ADVERTISE_100HALF | ADVERTISE_10HALF |
  1350. ADVERTISE_100BASE4);
  1351. if (bmsr & BMSR_100FULL)
  1352. anar |= ADVERTISE_100FULL;
  1353. if (bmsr & BMSR_100HALF)
  1354. anar |= ADVERTISE_100HALF;
  1355. if (bmsr & BMSR_100BASE4)
  1356. anar |= ADVERTISE_100BASE4;
  1357. if (bmsr & BMSR_10FULL)
  1358. anar |= ADVERTISE_10FULL;
  1359. if (bmsr & BMSR_10HALF)
  1360. anar |= ADVERTISE_10HALF;
  1361. anar |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  1362. mii_write (dev, phy_addr, MII_ADVERTISE, anar);
  1363. /* Enable Auto crossover */
  1364. pscr = mii_read (dev, phy_addr, MII_PHY_SCR);
  1365. pscr |= 3 << 5; /* 11'b */
  1366. mii_write (dev, phy_addr, MII_PHY_SCR, pscr);
  1367. /* Soft reset PHY */
  1368. mii_write (dev, phy_addr, MII_BMCR, BMCR_RESET);
  1369. bmcr = BMCR_ANENABLE | BMCR_ANRESTART | BMCR_RESET;
  1370. mii_write (dev, phy_addr, MII_BMCR, bmcr);
  1371. mdelay(1);
  1372. } else {
  1373. /* Force speed setting */
  1374. /* 1) Disable Auto crossover */
  1375. pscr = mii_read (dev, phy_addr, MII_PHY_SCR);
  1376. pscr &= ~(3 << 5);
  1377. mii_write (dev, phy_addr, MII_PHY_SCR, pscr);
  1378. /* 2) PHY Reset */
  1379. bmcr = mii_read (dev, phy_addr, MII_BMCR);
  1380. bmcr |= BMCR_RESET;
  1381. mii_write (dev, phy_addr, MII_BMCR, bmcr);
  1382. /* 3) Power Down */
  1383. bmcr = 0x1940; /* must be 0x1940 */
  1384. mii_write (dev, phy_addr, MII_BMCR, bmcr);
  1385. mdelay (100); /* wait a certain time */
  1386. /* 4) Advertise nothing */
  1387. mii_write (dev, phy_addr, MII_ADVERTISE, 0);
  1388. /* 5) Set media and Power Up */
  1389. bmcr = BMCR_PDOWN;
  1390. if (np->speed == 100) {
  1391. bmcr |= BMCR_SPEED100;
  1392. printk (KERN_INFO "Manual 100 Mbps, ");
  1393. } else if (np->speed == 10) {
  1394. printk (KERN_INFO "Manual 10 Mbps, ");
  1395. }
  1396. if (np->full_duplex) {
  1397. bmcr |= BMCR_FULLDPLX;
  1398. printk (KERN_CONT "Full duplex\n");
  1399. } else {
  1400. printk (KERN_CONT "Half duplex\n");
  1401. }
  1402. #if 0
  1403. /* Set 1000BaseT Master/Slave setting */
  1404. mscr = mii_read (dev, phy_addr, MII_CTRL1000);
  1405. mscr |= MII_MSCR_CFG_ENABLE;
  1406. mscr &= ~MII_MSCR_CFG_VALUE = 0;
  1407. #endif
  1408. mii_write (dev, phy_addr, MII_BMCR, bmcr);
  1409. mdelay(10);
  1410. }
  1411. return 0;
  1412. }
  1413. static int
  1414. mii_get_media_pcs (struct net_device *dev)
  1415. {
  1416. __u16 negotiate;
  1417. __u16 bmsr;
  1418. int phy_addr;
  1419. struct netdev_private *np;
  1420. np = netdev_priv(dev);
  1421. phy_addr = np->phy_addr;
  1422. bmsr = mii_read (dev, phy_addr, PCS_BMSR);
  1423. if (np->an_enable) {
  1424. if (!(bmsr & BMSR_ANEGCOMPLETE)) {
  1425. /* Auto-Negotiation not completed */
  1426. return -1;
  1427. }
  1428. negotiate = mii_read (dev, phy_addr, PCS_ANAR) &
  1429. mii_read (dev, phy_addr, PCS_ANLPAR);
  1430. np->speed = 1000;
  1431. if (negotiate & PCS_ANAR_FULL_DUPLEX) {
  1432. printk (KERN_INFO "Auto 1000 Mbps, Full duplex\n");
  1433. np->full_duplex = 1;
  1434. } else {
  1435. printk (KERN_INFO "Auto 1000 Mbps, half duplex\n");
  1436. np->full_duplex = 0;
  1437. }
  1438. if (negotiate & PCS_ANAR_PAUSE) {
  1439. np->tx_flow &= 1;
  1440. np->rx_flow &= 1;
  1441. } else if (negotiate & PCS_ANAR_ASYMMETRIC) {
  1442. np->tx_flow = 0;
  1443. np->rx_flow &= 1;
  1444. }
  1445. /* else tx_flow, rx_flow = user select */
  1446. } else {
  1447. __u16 bmcr = mii_read (dev, phy_addr, PCS_BMCR);
  1448. printk (KERN_INFO "Operating at 1000 Mbps, ");
  1449. if (bmcr & BMCR_FULLDPLX) {
  1450. printk (KERN_CONT "Full duplex\n");
  1451. } else {
  1452. printk (KERN_CONT "Half duplex\n");
  1453. }
  1454. }
  1455. if (np->tx_flow)
  1456. printk(KERN_INFO "Enable Tx Flow Control\n");
  1457. else
  1458. printk(KERN_INFO "Disable Tx Flow Control\n");
  1459. if (np->rx_flow)
  1460. printk(KERN_INFO "Enable Rx Flow Control\n");
  1461. else
  1462. printk(KERN_INFO "Disable Rx Flow Control\n");
  1463. return 0;
  1464. }
  1465. static int
  1466. mii_set_media_pcs (struct net_device *dev)
  1467. {
  1468. __u16 bmcr;
  1469. __u16 esr;
  1470. __u16 anar;
  1471. int phy_addr;
  1472. struct netdev_private *np;
  1473. np = netdev_priv(dev);
  1474. phy_addr = np->phy_addr;
  1475. /* Auto-Negotiation? */
  1476. if (np->an_enable) {
  1477. /* Advertise capabilities */
  1478. esr = mii_read (dev, phy_addr, PCS_ESR);
  1479. anar = mii_read (dev, phy_addr, MII_ADVERTISE) &
  1480. ~PCS_ANAR_HALF_DUPLEX &
  1481. ~PCS_ANAR_FULL_DUPLEX;
  1482. if (esr & (MII_ESR_1000BT_HD | MII_ESR_1000BX_HD))
  1483. anar |= PCS_ANAR_HALF_DUPLEX;
  1484. if (esr & (MII_ESR_1000BT_FD | MII_ESR_1000BX_FD))
  1485. anar |= PCS_ANAR_FULL_DUPLEX;
  1486. anar |= PCS_ANAR_PAUSE | PCS_ANAR_ASYMMETRIC;
  1487. mii_write (dev, phy_addr, MII_ADVERTISE, anar);
  1488. /* Soft reset PHY */
  1489. mii_write (dev, phy_addr, MII_BMCR, BMCR_RESET);
  1490. bmcr = BMCR_ANENABLE | BMCR_ANRESTART | BMCR_RESET;
  1491. mii_write (dev, phy_addr, MII_BMCR, bmcr);
  1492. mdelay(1);
  1493. } else {
  1494. /* Force speed setting */
  1495. /* PHY Reset */
  1496. bmcr = BMCR_RESET;
  1497. mii_write (dev, phy_addr, MII_BMCR, bmcr);
  1498. mdelay(10);
  1499. if (np->full_duplex) {
  1500. bmcr = BMCR_FULLDPLX;
  1501. printk (KERN_INFO "Manual full duplex\n");
  1502. } else {
  1503. bmcr = 0;
  1504. printk (KERN_INFO "Manual half duplex\n");
  1505. }
  1506. mii_write (dev, phy_addr, MII_BMCR, bmcr);
  1507. mdelay(10);
  1508. /* Advertise nothing */
  1509. mii_write (dev, phy_addr, MII_ADVERTISE, 0);
  1510. }
  1511. return 0;
  1512. }
  1513. static int
  1514. rio_close (struct net_device *dev)
  1515. {
  1516. struct netdev_private *np = netdev_priv(dev);
  1517. void __iomem *ioaddr = np->ioaddr;
  1518. struct pci_dev *pdev = np->pdev;
  1519. struct sk_buff *skb;
  1520. int i;
  1521. netif_stop_queue (dev);
  1522. /* Disable interrupts */
  1523. dw16(IntEnable, 0);
  1524. /* Stop Tx and Rx logics */
  1525. dw32(MACCtrl, TxDisable | RxDisable | StatsDisable);
  1526. free_irq(pdev->irq, dev);
  1527. del_timer_sync (&np->timer);
  1528. /* Free all the skbuffs in the queue. */
  1529. for (i = 0; i < RX_RING_SIZE; i++) {
  1530. skb = np->rx_skbuff[i];
  1531. if (skb) {
  1532. pci_unmap_single(pdev, desc_to_dma(&np->rx_ring[i]),
  1533. skb->len, PCI_DMA_FROMDEVICE);
  1534. dev_kfree_skb (skb);
  1535. np->rx_skbuff[i] = NULL;
  1536. }
  1537. np->rx_ring[i].status = 0;
  1538. np->rx_ring[i].fraginfo = 0;
  1539. }
  1540. for (i = 0; i < TX_RING_SIZE; i++) {
  1541. skb = np->tx_skbuff[i];
  1542. if (skb) {
  1543. pci_unmap_single(pdev, desc_to_dma(&np->tx_ring[i]),
  1544. skb->len, PCI_DMA_TODEVICE);
  1545. dev_kfree_skb (skb);
  1546. np->tx_skbuff[i] = NULL;
  1547. }
  1548. }
  1549. return 0;
  1550. }
  1551. static void
  1552. rio_remove1 (struct pci_dev *pdev)
  1553. {
  1554. struct net_device *dev = pci_get_drvdata (pdev);
  1555. if (dev) {
  1556. struct netdev_private *np = netdev_priv(dev);
  1557. unregister_netdev (dev);
  1558. pci_free_consistent (pdev, RX_TOTAL_SIZE, np->rx_ring,
  1559. np->rx_ring_dma);
  1560. pci_free_consistent (pdev, TX_TOTAL_SIZE, np->tx_ring,
  1561. np->tx_ring_dma);
  1562. #ifdef MEM_MAPPING
  1563. pci_iounmap(pdev, np->ioaddr);
  1564. #endif
  1565. pci_iounmap(pdev, np->eeprom_addr);
  1566. free_netdev (dev);
  1567. pci_release_regions (pdev);
  1568. pci_disable_device (pdev);
  1569. }
  1570. }
  1571. static struct pci_driver rio_driver = {
  1572. .name = "dl2k",
  1573. .id_table = rio_pci_tbl,
  1574. .probe = rio_probe1,
  1575. .remove = rio_remove1,
  1576. };
  1577. module_pci_driver(rio_driver);
  1578. /*
  1579. Compile command:
  1580. gcc -D__KERNEL__ -DMODULE -I/usr/src/linux/include -Wall -Wstrict-prototypes -O2 -c dl2k.c
  1581. Read Documentation/networking/dl2k.txt for details.
  1582. */