dl2k.c 48 KB

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