PageRenderTime 50ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/net/defxx.c

https://github.com/ab3416/linux-2.6
C | 1649 lines | 664 code | 224 blank | 761 comment | 85 complexity | b04de96eee3e4727f21c049dff707e21 MD5 | raw file
  1. /*
  2. * File Name:
  3. * defxx.c
  4. *
  5. * Copyright Information:
  6. * Copyright Digital Equipment Corporation 1996.
  7. *
  8. * This software may be used and distributed according to the terms of
  9. * the GNU General Public License, incorporated herein by reference.
  10. *
  11. * Abstract:
  12. * A Linux device driver supporting the Digital Equipment Corporation
  13. * FDDI TURBOchannel, EISA and PCI controller families. Supported
  14. * adapters include:
  15. *
  16. * DEC FDDIcontroller/TURBOchannel (DEFTA)
  17. * DEC FDDIcontroller/EISA (DEFEA)
  18. * DEC FDDIcontroller/PCI (DEFPA)
  19. *
  20. * The original author:
  21. * LVS Lawrence V. Stefani <lstefani@yahoo.com>
  22. *
  23. * Maintainers:
  24. * macro Maciej W. Rozycki <macro@linux-mips.org>
  25. *
  26. * Credits:
  27. * I'd like to thank Patricia Cross for helping me get started with
  28. * Linux, David Davies for a lot of help upgrading and configuring
  29. * my development system and for answering many OS and driver
  30. * development questions, and Alan Cox for recommendations and
  31. * integration help on getting FDDI support into Linux. LVS
  32. *
  33. * Driver Architecture:
  34. * The driver architecture is largely based on previous driver work
  35. * for other operating systems. The upper edge interface and
  36. * functions were largely taken from existing Linux device drivers
  37. * such as David Davies' DE4X5.C driver and Donald Becker's TULIP.C
  38. * driver.
  39. *
  40. * Adapter Probe -
  41. * The driver scans for supported EISA adapters by reading the
  42. * SLOT ID register for each EISA slot and making a match
  43. * against the expected value.
  44. *
  45. * Bus-Specific Initialization -
  46. * This driver currently supports both EISA and PCI controller
  47. * families. While the custom DMA chip and FDDI logic is similar
  48. * or identical, the bus logic is very different. After
  49. * initialization, the only bus-specific differences is in how the
  50. * driver enables and disables interrupts. Other than that, the
  51. * run-time critical code behaves the same on both families.
  52. * It's important to note that both adapter families are configured
  53. * to I/O map, rather than memory map, the adapter registers.
  54. *
  55. * Driver Open/Close -
  56. * In the driver open routine, the driver ISR (interrupt service
  57. * routine) is registered and the adapter is brought to an
  58. * operational state. In the driver close routine, the opposite
  59. * occurs; the driver ISR is deregistered and the adapter is
  60. * brought to a safe, but closed state. Users may use consecutive
  61. * commands to bring the adapter up and down as in the following
  62. * example:
  63. * ifconfig fddi0 up
  64. * ifconfig fddi0 down
  65. * ifconfig fddi0 up
  66. *
  67. * Driver Shutdown -
  68. * Apparently, there is no shutdown or halt routine support under
  69. * Linux. This routine would be called during "reboot" or
  70. * "shutdown" to allow the driver to place the adapter in a safe
  71. * state before a warm reboot occurs. To be really safe, the user
  72. * should close the adapter before shutdown (eg. ifconfig fddi0 down)
  73. * to ensure that the adapter DMA engine is taken off-line. However,
  74. * the current driver code anticipates this problem and always issues
  75. * a soft reset of the adapter at the beginning of driver initialization.
  76. * A future driver enhancement in this area may occur in 2.1.X where
  77. * Alan indicated that a shutdown handler may be implemented.
  78. *
  79. * Interrupt Service Routine -
  80. * The driver supports shared interrupts, so the ISR is registered for
  81. * each board with the appropriate flag and the pointer to that board's
  82. * device structure. This provides the context during interrupt
  83. * processing to support shared interrupts and multiple boards.
  84. *
  85. * Interrupt enabling/disabling can occur at many levels. At the host
  86. * end, you can disable system interrupts, or disable interrupts at the
  87. * PIC (on Intel systems). Across the bus, both EISA and PCI adapters
  88. * have a bus-logic chip interrupt enable/disable as well as a DMA
  89. * controller interrupt enable/disable.
  90. *
  91. * The driver currently enables and disables adapter interrupts at the
  92. * bus-logic chip and assumes that Linux will take care of clearing or
  93. * acknowledging any host-based interrupt chips.
  94. *
  95. * Control Functions -
  96. * Control functions are those used to support functions such as adding
  97. * or deleting multicast addresses, enabling or disabling packet
  98. * reception filters, or other custom/proprietary commands. Presently,
  99. * the driver supports the "get statistics", "set multicast list", and
  100. * "set mac address" functions defined by Linux. A list of possible
  101. * enhancements include:
  102. *
  103. * - Custom ioctl interface for executing port interface commands
  104. * - Custom ioctl interface for adding unicast addresses to
  105. * adapter CAM (to support bridge functions).
  106. * - Custom ioctl interface for supporting firmware upgrades.
  107. *
  108. * Hardware (port interface) Support Routines -
  109. * The driver function names that start with "dfx_hw_" represent
  110. * low-level port interface routines that are called frequently. They
  111. * include issuing a DMA or port control command to the adapter,
  112. * resetting the adapter, or reading the adapter state. Since the
  113. * driver initialization and run-time code must make calls into the
  114. * port interface, these routines were written to be as generic and
  115. * usable as possible.
  116. *
  117. * Receive Path -
  118. * The adapter DMA engine supports a 256 entry receive descriptor block
  119. * of which up to 255 entries can be used at any given time. The
  120. * architecture is a standard producer, consumer, completion model in
  121. * which the driver "produces" receive buffers to the adapter, the
  122. * adapter "consumes" the receive buffers by DMAing incoming packet data,
  123. * and the driver "completes" the receive buffers by servicing the
  124. * incoming packet, then "produces" a new buffer and starts the cycle
  125. * again. Receive buffers can be fragmented in up to 16 fragments
  126. * (descriptor entries). For simplicity, this driver posts
  127. * single-fragment receive buffers of 4608 bytes, then allocates a
  128. * sk_buff, copies the data, then reposts the buffer. To reduce CPU
  129. * utilization, a better approach would be to pass up the receive
  130. * buffer (no extra copy) then allocate and post a replacement buffer.
  131. * This is a performance enhancement that should be looked into at
  132. * some point.
  133. *
  134. * Transmit Path -
  135. * Like the receive path, the adapter DMA engine supports a 256 entry
  136. * transmit descriptor block of which up to 255 entries can be used at
  137. * any given time. Transmit buffers can be fragmented in up to 255
  138. * fragments (descriptor entries). This driver always posts one
  139. * fragment per transmit packet request.
  140. *
  141. * The fragment contains the entire packet from FC to end of data.
  142. * Before posting the buffer to the adapter, the driver sets a three-byte
  143. * packet request header (PRH) which is required by the Motorola MAC chip
  144. * used on the adapters. The PRH tells the MAC the type of token to
  145. * receive/send, whether or not to generate and append the CRC, whether
  146. * synchronous or asynchronous framing is used, etc. Since the PRH
  147. * definition is not necessarily consistent across all FDDI chipsets,
  148. * the driver, rather than the common FDDI packet handler routines,
  149. * sets these bytes.
  150. *
  151. * To reduce the amount of descriptor fetches needed per transmit request,
  152. * the driver takes advantage of the fact that there are at least three
  153. * bytes available before the skb->data field on the outgoing transmit
  154. * request. This is guaranteed by having fddi_setup() in net_init.c set
  155. * dev->hard_header_len to 24 bytes. 21 bytes accounts for the largest
  156. * header in an 802.2 SNAP frame. The other 3 bytes are the extra "pad"
  157. * bytes which we'll use to store the PRH.
  158. *
  159. * There's a subtle advantage to adding these pad bytes to the
  160. * hard_header_len, it ensures that the data portion of the packet for
  161. * an 802.2 SNAP frame is longword aligned. Other FDDI driver
  162. * implementations may not need the extra padding and can start copying
  163. * or DMAing directly from the FC byte which starts at skb->data. Should
  164. * another driver implementation need ADDITIONAL padding, the net_init.c
  165. * module should be updated and dev->hard_header_len should be increased.
  166. * NOTE: To maintain the alignment on the data portion of the packet,
  167. * dev->hard_header_len should always be evenly divisible by 4 and at
  168. * least 24 bytes in size.
  169. *
  170. * Modification History:
  171. * Date Name Description
  172. * 16-Aug-96 LVS Created.
  173. * 20-Aug-96 LVS Updated dfx_probe so that version information
  174. * string is only displayed if 1 or more cards are
  175. * found. Changed dfx_rcv_queue_process to copy
  176. * 3 NULL bytes before FC to ensure that data is
  177. * longword aligned in receive buffer.
  178. * 09-Sep-96 LVS Updated dfx_ctl_set_multicast_list to enable
  179. * LLC group promiscuous mode if multicast list
  180. * is too large. LLC individual/group promiscuous
  181. * mode is now disabled if IFF_PROMISC flag not set.
  182. * dfx_xmt_queue_pkt no longer checks for NULL skb
  183. * on Alan Cox recommendation. Added node address
  184. * override support.
  185. * 12-Sep-96 LVS Reset current address to factory address during
  186. * device open. Updated transmit path to post a
  187. * single fragment which includes PRH->end of data.
  188. * Mar 2000 AC Did various cleanups for 2.3.x
  189. * Jun 2000 jgarzik PCI and resource alloc cleanups
  190. * Jul 2000 tjeerd Much cleanup and some bug fixes
  191. * Sep 2000 tjeerd Fix leak on unload, cosmetic code cleanup
  192. * Feb 2001 Skb allocation fixes
  193. * Feb 2001 davej PCI enable cleanups.
  194. * 04 Aug 2003 macro Converted to the DMA API.
  195. * 14 Aug 2004 macro Fix device names reported.
  196. * 14 Jun 2005 macro Use irqreturn_t.
  197. * 23 Oct 2006 macro Big-endian host support.
  198. * 14 Dec 2006 macro TURBOchannel support.
  199. */
  200. /* Include files */
  201. #include <linux/bitops.h>
  202. #include <linux/compiler.h>
  203. #include <linux/delay.h>
  204. #include <linux/dma-mapping.h>
  205. #include <linux/eisa.h>
  206. #include <linux/errno.h>
  207. #include <linux/fddidevice.h>
  208. #include <linux/init.h>
  209. #include <linux/interrupt.h>
  210. #include <linux/ioport.h>
  211. #include <linux/kernel.h>
  212. #include <linux/module.h>
  213. #include <linux/netdevice.h>
  214. #include <linux/pci.h>
  215. #include <linux/skbuff.h>
  216. #include <linux/slab.h>
  217. #include <linux/string.h>
  218. #include <linux/tc.h>
  219. #include <asm/byteorder.h>
  220. #include <asm/io.h>
  221. #include "defxx.h"
  222. /* Version information string should be updated prior to each new release! */
  223. #define DRV_NAME "defxx"
  224. #define DRV_VERSION "v1.10"
  225. #define DRV_RELDATE "2006/12/14"
  226. static char version[] __devinitdata =
  227. DRV_NAME ": " DRV_VERSION " " DRV_RELDATE
  228. " Lawrence V. Stefani and others\n";
  229. #define DYNAMIC_BUFFERS 1
  230. #define SKBUFF_RX_COPYBREAK 200
  231. /*
  232. * NEW_SKB_SIZE = PI_RCV_DATA_K_SIZE_MAX+128 to allow 128 byte
  233. * alignment for compatibility with old EISA boards.
  234. */
  235. #define NEW_SKB_SIZE (PI_RCV_DATA_K_SIZE_MAX+128)
  236. #ifdef CONFIG_PCI
  237. #define DFX_BUS_PCI(dev) (dev->bus == &pci_bus_type)
  238. #else
  239. #define DFX_BUS_PCI(dev) 0
  240. #endif
  241. #ifdef CONFIG_EISA
  242. #define DFX_BUS_EISA(dev) (dev->bus == &eisa_bus_type)
  243. #else
  244. #define DFX_BUS_EISA(dev) 0
  245. #endif
  246. #ifdef CONFIG_TC
  247. #define DFX_BUS_TC(dev) (dev->bus == &tc_bus_type)
  248. #else
  249. #define DFX_BUS_TC(dev) 0
  250. #endif
  251. #ifdef CONFIG_DEFXX_MMIO
  252. #define DFX_MMIO 1
  253. #else
  254. #define DFX_MMIO 0
  255. #endif
  256. /* Define module-wide (static) routines */
  257. static void dfx_bus_init(struct net_device *dev);
  258. static void dfx_bus_uninit(struct net_device *dev);
  259. static void dfx_bus_config_check(DFX_board_t *bp);
  260. static int dfx_driver_init(struct net_device *dev,
  261. const char *print_name,
  262. resource_size_t bar_start);
  263. static int dfx_adap_init(DFX_board_t *bp, int get_buffers);
  264. static int dfx_open(struct net_device *dev);
  265. static int dfx_close(struct net_device *dev);
  266. static void dfx_int_pr_halt_id(DFX_board_t *bp);
  267. static void dfx_int_type_0_process(DFX_board_t *bp);
  268. static void dfx_int_common(struct net_device *dev);
  269. static irqreturn_t dfx_interrupt(int irq, void *dev_id);
  270. static struct net_device_stats *dfx_ctl_get_stats(struct net_device *dev);
  271. static void dfx_ctl_set_multicast_list(struct net_device *dev);
  272. static int dfx_ctl_set_mac_address(struct net_device *dev, void *addr);
  273. static int dfx_ctl_update_cam(DFX_board_t *bp);
  274. static int dfx_ctl_update_filters(DFX_board_t *bp);
  275. static int dfx_hw_dma_cmd_req(DFX_board_t *bp);
  276. static int dfx_hw_port_ctrl_req(DFX_board_t *bp, PI_UINT32 command, PI_UINT32 data_a, PI_UINT32 data_b, PI_UINT32 *host_data);
  277. static void dfx_hw_adap_reset(DFX_board_t *bp, PI_UINT32 type);
  278. static int dfx_hw_adap_state_rd(DFX_board_t *bp);
  279. static int dfx_hw_dma_uninit(DFX_board_t *bp, PI_UINT32 type);
  280. static int dfx_rcv_init(DFX_board_t *bp, int get_buffers);
  281. static void dfx_rcv_queue_process(DFX_board_t *bp);
  282. static void dfx_rcv_flush(DFX_board_t *bp);
  283. static netdev_tx_t dfx_xmt_queue_pkt(struct sk_buff *skb,
  284. struct net_device *dev);
  285. static int dfx_xmt_done(DFX_board_t *bp);
  286. static void dfx_xmt_flush(DFX_board_t *bp);
  287. /* Define module-wide (static) variables */
  288. static struct pci_driver dfx_pci_driver;
  289. static struct eisa_driver dfx_eisa_driver;
  290. static struct tc_driver dfx_tc_driver;
  291. /*
  292. * =======================
  293. * = dfx_port_write_long =
  294. * = dfx_port_read_long =
  295. * =======================
  296. *
  297. * Overview:
  298. * Routines for reading and writing values from/to adapter
  299. *
  300. * Returns:
  301. * None
  302. *
  303. * Arguments:
  304. * bp - pointer to board information
  305. * offset - register offset from base I/O address
  306. * data - for dfx_port_write_long, this is a value to write;
  307. * for dfx_port_read_long, this is a pointer to store
  308. * the read value
  309. *
  310. * Functional Description:
  311. * These routines perform the correct operation to read or write
  312. * the adapter register.
  313. *
  314. * EISA port block base addresses are based on the slot number in which the
  315. * controller is installed. For example, if the EISA controller is installed
  316. * in slot 4, the port block base address is 0x4000. If the controller is
  317. * installed in slot 2, the port block base address is 0x2000, and so on.
  318. * This port block can be used to access PDQ, ESIC, and DEFEA on-board
  319. * registers using the register offsets defined in DEFXX.H.
  320. *
  321. * PCI port block base addresses are assigned by the PCI BIOS or system
  322. * firmware. There is one 128 byte port block which can be accessed. It
  323. * allows for I/O mapping of both PDQ and PFI registers using the register
  324. * offsets defined in DEFXX.H.
  325. *
  326. * Return Codes:
  327. * None
  328. *
  329. * Assumptions:
  330. * bp->base is a valid base I/O address for this adapter.
  331. * offset is a valid register offset for this adapter.
  332. *
  333. * Side Effects:
  334. * Rather than produce macros for these functions, these routines
  335. * are defined using "inline" to ensure that the compiler will
  336. * generate inline code and not waste a procedure call and return.
  337. * This provides all the benefits of macros, but with the
  338. * advantage of strict data type checking.
  339. */
  340. static inline void dfx_writel(DFX_board_t *bp, int offset, u32 data)
  341. {
  342. writel(data, bp->base.mem + offset);
  343. mb();
  344. }
  345. static inline void dfx_outl(DFX_board_t *bp, int offset, u32 data)
  346. {
  347. outl(data, bp->base.port + offset);
  348. }
  349. static void dfx_port_write_long(DFX_board_t *bp, int offset, u32 data)
  350. {
  351. struct device __maybe_unused *bdev = bp->bus_dev;
  352. int dfx_bus_tc = DFX_BUS_TC(bdev);
  353. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  354. if (dfx_use_mmio)
  355. dfx_writel(bp, offset, data);
  356. else
  357. dfx_outl(bp, offset, data);
  358. }
  359. static inline void dfx_readl(DFX_board_t *bp, int offset, u32 *data)
  360. {
  361. mb();
  362. *data = readl(bp->base.mem + offset);
  363. }
  364. static inline void dfx_inl(DFX_board_t *bp, int offset, u32 *data)
  365. {
  366. *data = inl(bp->base.port + offset);
  367. }
  368. static void dfx_port_read_long(DFX_board_t *bp, int offset, u32 *data)
  369. {
  370. struct device __maybe_unused *bdev = bp->bus_dev;
  371. int dfx_bus_tc = DFX_BUS_TC(bdev);
  372. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  373. if (dfx_use_mmio)
  374. dfx_readl(bp, offset, data);
  375. else
  376. dfx_inl(bp, offset, data);
  377. }
  378. /*
  379. * ================
  380. * = dfx_get_bars =
  381. * ================
  382. *
  383. * Overview:
  384. * Retrieves the address range used to access control and status
  385. * registers.
  386. *
  387. * Returns:
  388. * None
  389. *
  390. * Arguments:
  391. * bdev - pointer to device information
  392. * bar_start - pointer to store the start address
  393. * bar_len - pointer to store the length of the area
  394. *
  395. * Assumptions:
  396. * I am sure there are some.
  397. *
  398. * Side Effects:
  399. * None
  400. */
  401. static void dfx_get_bars(struct device *bdev,
  402. resource_size_t *bar_start, resource_size_t *bar_len)
  403. {
  404. int dfx_bus_pci = DFX_BUS_PCI(bdev);
  405. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  406. int dfx_bus_tc = DFX_BUS_TC(bdev);
  407. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  408. if (dfx_bus_pci) {
  409. int num = dfx_use_mmio ? 0 : 1;
  410. *bar_start = pci_resource_start(to_pci_dev(bdev), num);
  411. *bar_len = pci_resource_len(to_pci_dev(bdev), num);
  412. }
  413. if (dfx_bus_eisa) {
  414. unsigned long base_addr = to_eisa_device(bdev)->base_addr;
  415. resource_size_t bar;
  416. if (dfx_use_mmio) {
  417. bar = inb(base_addr + PI_ESIC_K_MEM_ADD_CMP_2);
  418. bar <<= 8;
  419. bar |= inb(base_addr + PI_ESIC_K_MEM_ADD_CMP_1);
  420. bar <<= 8;
  421. bar |= inb(base_addr + PI_ESIC_K_MEM_ADD_CMP_0);
  422. bar <<= 16;
  423. *bar_start = bar;
  424. bar = inb(base_addr + PI_ESIC_K_MEM_ADD_MASK_2);
  425. bar <<= 8;
  426. bar |= inb(base_addr + PI_ESIC_K_MEM_ADD_MASK_1);
  427. bar <<= 8;
  428. bar |= inb(base_addr + PI_ESIC_K_MEM_ADD_MASK_0);
  429. bar <<= 16;
  430. *bar_len = (bar | PI_MEM_ADD_MASK_M) + 1;
  431. } else {
  432. *bar_start = base_addr;
  433. *bar_len = PI_ESIC_K_CSR_IO_LEN;
  434. }
  435. }
  436. if (dfx_bus_tc) {
  437. *bar_start = to_tc_dev(bdev)->resource.start +
  438. PI_TC_K_CSR_OFFSET;
  439. *bar_len = PI_TC_K_CSR_LEN;
  440. }
  441. }
  442. static const struct net_device_ops dfx_netdev_ops = {
  443. .ndo_open = dfx_open,
  444. .ndo_stop = dfx_close,
  445. .ndo_start_xmit = dfx_xmt_queue_pkt,
  446. .ndo_get_stats = dfx_ctl_get_stats,
  447. .ndo_set_multicast_list = dfx_ctl_set_multicast_list,
  448. .ndo_set_mac_address = dfx_ctl_set_mac_address,
  449. };
  450. /*
  451. * ================
  452. * = dfx_register =
  453. * ================
  454. *
  455. * Overview:
  456. * Initializes a supported FDDI controller
  457. *
  458. * Returns:
  459. * Condition code
  460. *
  461. * Arguments:
  462. * bdev - pointer to device information
  463. *
  464. * Functional Description:
  465. *
  466. * Return Codes:
  467. * 0 - This device (fddi0, fddi1, etc) configured successfully
  468. * -EBUSY - Failed to get resources, or dfx_driver_init failed.
  469. *
  470. * Assumptions:
  471. * It compiles so it should work :-( (PCI cards do :-)
  472. *
  473. * Side Effects:
  474. * Device structures for FDDI adapters (fddi0, fddi1, etc) are
  475. * initialized and the board resources are read and stored in
  476. * the device structure.
  477. */
  478. static int __devinit dfx_register(struct device *bdev)
  479. {
  480. static int version_disp;
  481. int dfx_bus_pci = DFX_BUS_PCI(bdev);
  482. int dfx_bus_tc = DFX_BUS_TC(bdev);
  483. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  484. const char *print_name = dev_name(bdev);
  485. struct net_device *dev;
  486. DFX_board_t *bp; /* board pointer */
  487. resource_size_t bar_start = 0; /* pointer to port */
  488. resource_size_t bar_len = 0; /* resource length */
  489. int alloc_size; /* total buffer size used */
  490. struct resource *region;
  491. int err = 0;
  492. if (!version_disp) { /* display version info if adapter is found */
  493. version_disp = 1; /* set display flag to TRUE so that */
  494. printk(version); /* we only display this string ONCE */
  495. }
  496. dev = alloc_fddidev(sizeof(*bp));
  497. if (!dev) {
  498. printk(KERN_ERR "%s: Unable to allocate fddidev, aborting\n",
  499. print_name);
  500. return -ENOMEM;
  501. }
  502. /* Enable PCI device. */
  503. if (dfx_bus_pci && pci_enable_device(to_pci_dev(bdev))) {
  504. printk(KERN_ERR "%s: Cannot enable PCI device, aborting\n",
  505. print_name);
  506. goto err_out;
  507. }
  508. SET_NETDEV_DEV(dev, bdev);
  509. bp = netdev_priv(dev);
  510. bp->bus_dev = bdev;
  511. dev_set_drvdata(bdev, dev);
  512. dfx_get_bars(bdev, &bar_start, &bar_len);
  513. if (dfx_use_mmio)
  514. region = request_mem_region(bar_start, bar_len, print_name);
  515. else
  516. region = request_region(bar_start, bar_len, print_name);
  517. if (!region) {
  518. printk(KERN_ERR "%s: Cannot reserve I/O resource "
  519. "0x%lx @ 0x%lx, aborting\n",
  520. print_name, (long)bar_len, (long)bar_start);
  521. err = -EBUSY;
  522. goto err_out_disable;
  523. }
  524. /* Set up I/O base address. */
  525. if (dfx_use_mmio) {
  526. bp->base.mem = ioremap_nocache(bar_start, bar_len);
  527. if (!bp->base.mem) {
  528. printk(KERN_ERR "%s: Cannot map MMIO\n", print_name);
  529. err = -ENOMEM;
  530. goto err_out_region;
  531. }
  532. } else {
  533. bp->base.port = bar_start;
  534. dev->base_addr = bar_start;
  535. }
  536. /* Initialize new device structure */
  537. dev->netdev_ops = &dfx_netdev_ops;
  538. if (dfx_bus_pci)
  539. pci_set_master(to_pci_dev(bdev));
  540. if (dfx_driver_init(dev, print_name, bar_start) != DFX_K_SUCCESS) {
  541. err = -ENODEV;
  542. goto err_out_unmap;
  543. }
  544. err = register_netdev(dev);
  545. if (err)
  546. goto err_out_kfree;
  547. printk("%s: registered as %s\n", print_name, dev->name);
  548. return 0;
  549. err_out_kfree:
  550. alloc_size = sizeof(PI_DESCR_BLOCK) +
  551. PI_CMD_REQ_K_SIZE_MAX + PI_CMD_RSP_K_SIZE_MAX +
  552. #ifndef DYNAMIC_BUFFERS
  553. (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
  554. #endif
  555. sizeof(PI_CONSUMER_BLOCK) +
  556. (PI_ALIGN_K_DESC_BLK - 1);
  557. if (bp->kmalloced)
  558. dma_free_coherent(bdev, alloc_size,
  559. bp->kmalloced, bp->kmalloced_dma);
  560. err_out_unmap:
  561. if (dfx_use_mmio)
  562. iounmap(bp->base.mem);
  563. err_out_region:
  564. if (dfx_use_mmio)
  565. release_mem_region(bar_start, bar_len);
  566. else
  567. release_region(bar_start, bar_len);
  568. err_out_disable:
  569. if (dfx_bus_pci)
  570. pci_disable_device(to_pci_dev(bdev));
  571. err_out:
  572. free_netdev(dev);
  573. return err;
  574. }
  575. /*
  576. * ================
  577. * = dfx_bus_init =
  578. * ================
  579. *
  580. * Overview:
  581. * Initializes the bus-specific controller logic.
  582. *
  583. * Returns:
  584. * None
  585. *
  586. * Arguments:
  587. * dev - pointer to device information
  588. *
  589. * Functional Description:
  590. * Determine and save adapter IRQ in device table,
  591. * then perform bus-specific logic initialization.
  592. *
  593. * Return Codes:
  594. * None
  595. *
  596. * Assumptions:
  597. * bp->base has already been set with the proper
  598. * base I/O address for this device.
  599. *
  600. * Side Effects:
  601. * Interrupts are enabled at the adapter bus-specific logic.
  602. * Note: Interrupts at the DMA engine (PDQ chip) are not
  603. * enabled yet.
  604. */
  605. static void __devinit dfx_bus_init(struct net_device *dev)
  606. {
  607. DFX_board_t *bp = netdev_priv(dev);
  608. struct device *bdev = bp->bus_dev;
  609. int dfx_bus_pci = DFX_BUS_PCI(bdev);
  610. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  611. int dfx_bus_tc = DFX_BUS_TC(bdev);
  612. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  613. u8 val;
  614. DBG_printk("In dfx_bus_init...\n");
  615. /* Initialize a pointer back to the net_device struct */
  616. bp->dev = dev;
  617. /* Initialize adapter based on bus type */
  618. if (dfx_bus_tc)
  619. dev->irq = to_tc_dev(bdev)->interrupt;
  620. if (dfx_bus_eisa) {
  621. unsigned long base_addr = to_eisa_device(bdev)->base_addr;
  622. /* Get the interrupt level from the ESIC chip. */
  623. val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  624. val &= PI_CONFIG_STAT_0_M_IRQ;
  625. val >>= PI_CONFIG_STAT_0_V_IRQ;
  626. switch (val) {
  627. case PI_CONFIG_STAT_0_IRQ_K_9:
  628. dev->irq = 9;
  629. break;
  630. case PI_CONFIG_STAT_0_IRQ_K_10:
  631. dev->irq = 10;
  632. break;
  633. case PI_CONFIG_STAT_0_IRQ_K_11:
  634. dev->irq = 11;
  635. break;
  636. case PI_CONFIG_STAT_0_IRQ_K_15:
  637. dev->irq = 15;
  638. break;
  639. }
  640. /*
  641. * Enable memory decoding (MEMCS0) and/or port decoding
  642. * (IOCS1/IOCS0) as appropriate in Function Control
  643. * Register. One of the port chip selects seems to be
  644. * used for the Burst Holdoff register, but this bit of
  645. * documentation is missing and as yet it has not been
  646. * determined which of the two. This is also the reason
  647. * the size of the decoded port range is twice as large
  648. * as one required by the PDQ.
  649. */
  650. /* Set the decode range of the board. */
  651. val = ((bp->base.port >> 12) << PI_IO_CMP_V_SLOT);
  652. outb(base_addr + PI_ESIC_K_IO_ADD_CMP_0_1, val);
  653. outb(base_addr + PI_ESIC_K_IO_ADD_CMP_0_0, 0);
  654. outb(base_addr + PI_ESIC_K_IO_ADD_CMP_1_1, val);
  655. outb(base_addr + PI_ESIC_K_IO_ADD_CMP_1_0, 0);
  656. val = PI_ESIC_K_CSR_IO_LEN - 1;
  657. outb(base_addr + PI_ESIC_K_IO_ADD_MASK_0_1, (val >> 8) & 0xff);
  658. outb(base_addr + PI_ESIC_K_IO_ADD_MASK_0_0, val & 0xff);
  659. outb(base_addr + PI_ESIC_K_IO_ADD_MASK_1_1, (val >> 8) & 0xff);
  660. outb(base_addr + PI_ESIC_K_IO_ADD_MASK_1_0, val & 0xff);
  661. /* Enable the decoders. */
  662. val = PI_FUNCTION_CNTRL_M_IOCS1 | PI_FUNCTION_CNTRL_M_IOCS0;
  663. if (dfx_use_mmio)
  664. val |= PI_FUNCTION_CNTRL_M_MEMCS0;
  665. outb(base_addr + PI_ESIC_K_FUNCTION_CNTRL, val);
  666. /*
  667. * Enable access to the rest of the module
  668. * (including PDQ and packet memory).
  669. */
  670. val = PI_SLOT_CNTRL_M_ENB;
  671. outb(base_addr + PI_ESIC_K_SLOT_CNTRL, val);
  672. /*
  673. * Map PDQ registers into memory or port space. This is
  674. * done with a bit in the Burst Holdoff register.
  675. */
  676. val = inb(base_addr + PI_DEFEA_K_BURST_HOLDOFF);
  677. if (dfx_use_mmio)
  678. val |= PI_BURST_HOLDOFF_V_MEM_MAP;
  679. else
  680. val &= ~PI_BURST_HOLDOFF_V_MEM_MAP;
  681. outb(base_addr + PI_DEFEA_K_BURST_HOLDOFF, val);
  682. /* Enable interrupts at EISA bus interface chip (ESIC) */
  683. val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  684. val |= PI_CONFIG_STAT_0_M_INT_ENB;
  685. outb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0, val);
  686. }
  687. if (dfx_bus_pci) {
  688. struct pci_dev *pdev = to_pci_dev(bdev);
  689. /* Get the interrupt level from the PCI Configuration Table */
  690. dev->irq = pdev->irq;
  691. /* Check Latency Timer and set if less than minimal */
  692. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &val);
  693. if (val < PFI_K_LAT_TIMER_MIN) {
  694. val = PFI_K_LAT_TIMER_DEF;
  695. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, val);
  696. }
  697. /* Enable interrupts at PCI bus interface chip (PFI) */
  698. val = PFI_MODE_M_PDQ_INT_ENB | PFI_MODE_M_DMA_ENB;
  699. dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, val);
  700. }
  701. }
  702. /*
  703. * ==================
  704. * = dfx_bus_uninit =
  705. * ==================
  706. *
  707. * Overview:
  708. * Uninitializes the bus-specific controller logic.
  709. *
  710. * Returns:
  711. * None
  712. *
  713. * Arguments:
  714. * dev - pointer to device information
  715. *
  716. * Functional Description:
  717. * Perform bus-specific logic uninitialization.
  718. *
  719. * Return Codes:
  720. * None
  721. *
  722. * Assumptions:
  723. * bp->base has already been set with the proper
  724. * base I/O address for this device.
  725. *
  726. * Side Effects:
  727. * Interrupts are disabled at the adapter bus-specific logic.
  728. */
  729. static void __devexit dfx_bus_uninit(struct net_device *dev)
  730. {
  731. DFX_board_t *bp = netdev_priv(dev);
  732. struct device *bdev = bp->bus_dev;
  733. int dfx_bus_pci = DFX_BUS_PCI(bdev);
  734. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  735. u8 val;
  736. DBG_printk("In dfx_bus_uninit...\n");
  737. /* Uninitialize adapter based on bus type */
  738. if (dfx_bus_eisa) {
  739. unsigned long base_addr = to_eisa_device(bdev)->base_addr;
  740. /* Disable interrupts at EISA bus interface chip (ESIC) */
  741. val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  742. val &= ~PI_CONFIG_STAT_0_M_INT_ENB;
  743. outb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0, val);
  744. }
  745. if (dfx_bus_pci) {
  746. /* Disable interrupts at PCI bus interface chip (PFI) */
  747. dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, 0);
  748. }
  749. }
  750. /*
  751. * ========================
  752. * = dfx_bus_config_check =
  753. * ========================
  754. *
  755. * Overview:
  756. * Checks the configuration (burst size, full-duplex, etc.) If any parameters
  757. * are illegal, then this routine will set new defaults.
  758. *
  759. * Returns:
  760. * None
  761. *
  762. * Arguments:
  763. * bp - pointer to board information
  764. *
  765. * Functional Description:
  766. * For Revision 1 FDDI EISA, Revision 2 or later FDDI EISA with rev E or later
  767. * PDQ, and all FDDI PCI controllers, all values are legal.
  768. *
  769. * Return Codes:
  770. * None
  771. *
  772. * Assumptions:
  773. * dfx_adap_init has NOT been called yet so burst size and other items have
  774. * not been set.
  775. *
  776. * Side Effects:
  777. * None
  778. */
  779. static void __devinit dfx_bus_config_check(DFX_board_t *bp)
  780. {
  781. struct device __maybe_unused *bdev = bp->bus_dev;
  782. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  783. int status; /* return code from adapter port control call */
  784. u32 host_data; /* LW data returned from port control call */
  785. DBG_printk("In dfx_bus_config_check...\n");
  786. /* Configuration check only valid for EISA adapter */
  787. if (dfx_bus_eisa) {
  788. /*
  789. * First check if revision 2 EISA controller. Rev. 1 cards used
  790. * PDQ revision B, so no workaround needed in this case. Rev. 3
  791. * cards used PDQ revision E, so no workaround needed in this
  792. * case, either. Only Rev. 2 cards used either Rev. D or E
  793. * chips, so we must verify the chip revision on Rev. 2 cards.
  794. */
  795. if (to_eisa_device(bdev)->id.driver_data == DEFEA_PROD_ID_2) {
  796. /*
  797. * Revision 2 FDDI EISA controller found,
  798. * so let's check PDQ revision of adapter.
  799. */
  800. status = dfx_hw_port_ctrl_req(bp,
  801. PI_PCTRL_M_SUB_CMD,
  802. PI_SUB_CMD_K_PDQ_REV_GET,
  803. 0,
  804. &host_data);
  805. if ((status != DFX_K_SUCCESS) || (host_data == 2))
  806. {
  807. /*
  808. * Either we couldn't determine the PDQ revision, or
  809. * we determined that it is at revision D. In either case,
  810. * we need to implement the workaround.
  811. */
  812. /* Ensure that the burst size is set to 8 longwords or less */
  813. switch (bp->burst_size)
  814. {
  815. case PI_PDATA_B_DMA_BURST_SIZE_32:
  816. case PI_PDATA_B_DMA_BURST_SIZE_16:
  817. bp->burst_size = PI_PDATA_B_DMA_BURST_SIZE_8;
  818. break;
  819. default:
  820. break;
  821. }
  822. /* Ensure that full-duplex mode is not enabled */
  823. bp->full_duplex_enb = PI_SNMP_K_FALSE;
  824. }
  825. }
  826. }
  827. }
  828. /*
  829. * ===================
  830. * = dfx_driver_init =
  831. * ===================
  832. *
  833. * Overview:
  834. * Initializes remaining adapter board structure information
  835. * and makes sure adapter is in a safe state prior to dfx_open().
  836. *
  837. * Returns:
  838. * Condition code
  839. *
  840. * Arguments:
  841. * dev - pointer to device information
  842. * print_name - printable device name
  843. *
  844. * Functional Description:
  845. * This function allocates additional resources such as the host memory
  846. * blocks needed by the adapter (eg. descriptor and consumer blocks).
  847. * Remaining bus initialization steps are also completed. The adapter
  848. * is also reset so that it is in the DMA_UNAVAILABLE state. The OS
  849. * must call dfx_open() to open the adapter and bring it on-line.
  850. *
  851. * Return Codes:
  852. * DFX_K_SUCCESS - initialization succeeded
  853. * DFX_K_FAILURE - initialization failed - could not allocate memory
  854. * or read adapter MAC address
  855. *
  856. * Assumptions:
  857. * Memory allocated from pci_alloc_consistent() call is physically
  858. * contiguous, locked memory.
  859. *
  860. * Side Effects:
  861. * Adapter is reset and should be in DMA_UNAVAILABLE state before
  862. * returning from this routine.
  863. */
  864. static int __devinit dfx_driver_init(struct net_device *dev,
  865. const char *print_name,
  866. resource_size_t bar_start)
  867. {
  868. DFX_board_t *bp = netdev_priv(dev);
  869. struct device *bdev = bp->bus_dev;
  870. int dfx_bus_pci = DFX_BUS_PCI(bdev);
  871. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  872. int dfx_bus_tc = DFX_BUS_TC(bdev);
  873. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  874. int alloc_size; /* total buffer size needed */
  875. char *top_v, *curr_v; /* virtual addrs into memory block */
  876. dma_addr_t top_p, curr_p; /* physical addrs into memory block */
  877. u32 data; /* host data register value */
  878. __le32 le32;
  879. char *board_name = NULL;
  880. DBG_printk("In dfx_driver_init...\n");
  881. /* Initialize bus-specific hardware registers */
  882. dfx_bus_init(dev);
  883. /*
  884. * Initialize default values for configurable parameters
  885. *
  886. * Note: All of these parameters are ones that a user may
  887. * want to customize. It'd be nice to break these
  888. * out into Space.c or someplace else that's more
  889. * accessible/understandable than this file.
  890. */
  891. bp->full_duplex_enb = PI_SNMP_K_FALSE;
  892. bp->req_ttrt = 8 * 12500; /* 8ms in 80 nanosec units */
  893. bp->burst_size = PI_PDATA_B_DMA_BURST_SIZE_DEF;
  894. bp->rcv_bufs_to_post = RCV_BUFS_DEF;
  895. /*
  896. * Ensure that HW configuration is OK
  897. *
  898. * Note: Depending on the hardware revision, we may need to modify
  899. * some of the configurable parameters to workaround hardware
  900. * limitations. We'll perform this configuration check AFTER
  901. * setting the parameters to their default values.
  902. */
  903. dfx_bus_config_check(bp);
  904. /* Disable PDQ interrupts first */
  905. dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  906. /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
  907. (void) dfx_hw_dma_uninit(bp, PI_PDATA_A_RESET_M_SKIP_ST);
  908. /* Read the factory MAC address from the adapter then save it */
  909. if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_MLA, PI_PDATA_A_MLA_K_LO, 0,
  910. &data) != DFX_K_SUCCESS) {
  911. printk("%s: Could not read adapter factory MAC address!\n",
  912. print_name);
  913. return DFX_K_FAILURE;
  914. }
  915. le32 = cpu_to_le32(data);
  916. memcpy(&bp->factory_mac_addr[0], &le32, sizeof(u32));
  917. if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_MLA, PI_PDATA_A_MLA_K_HI, 0,
  918. &data) != DFX_K_SUCCESS) {
  919. printk("%s: Could not read adapter factory MAC address!\n",
  920. print_name);
  921. return DFX_K_FAILURE;
  922. }
  923. le32 = cpu_to_le32(data);
  924. memcpy(&bp->factory_mac_addr[4], &le32, sizeof(u16));
  925. /*
  926. * Set current address to factory address
  927. *
  928. * Note: Node address override support is handled through
  929. * dfx_ctl_set_mac_address.
  930. */
  931. memcpy(dev->dev_addr, bp->factory_mac_addr, FDDI_K_ALEN);
  932. if (dfx_bus_tc)
  933. board_name = "DEFTA";
  934. if (dfx_bus_eisa)
  935. board_name = "DEFEA";
  936. if (dfx_bus_pci)
  937. board_name = "DEFPA";
  938. pr_info("%s: %s at %saddr = 0x%llx, IRQ = %d, Hardware addr = %pMF\n",
  939. print_name, board_name, dfx_use_mmio ? "" : "I/O ",
  940. (long long)bar_start, dev->irq, dev->dev_addr);
  941. /*
  942. * Get memory for descriptor block, consumer block, and other buffers
  943. * that need to be DMA read or written to by the adapter.
  944. */
  945. alloc_size = sizeof(PI_DESCR_BLOCK) +
  946. PI_CMD_REQ_K_SIZE_MAX +
  947. PI_CMD_RSP_K_SIZE_MAX +
  948. #ifndef DYNAMIC_BUFFERS
  949. (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
  950. #endif
  951. sizeof(PI_CONSUMER_BLOCK) +
  952. (PI_ALIGN_K_DESC_BLK - 1);
  953. bp->kmalloced = top_v = dma_alloc_coherent(bp->bus_dev, alloc_size,
  954. &bp->kmalloced_dma,
  955. GFP_ATOMIC);
  956. if (top_v == NULL) {
  957. printk("%s: Could not allocate memory for host buffers "
  958. "and structures!\n", print_name);
  959. return DFX_K_FAILURE;
  960. }
  961. memset(top_v, 0, alloc_size); /* zero out memory before continuing */
  962. top_p = bp->kmalloced_dma; /* get physical address of buffer */
  963. /*
  964. * To guarantee the 8K alignment required for the descriptor block, 8K - 1
  965. * plus the amount of memory needed was allocated. The physical address
  966. * is now 8K aligned. By carving up the memory in a specific order,
  967. * we'll guarantee the alignment requirements for all other structures.
  968. *
  969. * Note: If the assumptions change regarding the non-paged, non-cached,
  970. * physically contiguous nature of the memory block or the address
  971. * alignments, then we'll need to implement a different algorithm
  972. * for allocating the needed memory.
  973. */
  974. curr_p = ALIGN(top_p, PI_ALIGN_K_DESC_BLK);
  975. curr_v = top_v + (curr_p - top_p);
  976. /* Reserve space for descriptor block */
  977. bp->descr_block_virt = (PI_DESCR_BLOCK *) curr_v;
  978. bp->descr_block_phys = curr_p;
  979. curr_v += sizeof(PI_DESCR_BLOCK);
  980. curr_p += sizeof(PI_DESCR_BLOCK);
  981. /* Reserve space for command request buffer */
  982. bp->cmd_req_virt = (PI_DMA_CMD_REQ *) curr_v;
  983. bp->cmd_req_phys = curr_p;
  984. curr_v += PI_CMD_REQ_K_SIZE_MAX;
  985. curr_p += PI_CMD_REQ_K_SIZE_MAX;
  986. /* Reserve space for command response buffer */
  987. bp->cmd_rsp_virt = (PI_DMA_CMD_RSP *) curr_v;
  988. bp->cmd_rsp_phys = curr_p;
  989. curr_v += PI_CMD_RSP_K_SIZE_MAX;
  990. curr_p += PI_CMD_RSP_K_SIZE_MAX;
  991. /* Reserve space for the LLC host receive queue buffers */
  992. bp->rcv_block_virt = curr_v;
  993. bp->rcv_block_phys = curr_p;
  994. #ifndef DYNAMIC_BUFFERS
  995. curr_v += (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX);
  996. curr_p += (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX);
  997. #endif
  998. /* Reserve space for the consumer block */
  999. bp->cons_block_virt = (PI_CONSUMER_BLOCK *) curr_v;
  1000. bp->cons_block_phys = curr_p;
  1001. /* Display virtual and physical addresses if debug driver */
  1002. DBG_printk("%s: Descriptor block virt = %0lX, phys = %0X\n",
  1003. print_name,
  1004. (long)bp->descr_block_virt, bp->descr_block_phys);
  1005. DBG_printk("%s: Command Request buffer virt = %0lX, phys = %0X\n",
  1006. print_name, (long)bp->cmd_req_virt, bp->cmd_req_phys);
  1007. DBG_printk("%s: Command Response buffer virt = %0lX, phys = %0X\n",
  1008. print_name, (long)bp->cmd_rsp_virt, bp->cmd_rsp_phys);
  1009. DBG_printk("%s: Receive buffer block virt = %0lX, phys = %0X\n",
  1010. print_name, (long)bp->rcv_block_virt, bp->rcv_block_phys);
  1011. DBG_printk("%s: Consumer block virt = %0lX, phys = %0X\n",
  1012. print_name, (long)bp->cons_block_virt, bp->cons_block_phys);
  1013. return DFX_K_SUCCESS;
  1014. }
  1015. /*
  1016. * =================
  1017. * = dfx_adap_init =
  1018. * =================
  1019. *
  1020. * Overview:
  1021. * Brings the adapter to the link avail/link unavailable state.
  1022. *
  1023. * Returns:
  1024. * Condition code
  1025. *
  1026. * Arguments:
  1027. * bp - pointer to board information
  1028. * get_buffers - non-zero if buffers to be allocated
  1029. *
  1030. * Functional Description:
  1031. * Issues the low-level firmware/hardware calls necessary to bring
  1032. * the adapter up, or to properly reset and restore adapter during
  1033. * run-time.
  1034. *
  1035. * Return Codes:
  1036. * DFX_K_SUCCESS - Adapter brought up successfully
  1037. * DFX_K_FAILURE - Adapter initialization failed
  1038. *
  1039. * Assumptions:
  1040. * bp->reset_type should be set to a valid reset type value before
  1041. * calling this routine.
  1042. *
  1043. * Side Effects:
  1044. * Adapter should be in LINK_AVAILABLE or LINK_UNAVAILABLE state
  1045. * upon a successful return of this routine.
  1046. */
  1047. static int dfx_adap_init(DFX_board_t *bp, int get_buffers)
  1048. {
  1049. DBG_printk("In dfx_adap_init...\n");
  1050. /* Disable PDQ interrupts first */
  1051. dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  1052. /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
  1053. if (dfx_hw_dma_uninit(bp, bp->reset_type) != DFX_K_SUCCESS)
  1054. {
  1055. printk("%s: Could not uninitialize/reset adapter!\n", bp->dev->name);
  1056. return DFX_K_FAILURE;
  1057. }
  1058. /*
  1059. * When the PDQ is reset, some false Type 0 interrupts may be pending,
  1060. * so we'll acknowledge all Type 0 interrupts now before continuing.
  1061. */
  1062. dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, PI_HOST_INT_K_ACK_ALL_TYPE_0);
  1063. /*
  1064. * Clear Type 1 and Type 2 registers before going to DMA_AVAILABLE state
  1065. *
  1066. * Note: We only need to clear host copies of these registers. The PDQ reset
  1067. * takes care of the on-board register values.
  1068. */
  1069. bp->cmd_req_reg.lword = 0;
  1070. bp->cmd_rsp_reg.lword = 0;
  1071. bp->rcv_xmt_reg.lword = 0;
  1072. /* Clear consumer block before going to DMA_AVAILABLE state */
  1073. memset(bp->cons_block_virt, 0, sizeof(PI_CONSUMER_BLOCK));
  1074. /* Initialize the DMA Burst Size */
  1075. if (dfx_hw_port_ctrl_req(bp,
  1076. PI_PCTRL_M_SUB_CMD,
  1077. PI_SUB_CMD_K_BURST_SIZE_SET,
  1078. bp->burst_size,
  1079. NULL) != DFX_K_SUCCESS)
  1080. {
  1081. printk("%s: Could not set adapter burst size!\n", bp->dev->name);
  1082. return DFX_K_FAILURE;
  1083. }
  1084. /*
  1085. * Set base address of Consumer Block
  1086. *
  1087. * Assumption: 32-bit physical address of consumer block is 64 byte
  1088. * aligned. That is, bits 0-5 of the address must be zero.
  1089. */
  1090. if (dfx_hw_port_ctrl_req(bp,
  1091. PI_PCTRL_M_CONS_BLOCK,
  1092. bp->cons_block_phys,
  1093. 0,
  1094. NULL) != DFX_K_SUCCESS)
  1095. {
  1096. printk("%s: Could not set consumer block address!\n", bp->dev->name);
  1097. return DFX_K_FAILURE;
  1098. }
  1099. /*
  1100. * Set the base address of Descriptor Block and bring adapter
  1101. * to DMA_AVAILABLE state.
  1102. *
  1103. * Note: We also set the literal and data swapping requirements
  1104. * in this command.
  1105. *
  1106. * Assumption: 32-bit physical address of descriptor block
  1107. * is 8Kbyte aligned.
  1108. */
  1109. if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_INIT,
  1110. (u32)(bp->descr_block_phys |
  1111. PI_PDATA_A_INIT_M_BSWAP_INIT),
  1112. 0, NULL) != DFX_K_SUCCESS) {
  1113. printk("%s: Could not set descriptor block address!\n",
  1114. bp->dev->name);
  1115. return DFX_K_FAILURE;
  1116. }
  1117. /* Set transmit flush timeout value */
  1118. bp->cmd_req_virt->cmd_type = PI_CMD_K_CHARS_SET;
  1119. bp->cmd_req_virt->char_set.item[0].item_code = PI_ITEM_K_FLUSH_TIME;
  1120. bp->cmd_req_virt->char_set.item[0].value = 3; /* 3 seconds */
  1121. bp->cmd_req_virt->char_set.item[0].item_index = 0;
  1122. bp->cmd_req_virt->char_set.item[1].item_code = PI_ITEM_K_EOL;
  1123. if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  1124. {
  1125. printk("%s: DMA command request failed!\n", bp->dev->name);
  1126. return DFX_K_FAILURE;
  1127. }
  1128. /* Set the initial values for eFDXEnable and MACTReq MIB objects */
  1129. bp->cmd_req_virt->cmd_type = PI_CMD_K_SNMP_SET;
  1130. bp->cmd_req_virt->snmp_set.item[0].item_code = PI_ITEM_K_FDX_ENB_DIS;
  1131. bp->cmd_req_virt->snmp_set.item[0].value = bp->full_duplex_enb;
  1132. bp->cmd_req_virt->snmp_set.item[0].item_index = 0;
  1133. bp->cmd_req_virt->snmp_set.item[1].item_code = PI_ITEM_K_MAC_T_REQ;
  1134. bp->cmd_req_virt->snmp_set.item[1].value = bp->req_ttrt;
  1135. bp->cmd_req_virt->snmp_set.item[1].item_index = 0;
  1136. bp->cmd_req_virt->snmp_set.item[2].item_code = PI_ITEM_K_EOL;
  1137. if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  1138. {
  1139. printk("%s: DMA command request failed!\n", bp->dev->name);
  1140. return DFX_K_FAILURE;
  1141. }
  1142. /* Initialize adapter CAM */
  1143. if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
  1144. {
  1145. printk("%s: Adapter CAM update failed!\n", bp->dev->name);
  1146. return DFX_K_FAILURE;
  1147. }
  1148. /* Initialize adapter filters */
  1149. if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
  1150. {
  1151. printk("%s: Adapter filters update failed!\n", bp->dev->name);
  1152. return DFX_K_FAILURE;
  1153. }
  1154. /*
  1155. * Remove any existing dynamic buffers (i.e. if the adapter is being
  1156. * reinitialized)
  1157. */
  1158. if (get_buffers)
  1159. dfx_rcv_flush(bp);
  1160. /* Initialize receive descriptor block and produce buffers */
  1161. if (dfx_rcv_init(bp, get_buffers))
  1162. {
  1163. printk("%s: Receive buffer allocation failed\n", bp->dev->name);
  1164. if (get_buffers)
  1165. dfx_rcv_flush(bp);
  1166. return DFX_K_FAILURE;
  1167. }
  1168. /* Issue START command and bring adapter to LINK_(UN)AVAILABLE state */
  1169. bp->cmd_req_virt->cmd_type = PI_CMD_K_START;
  1170. if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  1171. {
  1172. printk("%s: Start command failed\n", bp->dev->name);
  1173. if (get_buffers)
  1174. dfx_rcv_flush(bp);
  1175. return DFX_K_FAILURE;
  1176. }
  1177. /* Initialization succeeded, reenable PDQ interrupts */
  1178. dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_ENABLE_DEF_INTS);
  1179. return DFX_K_SUCCESS;
  1180. }
  1181. /*
  1182. * ============
  1183. * = dfx_open =
  1184. * ============
  1185. *
  1186. * Overview:
  1187. * Opens the adapter
  1188. *
  1189. * Returns:
  1190. * Condition code
  1191. *
  1192. * Arguments:
  1193. * dev - pointer to device information
  1194. *
  1195. * Functional Description:
  1196. * This function brings the adapter to an operational state.
  1197. *
  1198. * Return Codes:
  1199. * 0 - Adapter was successfully opened
  1200. * -EAGAIN - Could not register IRQ or adapter initialization failed
  1201. *
  1202. * Assumptions:
  1203. * This routine should only be called for a device that was
  1204. * initialized successfully.
  1205. *
  1206. * Side Effects:
  1207. * Adapter should be in LINK_AVAILABLE or LINK_UNAVAILABLE state
  1208. * if the open is successful.
  1209. */
  1210. static int dfx_open(struct net_device *dev)
  1211. {
  1212. DFX_board_t *bp = netdev_priv(dev);
  1213. int ret;
  1214. DBG_printk("In dfx_open...\n");
  1215. /* Register IRQ - support shared interrupts by passing device ptr */
  1216. ret = request_irq(dev->irq, dfx_interrupt, IRQF_SHARED, dev->name,
  1217. dev);
  1218. if (ret) {
  1219. printk(KERN_ERR "%s: Requested IRQ %d is busy\n", dev->name, dev->irq);
  1220. return ret;
  1221. }
  1222. /*
  1223. * Set current address to factory MAC address
  1224. *
  1225. * Note: We've already done this step in dfx_driver_init.
  1226. * However, it's possible that a user has set a node
  1227. * address override, then closed and reopened the
  1228. * adapter. Unless we reset the device address field
  1229. * now, we'll continue to use the existing modified
  1230. * address.
  1231. */
  1232. memcpy(dev->dev_addr, bp->factory_mac_addr, FDDI_K_ALEN);
  1233. /* Clear local unicast/multicast address tables and counts */
  1234. memset(bp->uc_table, 0, sizeof(bp->uc_table));
  1235. memset(bp->mc_table, 0, sizeof(bp->mc_table));
  1236. bp->uc_count = 0;
  1237. bp->mc_count = 0;
  1238. /* Disable promiscuous filter settings */
  1239. bp->ind_group_prom = PI_FSTATE_K_BLOCK;
  1240. bp->group_prom = PI_FSTATE_K_BLOCK;
  1241. spin_lock_init(&bp->lock);
  1242. /* Reset and initialize adapter */
  1243. bp->reset_type = PI_PDATA_A_RESET_M_SKIP_ST; /* skip self-test */
  1244. if (dfx_adap_init(bp, 1) != DFX_K_SUCCESS)
  1245. {
  1246. printk(KERN_ERR "%s: Adapter open failed!\n", dev->name);
  1247. free_irq(dev->irq, dev);
  1248. return -EAGAIN;
  1249. }
  1250. /* Set device structure info */
  1251. netif_start_queue(dev);
  1252. return 0;
  1253. }
  1254. /*
  1255. * =============
  1256. * = dfx_close =
  1257. * =============
  1258. *
  1259. * Overview:
  1260. * Closes the device/module.
  1261. *
  1262. * Returns:
  1263. * Condition code
  1264. *
  1265. * Arguments:
  1266. * dev - pointer to device information
  1267. *
  1268. * Functional Description:
  1269. * This routine closes the adapter and brings it to a safe state.
  1270. * The interrupt service routine is deregistered with the OS.
  1271. * The adapter can be opened again with another call to dfx_open().
  1272. *
  1273. * Return Codes:
  1274. * Always return 0.
  1275. *
  1276. * Assumptions:
  1277. * No further requests for this adapter are made after this routine is
  1278. * called. dfx_open() can be called to reset and reinitialize the
  1279. * adapter.
  1280. *
  1281. * Side Effects:
  1282. * Adapter should be in DMA_UNAVAILABLE state upon completion of this
  1283. * routine.
  1284. */
  1285. static int dfx_close(struct net_device *dev)
  1286. {
  1287. DFX_board_t *bp = netdev_priv(dev);
  1288. DBG_printk("In dfx_close...\n");
  1289. /* Disable PDQ interrupts first */
  1290. dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  1291. /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
  1292. (void) dfx_hw_dma_uninit(bp, PI_PDATA_A_RESET_M_SKIP_ST);
  1293. /*
  1294. * Flush any pending transmit buffers
  1295. *
  1296. * Note: It's important that we flush the transmit buffers
  1297. * BEFORE we clear our copy of the Type 2 register.
  1298. * Otherwise, we'll have no idea how many buffers
  1299. * we need to free.
  1300. */
  1301. dfx_xmt_flush(bp);
  1302. /*
  1303. * Clear Type 1 and Type 2 registers after adapter reset
  1304. *
  1305. * Note: Even though we're closing the adapter, it's
  1306. * possible that an interrupt will occur after
  1307. * dfx_close is called. Without some assurance to
  1308. * the contrary we want to make sure that we don't
  1309. * process receive and transmit LLC frames and update
  1310. * the Type 2 register with bad information.
  1311. */
  1312. bp->cmd_req_reg.lword = 0;
  1313. bp->cmd_rsp_reg.lword = 0;
  1314. bp->rcv_xmt_reg.lword = 0;
  1315. /* Clear consumer block for the same reason given above */
  1316. memset(bp->cons_block_virt, 0, sizeof(PI_CONSUMER_BLOCK));
  1317. /* Release all dynamically allocate skb in the receive ring. */
  1318. dfx_rcv_flush(bp);
  1319. /* Clear device structure flags */
  1320. netif_stop_queue(dev);
  1321. /* Deregister (free) IRQ */
  1322. free_irq(dev->irq, dev);
  1323. return 0;
  1324. }
  1325. /*
  1326. * ======================
  1327. * = dfx_int_pr_halt_id =
  1328. * ======================
  1329. *
  1330. * Overview:
  1331. * Displays halt id's in string form.
  1332. *
  1333. * Returns:
  1334. * None
  1335. *
  1336. * Arguments:
  1337. * bp - pointer to board information
  1338. *
  1339. * Functional Description:
  1340. * Determine current halt id and display appropriate string.
  1341. *
  1342. * Return Codes:
  1343. * None
  1344. *
  1345. * Assumptions:
  1346. * None
  1347. *
  1348. * Side Effects:
  1349. * None
  1350. */
  1351. static void dfx_int_pr_halt_id(DFX_board_t *bp)
  1352. {
  1353. PI_UINT32 port_status; /* PDQ port status register value */
  1354. PI_UINT32 halt_id; /* PDQ port status halt ID */
  1355. /* Read the latest port status */
  1356. dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
  1357. /* Display halt state transition information */
  1358. halt_id = (port_status & PI_PSTATUS_M_HALT_ID) >> PI_PSTATUS_V_HALT_ID;
  1359. switch (halt_id)
  1360. {
  1361. case PI_HALT_ID_K_SELFTEST_TIMEOUT:
  1362. printk("%s: Halt ID: Selftest Timeout\n", bp->dev->name);
  1363. break;
  1364. case PI_HALT_ID_K_PARITY_ERROR:
  1365. printk("%s: Halt ID: Host Bus Parity Error\n", bp->dev->name);
  1366. break;
  1367. case PI_HALT_ID_K_HOST_DIR_HALT:
  1368. printk("%s: Halt ID: Host-Directed Halt\n", bp->dev->name);
  1369. break;
  1370. case PI_HALT_ID_K_SW_FAULT:
  1371. printk("%s: Halt ID: Adapter Software Fault\n", bp->dev->name);
  1372. break;
  1373. case PI_HALT_ID_K_HW_FAULT:
  1374. printk("%s: Halt ID: Adapter Hardware Fault\n", bp->dev->name);
  1375. break;
  1376. case PI_HALT_ID_K_PC_TRACE:
  1377. printk("%s: Halt ID: FDDI Network PC Trace Path Test\n", bp->dev->name);
  1378. break;
  1379. case PI_HALT_ID_K_DMA_ERROR:
  1380. printk("%s: Halt ID: Adapter DMA Error\n", bp->dev->name);
  1381. break;
  1382. case PI_HALT_ID_K_IMAGE_CRC_ERROR:
  1383. printk("%s: Halt ID: Firmware Image CRC Error\n", bp->dev->name);
  1384. break;
  1385. case PI_HALT_ID_K_BUS_EXCEPTION:
  1386. printk("%s: Halt ID: 68000 Bus Exception\n", bp->dev->name);
  1387. break;
  1388. default:
  1389. printk("%s: Halt ID: Unknown (code = %X)\n", bp->dev->name, halt_id);
  1390. break;
  1391. }
  1392. }
  1393. /*
  1394. * ==========================
  1395. * = dfx_int_type_0_process =
  1396. * ==========================
  1397. *
  1398. * Overview:
  1399. * Processes Type 0 interrupts.
  1400. *
  1401. * Returns:
  1402. * None
  1403. *
  1404. * Arguments:
  1405. * bp - pointer to board information
  1406. *
  1407. * Functional Description:
  1408. * Processes all enabled Type 0 interrupts. If the reason for the interrupt
  1409. * is a serious fault on the adapter, then an error message is displayed
  1410. * and the adapter is reset.
  1411. *
  1412. * One tricky potential timing window is the rapid succession of "link avail"
  1413. * "link unavail" state change interrupts. The acknowledgement of the Type 0
  1414. * interrupt must be done before reading the state from the Port Status
  1415. * register. This is true because a state change could occur after reading
  1416. * the data, but before acknowledging the interrupt. If this state change
  1417. * does happen, it would be lost because the driver is using the old state,
  1418. * and it will never know about the new state because it subsequently
  1419. * acknowledges the state change interrupt.
  1420. *
  1421. * INCORRECT CORRECT
  1422. * read type 0 int reasons read type 0 int reasons
  1423. * read adapter state ack type 0 interrupts
  1424. * ack type 0 interrupts read adapter state
  1425. * ... process interrupt ...