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

/drivers/net/fddi/defxx.c

https://github.com/mturquette/linux
C | 1661 lines | 703 code | 226 blank | 732 comment | 98 complexity | 7747d675b15700983878b90dfcfccfff 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. * 01 Jul 2014 macro Fixes for DMA on 64-bit hosts.
  200. */
  201. /* Include files */
  202. #include <linux/bitops.h>
  203. #include <linux/compiler.h>
  204. #include <linux/delay.h>
  205. #include <linux/dma-mapping.h>
  206. #include <linux/eisa.h>
  207. #include <linux/errno.h>
  208. #include <linux/fddidevice.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.11"
  225. #define DRV_RELDATE "2014/07/01"
  226. static char version[] =
  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_EISA
  237. #define DFX_BUS_EISA(dev) (dev->bus == &eisa_bus_type)
  238. #else
  239. #define DFX_BUS_EISA(dev) 0
  240. #endif
  241. #ifdef CONFIG_TC
  242. #define DFX_BUS_TC(dev) (dev->bus == &tc_bus_type)
  243. #else
  244. #define DFX_BUS_TC(dev) 0
  245. #endif
  246. #ifdef CONFIG_DEFXX_MMIO
  247. #define DFX_MMIO 1
  248. #else
  249. #define DFX_MMIO 0
  250. #endif
  251. /* Define module-wide (static) routines */
  252. static void dfx_bus_init(struct net_device *dev);
  253. static void dfx_bus_uninit(struct net_device *dev);
  254. static void dfx_bus_config_check(DFX_board_t *bp);
  255. static int dfx_driver_init(struct net_device *dev,
  256. const char *print_name,
  257. resource_size_t bar_start);
  258. static int dfx_adap_init(DFX_board_t *bp, int get_buffers);
  259. static int dfx_open(struct net_device *dev);
  260. static int dfx_close(struct net_device *dev);
  261. static void dfx_int_pr_halt_id(DFX_board_t *bp);
  262. static void dfx_int_type_0_process(DFX_board_t *bp);
  263. static void dfx_int_common(struct net_device *dev);
  264. static irqreturn_t dfx_interrupt(int irq, void *dev_id);
  265. static struct net_device_stats *dfx_ctl_get_stats(struct net_device *dev);
  266. static void dfx_ctl_set_multicast_list(struct net_device *dev);
  267. static int dfx_ctl_set_mac_address(struct net_device *dev, void *addr);
  268. static int dfx_ctl_update_cam(DFX_board_t *bp);
  269. static int dfx_ctl_update_filters(DFX_board_t *bp);
  270. static int dfx_hw_dma_cmd_req(DFX_board_t *bp);
  271. 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);
  272. static void dfx_hw_adap_reset(DFX_board_t *bp, PI_UINT32 type);
  273. static int dfx_hw_adap_state_rd(DFX_board_t *bp);
  274. static int dfx_hw_dma_uninit(DFX_board_t *bp, PI_UINT32 type);
  275. static int dfx_rcv_init(DFX_board_t *bp, int get_buffers);
  276. static void dfx_rcv_queue_process(DFX_board_t *bp);
  277. #ifdef DYNAMIC_BUFFERS
  278. static void dfx_rcv_flush(DFX_board_t *bp);
  279. #else
  280. static inline void dfx_rcv_flush(DFX_board_t *bp) {}
  281. #endif
  282. static netdev_tx_t dfx_xmt_queue_pkt(struct sk_buff *skb,
  283. struct net_device *dev);
  284. static int dfx_xmt_done(DFX_board_t *bp);
  285. static void dfx_xmt_flush(DFX_board_t *bp);
  286. /* Define module-wide (static) variables */
  287. static struct pci_driver dfx_pci_driver;
  288. static struct eisa_driver dfx_eisa_driver;
  289. static struct tc_driver dfx_tc_driver;
  290. /*
  291. * =======================
  292. * = dfx_port_write_long =
  293. * = dfx_port_read_long =
  294. * =======================
  295. *
  296. * Overview:
  297. * Routines for reading and writing values from/to adapter
  298. *
  299. * Returns:
  300. * None
  301. *
  302. * Arguments:
  303. * bp - pointer to board information
  304. * offset - register offset from base I/O address
  305. * data - for dfx_port_write_long, this is a value to write;
  306. * for dfx_port_read_long, this is a pointer to store
  307. * the read value
  308. *
  309. * Functional Description:
  310. * These routines perform the correct operation to read or write
  311. * the adapter register.
  312. *
  313. * EISA port block base addresses are based on the slot number in which the
  314. * controller is installed. For example, if the EISA controller is installed
  315. * in slot 4, the port block base address is 0x4000. If the controller is
  316. * installed in slot 2, the port block base address is 0x2000, and so on.
  317. * This port block can be used to access PDQ, ESIC, and DEFEA on-board
  318. * registers using the register offsets defined in DEFXX.H.
  319. *
  320. * PCI port block base addresses are assigned by the PCI BIOS or system
  321. * firmware. There is one 128 byte port block which can be accessed. It
  322. * allows for I/O mapping of both PDQ and PFI registers using the register
  323. * offsets defined in DEFXX.H.
  324. *
  325. * Return Codes:
  326. * None
  327. *
  328. * Assumptions:
  329. * bp->base is a valid base I/O address for this adapter.
  330. * offset is a valid register offset for this adapter.
  331. *
  332. * Side Effects:
  333. * Rather than produce macros for these functions, these routines
  334. * are defined using "inline" to ensure that the compiler will
  335. * generate inline code and not waste a procedure call and return.
  336. * This provides all the benefits of macros, but with the
  337. * advantage of strict data type checking.
  338. */
  339. static inline void dfx_writel(DFX_board_t *bp, int offset, u32 data)
  340. {
  341. writel(data, bp->base.mem + offset);
  342. mb();
  343. }
  344. static inline void dfx_outl(DFX_board_t *bp, int offset, u32 data)
  345. {
  346. outl(data, bp->base.port + offset);
  347. }
  348. static void dfx_port_write_long(DFX_board_t *bp, int offset, u32 data)
  349. {
  350. struct device __maybe_unused *bdev = bp->bus_dev;
  351. int dfx_bus_tc = DFX_BUS_TC(bdev);
  352. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  353. if (dfx_use_mmio)
  354. dfx_writel(bp, offset, data);
  355. else
  356. dfx_outl(bp, offset, data);
  357. }
  358. static inline void dfx_readl(DFX_board_t *bp, int offset, u32 *data)
  359. {
  360. mb();
  361. *data = readl(bp->base.mem + offset);
  362. }
  363. static inline void dfx_inl(DFX_board_t *bp, int offset, u32 *data)
  364. {
  365. *data = inl(bp->base.port + offset);
  366. }
  367. static void dfx_port_read_long(DFX_board_t *bp, int offset, u32 *data)
  368. {
  369. struct device __maybe_unused *bdev = bp->bus_dev;
  370. int dfx_bus_tc = DFX_BUS_TC(bdev);
  371. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  372. if (dfx_use_mmio)
  373. dfx_readl(bp, offset, data);
  374. else
  375. dfx_inl(bp, offset, data);
  376. }
  377. /*
  378. * ================
  379. * = dfx_get_bars =
  380. * ================
  381. *
  382. * Overview:
  383. * Retrieves the address ranges used to access control and status
  384. * registers.
  385. *
  386. * Returns:
  387. * None
  388. *
  389. * Arguments:
  390. * bdev - pointer to device information
  391. * bar_start - pointer to store the start addresses
  392. * bar_len - pointer to store the lengths of the areas
  393. *
  394. * Assumptions:
  395. * I am sure there are some.
  396. *
  397. * Side Effects:
  398. * None
  399. */
  400. static void dfx_get_bars(struct device *bdev,
  401. resource_size_t *bar_start, resource_size_t *bar_len)
  402. {
  403. int dfx_bus_pci = dev_is_pci(bdev);
  404. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  405. int dfx_bus_tc = DFX_BUS_TC(bdev);
  406. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  407. if (dfx_bus_pci) {
  408. int num = dfx_use_mmio ? 0 : 1;
  409. bar_start[0] = pci_resource_start(to_pci_dev(bdev), num);
  410. bar_len[0] = pci_resource_len(to_pci_dev(bdev), num);
  411. bar_start[2] = bar_start[1] = 0;
  412. bar_len[2] = bar_len[1] = 0;
  413. }
  414. if (dfx_bus_eisa) {
  415. unsigned long base_addr = to_eisa_device(bdev)->base_addr;
  416. resource_size_t bar_lo;
  417. resource_size_t bar_hi;
  418. if (dfx_use_mmio) {
  419. bar_lo = inb(base_addr + PI_ESIC_K_MEM_ADD_LO_CMP_2);
  420. bar_lo <<= 8;
  421. bar_lo |= inb(base_addr + PI_ESIC_K_MEM_ADD_LO_CMP_1);
  422. bar_lo <<= 8;
  423. bar_lo |= inb(base_addr + PI_ESIC_K_MEM_ADD_LO_CMP_0);
  424. bar_lo <<= 8;
  425. bar_start[0] = bar_lo;
  426. bar_hi = inb(base_addr + PI_ESIC_K_MEM_ADD_HI_CMP_2);
  427. bar_hi <<= 8;
  428. bar_hi |= inb(base_addr + PI_ESIC_K_MEM_ADD_HI_CMP_1);
  429. bar_hi <<= 8;
  430. bar_hi |= inb(base_addr + PI_ESIC_K_MEM_ADD_HI_CMP_0);
  431. bar_hi <<= 8;
  432. bar_len[0] = ((bar_hi - bar_lo) | PI_MEM_ADD_MASK_M) +
  433. 1;
  434. } else {
  435. bar_start[0] = base_addr;
  436. bar_len[0] = PI_ESIC_K_CSR_IO_LEN;
  437. }
  438. bar_start[1] = base_addr + PI_DEFEA_K_BURST_HOLDOFF;
  439. bar_len[1] = PI_ESIC_K_BURST_HOLDOFF_LEN;
  440. bar_start[2] = base_addr + PI_ESIC_K_ESIC_CSR;
  441. bar_len[2] = PI_ESIC_K_ESIC_CSR_LEN;
  442. }
  443. if (dfx_bus_tc) {
  444. bar_start[0] = to_tc_dev(bdev)->resource.start +
  445. PI_TC_K_CSR_OFFSET;
  446. bar_len[0] = PI_TC_K_CSR_LEN;
  447. bar_start[2] = bar_start[1] = 0;
  448. bar_len[2] = bar_len[1] = 0;
  449. }
  450. }
  451. static const struct net_device_ops dfx_netdev_ops = {
  452. .ndo_open = dfx_open,
  453. .ndo_stop = dfx_close,
  454. .ndo_start_xmit = dfx_xmt_queue_pkt,
  455. .ndo_get_stats = dfx_ctl_get_stats,
  456. .ndo_set_rx_mode = dfx_ctl_set_multicast_list,
  457. .ndo_set_mac_address = dfx_ctl_set_mac_address,
  458. };
  459. /*
  460. * ================
  461. * = dfx_register =
  462. * ================
  463. *
  464. * Overview:
  465. * Initializes a supported FDDI controller
  466. *
  467. * Returns:
  468. * Condition code
  469. *
  470. * Arguments:
  471. * bdev - pointer to device information
  472. *
  473. * Functional Description:
  474. *
  475. * Return Codes:
  476. * 0 - This device (fddi0, fddi1, etc) configured successfully
  477. * -EBUSY - Failed to get resources, or dfx_driver_init failed.
  478. *
  479. * Assumptions:
  480. * It compiles so it should work :-( (PCI cards do :-)
  481. *
  482. * Side Effects:
  483. * Device structures for FDDI adapters (fddi0, fddi1, etc) are
  484. * initialized and the board resources are read and stored in
  485. * the device structure.
  486. */
  487. static int dfx_register(struct device *bdev)
  488. {
  489. static int version_disp;
  490. int dfx_bus_pci = dev_is_pci(bdev);
  491. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  492. int dfx_bus_tc = DFX_BUS_TC(bdev);
  493. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  494. const char *print_name = dev_name(bdev);
  495. struct net_device *dev;
  496. DFX_board_t *bp; /* board pointer */
  497. resource_size_t bar_start[3] = {0}; /* pointers to ports */
  498. resource_size_t bar_len[3] = {0}; /* resource length */
  499. int alloc_size; /* total buffer size used */
  500. struct resource *region;
  501. int err = 0;
  502. if (!version_disp) { /* display version info if adapter is found */
  503. version_disp = 1; /* set display flag to TRUE so that */
  504. printk(version); /* we only display this string ONCE */
  505. }
  506. dev = alloc_fddidev(sizeof(*bp));
  507. if (!dev) {
  508. printk(KERN_ERR "%s: Unable to allocate fddidev, aborting\n",
  509. print_name);
  510. return -ENOMEM;
  511. }
  512. /* Enable PCI device. */
  513. if (dfx_bus_pci) {
  514. err = pci_enable_device(to_pci_dev(bdev));
  515. if (err) {
  516. pr_err("%s: Cannot enable PCI device, aborting\n",
  517. print_name);
  518. goto err_out;
  519. }
  520. }
  521. SET_NETDEV_DEV(dev, bdev);
  522. bp = netdev_priv(dev);
  523. bp->bus_dev = bdev;
  524. dev_set_drvdata(bdev, dev);
  525. dfx_get_bars(bdev, bar_start, bar_len);
  526. if (dfx_bus_eisa && dfx_use_mmio && bar_start[0] == 0) {
  527. pr_err("%s: Cannot use MMIO, no address set, aborting\n",
  528. print_name);
  529. pr_err("%s: Run ECU and set adapter's MMIO location\n",
  530. print_name);
  531. pr_err("%s: Or recompile driver with \"CONFIG_DEFXX_MMIO=n\""
  532. "\n", print_name);
  533. err = -ENXIO;
  534. goto err_out;
  535. }
  536. if (dfx_use_mmio)
  537. region = request_mem_region(bar_start[0], bar_len[0],
  538. print_name);
  539. else
  540. region = request_region(bar_start[0], bar_len[0], print_name);
  541. if (!region) {
  542. pr_err("%s: Cannot reserve %s resource 0x%lx @ 0x%lx, "
  543. "aborting\n", dfx_use_mmio ? "MMIO" : "I/O", print_name,
  544. (long)bar_len[0], (long)bar_start[0]);
  545. err = -EBUSY;
  546. goto err_out_disable;
  547. }
  548. if (bar_start[1] != 0) {
  549. region = request_region(bar_start[1], bar_len[1], print_name);
  550. if (!region) {
  551. pr_err("%s: Cannot reserve I/O resource "
  552. "0x%lx @ 0x%lx, aborting\n", print_name,
  553. (long)bar_len[1], (long)bar_start[1]);
  554. err = -EBUSY;
  555. goto err_out_csr_region;
  556. }
  557. }
  558. if (bar_start[2] != 0) {
  559. region = request_region(bar_start[2], bar_len[2], print_name);
  560. if (!region) {
  561. pr_err("%s: Cannot reserve I/O resource "
  562. "0x%lx @ 0x%lx, aborting\n", print_name,
  563. (long)bar_len[2], (long)bar_start[2]);
  564. err = -EBUSY;
  565. goto err_out_bh_region;
  566. }
  567. }
  568. /* Set up I/O base address. */
  569. if (dfx_use_mmio) {
  570. bp->base.mem = ioremap_nocache(bar_start[0], bar_len[0]);
  571. if (!bp->base.mem) {
  572. printk(KERN_ERR "%s: Cannot map MMIO\n", print_name);
  573. err = -ENOMEM;
  574. goto err_out_esic_region;
  575. }
  576. } else {
  577. bp->base.port = bar_start[0];
  578. dev->base_addr = bar_start[0];
  579. }
  580. /* Initialize new device structure */
  581. dev->netdev_ops = &dfx_netdev_ops;
  582. if (dfx_bus_pci)
  583. pci_set_master(to_pci_dev(bdev));
  584. if (dfx_driver_init(dev, print_name, bar_start[0]) != DFX_K_SUCCESS) {
  585. err = -ENODEV;
  586. goto err_out_unmap;
  587. }
  588. err = register_netdev(dev);
  589. if (err)
  590. goto err_out_kfree;
  591. printk("%s: registered as %s\n", print_name, dev->name);
  592. return 0;
  593. err_out_kfree:
  594. alloc_size = sizeof(PI_DESCR_BLOCK) +
  595. PI_CMD_REQ_K_SIZE_MAX + PI_CMD_RSP_K_SIZE_MAX +
  596. #ifndef DYNAMIC_BUFFERS
  597. (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
  598. #endif
  599. sizeof(PI_CONSUMER_BLOCK) +
  600. (PI_ALIGN_K_DESC_BLK - 1);
  601. if (bp->kmalloced)
  602. dma_free_coherent(bdev, alloc_size,
  603. bp->kmalloced, bp->kmalloced_dma);
  604. err_out_unmap:
  605. if (dfx_use_mmio)
  606. iounmap(bp->base.mem);
  607. err_out_esic_region:
  608. if (bar_start[2] != 0)
  609. release_region(bar_start[2], bar_len[2]);
  610. err_out_bh_region:
  611. if (bar_start[1] != 0)
  612. release_region(bar_start[1], bar_len[1]);
  613. err_out_csr_region:
  614. if (dfx_use_mmio)
  615. release_mem_region(bar_start[0], bar_len[0]);
  616. else
  617. release_region(bar_start[0], bar_len[0]);
  618. err_out_disable:
  619. if (dfx_bus_pci)
  620. pci_disable_device(to_pci_dev(bdev));
  621. err_out:
  622. free_netdev(dev);
  623. return err;
  624. }
  625. /*
  626. * ================
  627. * = dfx_bus_init =
  628. * ================
  629. *
  630. * Overview:
  631. * Initializes the bus-specific controller logic.
  632. *
  633. * Returns:
  634. * None
  635. *
  636. * Arguments:
  637. * dev - pointer to device information
  638. *
  639. * Functional Description:
  640. * Determine and save adapter IRQ in device table,
  641. * then perform bus-specific logic initialization.
  642. *
  643. * Return Codes:
  644. * None
  645. *
  646. * Assumptions:
  647. * bp->base has already been set with the proper
  648. * base I/O address for this device.
  649. *
  650. * Side Effects:
  651. * Interrupts are enabled at the adapter bus-specific logic.
  652. * Note: Interrupts at the DMA engine (PDQ chip) are not
  653. * enabled yet.
  654. */
  655. static void dfx_bus_init(struct net_device *dev)
  656. {
  657. DFX_board_t *bp = netdev_priv(dev);
  658. struct device *bdev = bp->bus_dev;
  659. int dfx_bus_pci = dev_is_pci(bdev);
  660. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  661. int dfx_bus_tc = DFX_BUS_TC(bdev);
  662. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  663. u8 val;
  664. DBG_printk("In dfx_bus_init...\n");
  665. /* Initialize a pointer back to the net_device struct */
  666. bp->dev = dev;
  667. /* Initialize adapter based on bus type */
  668. if (dfx_bus_tc)
  669. dev->irq = to_tc_dev(bdev)->interrupt;
  670. if (dfx_bus_eisa) {
  671. unsigned long base_addr = to_eisa_device(bdev)->base_addr;
  672. /* Disable the board before fiddling with the decoders. */
  673. outb(0, base_addr + PI_ESIC_K_SLOT_CNTRL);
  674. /* Get the interrupt level from the ESIC chip. */
  675. val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  676. val &= PI_CONFIG_STAT_0_M_IRQ;
  677. val >>= PI_CONFIG_STAT_0_V_IRQ;
  678. switch (val) {
  679. case PI_CONFIG_STAT_0_IRQ_K_9:
  680. dev->irq = 9;
  681. break;
  682. case PI_CONFIG_STAT_0_IRQ_K_10:
  683. dev->irq = 10;
  684. break;
  685. case PI_CONFIG_STAT_0_IRQ_K_11:
  686. dev->irq = 11;
  687. break;
  688. case PI_CONFIG_STAT_0_IRQ_K_15:
  689. dev->irq = 15;
  690. break;
  691. }
  692. /*
  693. * Enable memory decoding (MEMCS1) and/or port decoding
  694. * (IOCS1/IOCS0) as appropriate in Function Control
  695. * Register. MEMCS1 or IOCS0 is used for PDQ registers,
  696. * taking 16 32-bit words, while IOCS1 is used for the
  697. * Burst Holdoff register, taking a single 32-bit word
  698. * only. We use the slot-specific I/O range as per the
  699. * ESIC spec, that is set bits 15:12 in the mask registers
  700. * to mask them out.
  701. */
  702. /* Set the decode range of the board. */
  703. val = 0;
  704. outb(val, base_addr + PI_ESIC_K_IO_ADD_CMP_0_1);
  705. val = PI_DEFEA_K_CSR_IO;
  706. outb(val, base_addr + PI_ESIC_K_IO_ADD_CMP_0_0);
  707. val = PI_IO_CMP_M_SLOT;
  708. outb(val, base_addr + PI_ESIC_K_IO_ADD_MASK_0_1);
  709. val = (PI_ESIC_K_CSR_IO_LEN - 1) & ~3;
  710. outb(val, base_addr + PI_ESIC_K_IO_ADD_MASK_0_0);
  711. val = 0;
  712. outb(val, base_addr + PI_ESIC_K_IO_ADD_CMP_1_1);
  713. val = PI_DEFEA_K_BURST_HOLDOFF;
  714. outb(val, base_addr + PI_ESIC_K_IO_ADD_CMP_1_0);
  715. val = PI_IO_CMP_M_SLOT;
  716. outb(val, base_addr + PI_ESIC_K_IO_ADD_MASK_1_1);
  717. val = (PI_ESIC_K_BURST_HOLDOFF_LEN - 1) & ~3;
  718. outb(val, base_addr + PI_ESIC_K_IO_ADD_MASK_1_0);
  719. /* Enable the decoders. */
  720. val = PI_FUNCTION_CNTRL_M_IOCS1;
  721. if (dfx_use_mmio)
  722. val |= PI_FUNCTION_CNTRL_M_MEMCS1;
  723. else
  724. val |= PI_FUNCTION_CNTRL_M_IOCS0;
  725. outb(val, base_addr + PI_ESIC_K_FUNCTION_CNTRL);
  726. /*
  727. * Enable access to the rest of the module
  728. * (including PDQ and packet memory).
  729. */
  730. val = PI_SLOT_CNTRL_M_ENB;
  731. outb(val, base_addr + PI_ESIC_K_SLOT_CNTRL);
  732. /*
  733. * Map PDQ registers into memory or port space. This is
  734. * done with a bit in the Burst Holdoff register.
  735. */
  736. val = inb(base_addr + PI_DEFEA_K_BURST_HOLDOFF);
  737. if (dfx_use_mmio)
  738. val |= PI_BURST_HOLDOFF_M_MEM_MAP;
  739. else
  740. val &= ~PI_BURST_HOLDOFF_M_MEM_MAP;
  741. outb(val, base_addr + PI_DEFEA_K_BURST_HOLDOFF);
  742. /* Enable interrupts at EISA bus interface chip (ESIC) */
  743. val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  744. val |= PI_CONFIG_STAT_0_M_INT_ENB;
  745. outb(val, base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  746. }
  747. if (dfx_bus_pci) {
  748. struct pci_dev *pdev = to_pci_dev(bdev);
  749. /* Get the interrupt level from the PCI Configuration Table */
  750. dev->irq = pdev->irq;
  751. /* Check Latency Timer and set if less than minimal */
  752. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &val);
  753. if (val < PFI_K_LAT_TIMER_MIN) {
  754. val = PFI_K_LAT_TIMER_DEF;
  755. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, val);
  756. }
  757. /* Enable interrupts at PCI bus interface chip (PFI) */
  758. val = PFI_MODE_M_PDQ_INT_ENB | PFI_MODE_M_DMA_ENB;
  759. dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, val);
  760. }
  761. }
  762. /*
  763. * ==================
  764. * = dfx_bus_uninit =
  765. * ==================
  766. *
  767. * Overview:
  768. * Uninitializes the bus-specific controller logic.
  769. *
  770. * Returns:
  771. * None
  772. *
  773. * Arguments:
  774. * dev - pointer to device information
  775. *
  776. * Functional Description:
  777. * Perform bus-specific logic uninitialization.
  778. *
  779. * Return Codes:
  780. * None
  781. *
  782. * Assumptions:
  783. * bp->base has already been set with the proper
  784. * base I/O address for this device.
  785. *
  786. * Side Effects:
  787. * Interrupts are disabled at the adapter bus-specific logic.
  788. */
  789. static void dfx_bus_uninit(struct net_device *dev)
  790. {
  791. DFX_board_t *bp = netdev_priv(dev);
  792. struct device *bdev = bp->bus_dev;
  793. int dfx_bus_pci = dev_is_pci(bdev);
  794. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  795. u8 val;
  796. DBG_printk("In dfx_bus_uninit...\n");
  797. /* Uninitialize adapter based on bus type */
  798. if (dfx_bus_eisa) {
  799. unsigned long base_addr = to_eisa_device(bdev)->base_addr;
  800. /* Disable interrupts at EISA bus interface chip (ESIC) */
  801. val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  802. val &= ~PI_CONFIG_STAT_0_M_INT_ENB;
  803. outb(val, base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  804. /* Disable the board. */
  805. outb(0, base_addr + PI_ESIC_K_SLOT_CNTRL);
  806. /* Disable memory and port decoders. */
  807. outb(0, base_addr + PI_ESIC_K_FUNCTION_CNTRL);
  808. }
  809. if (dfx_bus_pci) {
  810. /* Disable interrupts at PCI bus interface chip (PFI) */
  811. dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, 0);
  812. }
  813. }
  814. /*
  815. * ========================
  816. * = dfx_bus_config_check =
  817. * ========================
  818. *
  819. * Overview:
  820. * Checks the configuration (burst size, full-duplex, etc.) If any parameters
  821. * are illegal, then this routine will set new defaults.
  822. *
  823. * Returns:
  824. * None
  825. *
  826. * Arguments:
  827. * bp - pointer to board information
  828. *
  829. * Functional Description:
  830. * For Revision 1 FDDI EISA, Revision 2 or later FDDI EISA with rev E or later
  831. * PDQ, and all FDDI PCI controllers, all values are legal.
  832. *
  833. * Return Codes:
  834. * None
  835. *
  836. * Assumptions:
  837. * dfx_adap_init has NOT been called yet so burst size and other items have
  838. * not been set.
  839. *
  840. * Side Effects:
  841. * None
  842. */
  843. static void dfx_bus_config_check(DFX_board_t *bp)
  844. {
  845. struct device __maybe_unused *bdev = bp->bus_dev;
  846. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  847. int status; /* return code from adapter port control call */
  848. u32 host_data; /* LW data returned from port control call */
  849. DBG_printk("In dfx_bus_config_check...\n");
  850. /* Configuration check only valid for EISA adapter */
  851. if (dfx_bus_eisa) {
  852. /*
  853. * First check if revision 2 EISA controller. Rev. 1 cards used
  854. * PDQ revision B, so no workaround needed in this case. Rev. 3
  855. * cards used PDQ revision E, so no workaround needed in this
  856. * case, either. Only Rev. 2 cards used either Rev. D or E
  857. * chips, so we must verify the chip revision on Rev. 2 cards.
  858. */
  859. if (to_eisa_device(bdev)->id.driver_data == DEFEA_PROD_ID_2) {
  860. /*
  861. * Revision 2 FDDI EISA controller found,
  862. * so let's check PDQ revision of adapter.
  863. */
  864. status = dfx_hw_port_ctrl_req(bp,
  865. PI_PCTRL_M_SUB_CMD,
  866. PI_SUB_CMD_K_PDQ_REV_GET,
  867. 0,
  868. &host_data);
  869. if ((status != DFX_K_SUCCESS) || (host_data == 2))
  870. {
  871. /*
  872. * Either we couldn't determine the PDQ revision, or
  873. * we determined that it is at revision D. In either case,
  874. * we need to implement the workaround.
  875. */
  876. /* Ensure that the burst size is set to 8 longwords or less */
  877. switch (bp->burst_size)
  878. {
  879. case PI_PDATA_B_DMA_BURST_SIZE_32:
  880. case PI_PDATA_B_DMA_BURST_SIZE_16:
  881. bp->burst_size = PI_PDATA_B_DMA_BURST_SIZE_8;
  882. break;
  883. default:
  884. break;
  885. }
  886. /* Ensure that full-duplex mode is not enabled */
  887. bp->full_duplex_enb = PI_SNMP_K_FALSE;
  888. }
  889. }
  890. }
  891. }
  892. /*
  893. * ===================
  894. * = dfx_driver_init =
  895. * ===================
  896. *
  897. * Overview:
  898. * Initializes remaining adapter board structure information
  899. * and makes sure adapter is in a safe state prior to dfx_open().
  900. *
  901. * Returns:
  902. * Condition code
  903. *
  904. * Arguments:
  905. * dev - pointer to device information
  906. * print_name - printable device name
  907. *
  908. * Functional Description:
  909. * This function allocates additional resources such as the host memory
  910. * blocks needed by the adapter (eg. descriptor and consumer blocks).
  911. * Remaining bus initialization steps are also completed. The adapter
  912. * is also reset so that it is in the DMA_UNAVAILABLE state. The OS
  913. * must call dfx_open() to open the adapter and bring it on-line.
  914. *
  915. * Return Codes:
  916. * DFX_K_SUCCESS - initialization succeeded
  917. * DFX_K_FAILURE - initialization failed - could not allocate memory
  918. * or read adapter MAC address
  919. *
  920. * Assumptions:
  921. * Memory allocated from pci_alloc_consistent() call is physically
  922. * contiguous, locked memory.
  923. *
  924. * Side Effects:
  925. * Adapter is reset and should be in DMA_UNAVAILABLE state before
  926. * returning from this routine.
  927. */
  928. static int dfx_driver_init(struct net_device *dev, const char *print_name,
  929. resource_size_t bar_start)
  930. {
  931. DFX_board_t *bp = netdev_priv(dev);
  932. struct device *bdev = bp->bus_dev;
  933. int dfx_bus_pci = dev_is_pci(bdev);
  934. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  935. int dfx_bus_tc = DFX_BUS_TC(bdev);
  936. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  937. int alloc_size; /* total buffer size needed */
  938. char *top_v, *curr_v; /* virtual addrs into memory block */
  939. dma_addr_t top_p, curr_p; /* physical addrs into memory block */
  940. u32 data; /* host data register value */
  941. __le32 le32;
  942. char *board_name = NULL;
  943. DBG_printk("In dfx_driver_init...\n");
  944. /* Initialize bus-specific hardware registers */
  945. dfx_bus_init(dev);
  946. /*
  947. * Initialize default values for configurable parameters
  948. *
  949. * Note: All of these parameters are ones that a user may
  950. * want to customize. It'd be nice to break these
  951. * out into Space.c or someplace else that's more
  952. * accessible/understandable than this file.
  953. */
  954. bp->full_duplex_enb = PI_SNMP_K_FALSE;
  955. bp->req_ttrt = 8 * 12500; /* 8ms in 80 nanosec units */
  956. bp->burst_size = PI_PDATA_B_DMA_BURST_SIZE_DEF;
  957. bp->rcv_bufs_to_post = RCV_BUFS_DEF;
  958. /*
  959. * Ensure that HW configuration is OK
  960. *
  961. * Note: Depending on the hardware revision, we may need to modify
  962. * some of the configurable parameters to workaround hardware
  963. * limitations. We'll perform this configuration check AFTER
  964. * setting the parameters to their default values.
  965. */
  966. dfx_bus_config_check(bp);
  967. /* Disable PDQ interrupts first */
  968. dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  969. /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
  970. (void) dfx_hw_dma_uninit(bp, PI_PDATA_A_RESET_M_SKIP_ST);
  971. /* Read the factory MAC address from the adapter then save it */
  972. if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_MLA, PI_PDATA_A_MLA_K_LO, 0,
  973. &data) != DFX_K_SUCCESS) {
  974. printk("%s: Could not read adapter factory MAC address!\n",
  975. print_name);
  976. return DFX_K_FAILURE;
  977. }
  978. le32 = cpu_to_le32(data);
  979. memcpy(&bp->factory_mac_addr[0], &le32, sizeof(u32));
  980. if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_MLA, PI_PDATA_A_MLA_K_HI, 0,
  981. &data) != DFX_K_SUCCESS) {
  982. printk("%s: Could not read adapter factory MAC address!\n",
  983. print_name);
  984. return DFX_K_FAILURE;
  985. }
  986. le32 = cpu_to_le32(data);
  987. memcpy(&bp->factory_mac_addr[4], &le32, sizeof(u16));
  988. /*
  989. * Set current address to factory address
  990. *
  991. * Note: Node address override support is handled through
  992. * dfx_ctl_set_mac_address.
  993. */
  994. memcpy(dev->dev_addr, bp->factory_mac_addr, FDDI_K_ALEN);
  995. if (dfx_bus_tc)
  996. board_name = "DEFTA";
  997. if (dfx_bus_eisa)
  998. board_name = "DEFEA";
  999. if (dfx_bus_pci)
  1000. board_name = "DEFPA";
  1001. pr_info("%s: %s at %s addr = 0x%llx, IRQ = %d, Hardware addr = %pMF\n",
  1002. print_name, board_name, dfx_use_mmio ? "MMIO" : "I/O",
  1003. (long long)bar_start, dev->irq, dev->dev_addr);
  1004. /*
  1005. * Get memory for descriptor block, consumer block, and other buffers
  1006. * that need to be DMA read or written to by the adapter.
  1007. */
  1008. alloc_size = sizeof(PI_DESCR_BLOCK) +
  1009. PI_CMD_REQ_K_SIZE_MAX +
  1010. PI_CMD_RSP_K_SIZE_MAX +
  1011. #ifndef DYNAMIC_BUFFERS
  1012. (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
  1013. #endif
  1014. sizeof(PI_CONSUMER_BLOCK) +
  1015. (PI_ALIGN_K_DESC_BLK - 1);
  1016. bp->kmalloced = top_v = dma_zalloc_coherent(bp->bus_dev, alloc_size,
  1017. &bp->kmalloced_dma,
  1018. GFP_ATOMIC);
  1019. if (top_v == NULL)
  1020. return DFX_K_FAILURE;
  1021. top_p = bp->kmalloced_dma; /* get physical address of buffer */
  1022. /*
  1023. * To guarantee the 8K alignment required for the descriptor block, 8K - 1
  1024. * plus the amount of memory needed was allocated. The physical address
  1025. * is now 8K aligned. By carving up the memory in a specific order,
  1026. * we'll guarantee the alignment requirements for all other structures.
  1027. *
  1028. * Note: If the assumptions change regarding the non-paged, non-cached,
  1029. * physically contiguous nature of the memory block or the address
  1030. * alignments, then we'll need to implement a different algorithm
  1031. * for allocating the needed memory.
  1032. */
  1033. curr_p = ALIGN(top_p, PI_ALIGN_K_DESC_BLK);
  1034. curr_v = top_v + (curr_p - top_p);
  1035. /* Reserve space for descriptor block */
  1036. bp->descr_block_virt = (PI_DESCR_BLOCK *) curr_v;
  1037. bp->descr_block_phys = curr_p;
  1038. curr_v += sizeof(PI_DESCR_BLOCK);
  1039. curr_p += sizeof(PI_DESCR_BLOCK);
  1040. /* Reserve space for command request buffer */
  1041. bp->cmd_req_virt = (PI_DMA_CMD_REQ *) curr_v;
  1042. bp->cmd_req_phys = curr_p;
  1043. curr_v += PI_CMD_REQ_K_SIZE_MAX;
  1044. curr_p += PI_CMD_REQ_K_SIZE_MAX;
  1045. /* Reserve space for command response buffer */
  1046. bp->cmd_rsp_virt = (PI_DMA_CMD_RSP *) curr_v;
  1047. bp->cmd_rsp_phys = curr_p;
  1048. curr_v += PI_CMD_RSP_K_SIZE_MAX;
  1049. curr_p += PI_CMD_RSP_K_SIZE_MAX;
  1050. /* Reserve space for the LLC host receive queue buffers */
  1051. bp->rcv_block_virt = curr_v;
  1052. bp->rcv_block_phys = curr_p;
  1053. #ifndef DYNAMIC_BUFFERS
  1054. curr_v += (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX);
  1055. curr_p += (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX);
  1056. #endif
  1057. /* Reserve space for the consumer block */
  1058. bp->cons_block_virt = (PI_CONSUMER_BLOCK *) curr_v;
  1059. bp->cons_block_phys = curr_p;
  1060. /* Display virtual and physical addresses if debug driver */
  1061. DBG_printk("%s: Descriptor block virt = %p, phys = %pad\n",
  1062. print_name, bp->descr_block_virt, &bp->descr_block_phys);
  1063. DBG_printk("%s: Command Request buffer virt = %p, phys = %pad\n",
  1064. print_name, bp->cmd_req_virt, &bp->cmd_req_phys);
  1065. DBG_printk("%s: Command Response buffer virt = %p, phys = %pad\n",
  1066. print_name, bp->cmd_rsp_virt, &bp->cmd_rsp_phys);
  1067. DBG_printk("%s: Receive buffer block virt = %p, phys = %pad\n",
  1068. print_name, bp->rcv_block_virt, &bp->rcv_block_phys);
  1069. DBG_printk("%s: Consumer block virt = %p, phys = %pad\n",
  1070. print_name, bp->cons_block_virt, &bp->cons_block_phys);
  1071. return DFX_K_SUCCESS;
  1072. }
  1073. /*
  1074. * =================
  1075. * = dfx_adap_init =
  1076. * =================
  1077. *
  1078. * Overview:
  1079. * Brings the adapter to the link avail/link unavailable state.
  1080. *
  1081. * Returns:
  1082. * Condition code
  1083. *
  1084. * Arguments:
  1085. * bp - pointer to board information
  1086. * get_buffers - non-zero if buffers to be allocated
  1087. *
  1088. * Functional Description:
  1089. * Issues the low-level firmware/hardware calls necessary to bring
  1090. * the adapter up, or to properly reset and restore adapter during
  1091. * run-time.
  1092. *
  1093. * Return Codes:
  1094. * DFX_K_SUCCESS - Adapter brought up successfully
  1095. * DFX_K_FAILURE - Adapter initialization failed
  1096. *
  1097. * Assumptions:
  1098. * bp->reset_type should be set to a valid reset type value before
  1099. * calling this routine.
  1100. *
  1101. * Side Effects:
  1102. * Adapter should be in LINK_AVAILABLE or LINK_UNAVAILABLE state
  1103. * upon a successful return of this routine.
  1104. */
  1105. static int dfx_adap_init(DFX_board_t *bp, int get_buffers)
  1106. {
  1107. DBG_printk("In dfx_adap_init...\n");
  1108. /* Disable PDQ interrupts first */
  1109. dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  1110. /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
  1111. if (dfx_hw_dma_uninit(bp, bp->reset_type) != DFX_K_SUCCESS)
  1112. {
  1113. printk("%s: Could not uninitialize/reset adapter!\n", bp->dev->name);
  1114. return DFX_K_FAILURE;
  1115. }
  1116. /*
  1117. * When the PDQ is reset, some false Type 0 interrupts may be pending,
  1118. * so we'll acknowledge all Type 0 interrupts now before continuing.
  1119. */
  1120. dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, PI_HOST_INT_K_ACK_ALL_TYPE_0);
  1121. /*
  1122. * Clear Type 1 and Type 2 registers before going to DMA_AVAILABLE state
  1123. *
  1124. * Note: We only need to clear host copies of these registers. The PDQ reset
  1125. * takes care of the on-board register values.
  1126. */
  1127. bp->cmd_req_reg.lword = 0;
  1128. bp->cmd_rsp_reg.lword = 0;
  1129. bp->rcv_xmt_reg.lword = 0;
  1130. /* Clear consumer block before going to DMA_AVAILABLE state */
  1131. memset(bp->cons_block_virt, 0, sizeof(PI_CONSUMER_BLOCK));
  1132. /* Initialize the DMA Burst Size */
  1133. if (dfx_hw_port_ctrl_req(bp,
  1134. PI_PCTRL_M_SUB_CMD,
  1135. PI_SUB_CMD_K_BURST_SIZE_SET,
  1136. bp->burst_size,
  1137. NULL) != DFX_K_SUCCESS)
  1138. {
  1139. printk("%s: Could not set adapter burst size!\n", bp->dev->name);
  1140. return DFX_K_FAILURE;
  1141. }
  1142. /*
  1143. * Set base address of Consumer Block
  1144. *
  1145. * Assumption: 32-bit physical address of consumer block is 64 byte
  1146. * aligned. That is, bits 0-5 of the address must be zero.
  1147. */
  1148. if (dfx_hw_port_ctrl_req(bp,
  1149. PI_PCTRL_M_CONS_BLOCK,
  1150. bp->cons_block_phys,
  1151. 0,
  1152. NULL) != DFX_K_SUCCESS)
  1153. {
  1154. printk("%s: Could not set consumer block address!\n", bp->dev->name);
  1155. return DFX_K_FAILURE;
  1156. }
  1157. /*
  1158. * Set the base address of Descriptor Block and bring adapter
  1159. * to DMA_AVAILABLE state.
  1160. *
  1161. * Note: We also set the literal and data swapping requirements
  1162. * in this command.
  1163. *
  1164. * Assumption: 32-bit physical address of descriptor block
  1165. * is 8Kbyte aligned.
  1166. */
  1167. if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_INIT,
  1168. (u32)(bp->descr_block_phys |
  1169. PI_PDATA_A_INIT_M_BSWAP_INIT),
  1170. 0, NULL) != DFX_K_SUCCESS) {
  1171. printk("%s: Could not set descriptor block address!\n",
  1172. bp->dev->name);
  1173. return DFX_K_FAILURE;
  1174. }
  1175. /* Set transmit flush timeout value */
  1176. bp->cmd_req_virt->cmd_type = PI_CMD_K_CHARS_SET;
  1177. bp->cmd_req_virt->char_set.item[0].item_code = PI_ITEM_K_FLUSH_TIME;
  1178. bp->cmd_req_virt->char_set.item[0].value = 3; /* 3 seconds */
  1179. bp->cmd_req_virt->char_set.item[0].item_index = 0;
  1180. bp->cmd_req_virt->char_set.item[1].item_code = PI_ITEM_K_EOL;
  1181. if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  1182. {
  1183. printk("%s: DMA command request failed!\n", bp->dev->name);
  1184. return DFX_K_FAILURE;
  1185. }
  1186. /* Set the initial values for eFDXEnable and MACTReq MIB objects */
  1187. bp->cmd_req_virt->cmd_type = PI_CMD_K_SNMP_SET;
  1188. bp->cmd_req_virt->snmp_set.item[0].item_code = PI_ITEM_K_FDX_ENB_DIS;
  1189. bp->cmd_req_virt->snmp_set.item[0].value = bp->full_duplex_enb;
  1190. bp->cmd_req_virt->snmp_set.item[0].item_index = 0;
  1191. bp->cmd_req_virt->snmp_set.item[1].item_code = PI_ITEM_K_MAC_T_REQ;
  1192. bp->cmd_req_virt->snmp_set.item[1].value = bp->req_ttrt;
  1193. bp->cmd_req_virt->snmp_set.item[1].item_index = 0;
  1194. bp->cmd_req_virt->snmp_set.item[2].item_code = PI_ITEM_K_EOL;
  1195. if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  1196. {
  1197. printk("%s: DMA command request failed!\n", bp->dev->name);
  1198. return DFX_K_FAILURE;
  1199. }
  1200. /* Initialize adapter CAM */
  1201. if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
  1202. {
  1203. printk("%s: Adapter CAM update failed!\n", bp->dev->name);
  1204. return DFX_K_FAILURE;
  1205. }
  1206. /* Initialize adapter filters */
  1207. if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
  1208. {
  1209. printk("%s: Adapter filters update failed!\n", bp->dev->name);
  1210. return DFX_K_FAILURE;
  1211. }
  1212. /*
  1213. * Remove any existing dynamic buffers (i.e. if the adapter is being
  1214. * reinitialized)
  1215. */
  1216. if (get_buffers)
  1217. dfx_rcv_flush(bp);
  1218. /* Initialize receive descriptor block and produce buffers */
  1219. if (dfx_rcv_init(bp, get_buffers))
  1220. {
  1221. printk("%s: Receive buffer allocation failed\n", bp->dev->name);
  1222. if (get_buffers)
  1223. dfx_rcv_flush(bp);
  1224. return DFX_K_FAILURE;
  1225. }
  1226. /* Issue START command and bring adapter to LINK_(UN)AVAILABLE state */
  1227. bp->cmd_req_virt->cmd_type = PI_CMD_K_START;
  1228. if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  1229. {
  1230. printk("%s: Start command failed\n", bp->dev->name);
  1231. if (get_buffers)
  1232. dfx_rcv_flush(bp);
  1233. return DFX_K_FAILURE;
  1234. }
  1235. /* Initialization succeeded, reenable PDQ interrupts */
  1236. dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_ENABLE_DEF_INTS);
  1237. return DFX_K_SUCCESS;
  1238. }
  1239. /*
  1240. * ============
  1241. * = dfx_open =
  1242. * ============
  1243. *
  1244. * Overview:
  1245. * Opens the adapter
  1246. *
  1247. * Returns:
  1248. * Condition code
  1249. *
  1250. * Arguments:
  1251. * dev - pointer to device information
  1252. *
  1253. * Functional Description:
  1254. * This function brings the adapter to an operational state.
  1255. *
  1256. * Return Codes:
  1257. * 0 - Adapter was successfully opened
  1258. * -EAGAIN - Could not register IRQ or adapter initialization failed
  1259. *
  1260. * Assumptions:
  1261. * This routine should only be called for a device that was
  1262. * initialized successfully.
  1263. *
  1264. * Side Effects:
  1265. * Adapter should be in LINK_AVAILABLE or LINK_UNAVAILABLE state
  1266. * if the open is successful.
  1267. */
  1268. static int dfx_open(struct net_device *dev)
  1269. {
  1270. DFX_board_t *bp = netdev_priv(dev);
  1271. int ret;
  1272. DBG_printk("In dfx_open...\n");
  1273. /* Register IRQ - support shared interrupts by passing device ptr */
  1274. ret = request_irq(dev->irq, dfx_interrupt, IRQF_SHARED, dev->name,
  1275. dev);
  1276. if (ret) {
  1277. printk(KERN_ERR "%s: Requested IRQ %d is busy\n", dev->name, dev->irq);
  1278. return ret;
  1279. }
  1280. /*
  1281. * Set current address to factory MAC address
  1282. *
  1283. * Note: We've already done this step in dfx_driver_init.
  1284. * However, it's possible that a user has set a node
  1285. * address override, then closed and reopened the
  1286. * adapter. Unless we reset the device address field
  1287. * now, we'll continue to use the existing modified
  1288. * address.
  1289. */
  1290. memcpy(dev->dev_addr, bp->factory_mac_addr, FDDI_K_ALEN);
  1291. /* Clear local unicast/multicast address tables and counts */
  1292. memset(bp->uc_table, 0, sizeof(bp->uc_table));
  1293. memset(bp->mc_table, 0, sizeof(bp->mc_table));
  1294. bp->uc_count = 0;
  1295. bp->mc_count = 0;
  1296. /* Disable promiscuous filter settings */
  1297. bp->ind_group_prom = PI_FSTATE_K_BLOCK;
  1298. bp->group_prom = PI_FSTATE_K_BLOCK;
  1299. spin_lock_init(&bp->lock);
  1300. /* Reset and initialize adapter */
  1301. bp->reset_type = PI_PDATA_A_RESET_M_SKIP_ST; /* skip self-test */
  1302. if (dfx_adap_init(bp, 1) != DFX_K_SUCCESS)
  1303. {
  1304. printk(KERN_ERR "%s: Adapter open failed!\n", dev->name);
  1305. free_irq(dev->irq, dev);
  1306. return -EAGAIN;
  1307. }
  1308. /* Set device structure info */
  1309. netif_start_queue(dev);
  1310. return 0;
  1311. }
  1312. /*
  1313. * =============
  1314. * = dfx_close =
  1315. * =============
  1316. *
  1317. * Overview:
  1318. * Closes the device/module.
  1319. *
  1320. * Returns:
  1321. * Condition code
  1322. *
  1323. * Arguments:
  1324. * dev - pointer to device information
  1325. *
  1326. * Functional Description:
  1327. * This routine closes the adapter and brings it to a safe state.
  1328. * The interrupt service routine is deregistered with the OS.
  1329. * The adapter can be opened again with another call to dfx_open().
  1330. *
  1331. * Return Codes:
  1332. * Always return 0.
  1333. *
  1334. * Assumptions:
  1335. * No further requests for this adapter are made after this routine is
  1336. * called. dfx_open() can be called to reset and reinitialize the
  1337. * adapter.
  1338. *
  1339. * Side Effects:
  1340. * Adapter should be in DMA_UNAVAILABLE state upon completion of this
  1341. * routine.
  1342. */
  1343. static int dfx_close(struct net_device *dev)
  1344. {
  1345. DFX_board_t *bp = netdev_priv(dev);
  1346. DBG_printk("In dfx_close...\n");
  1347. /* Disable PDQ interrupts first */
  1348. dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  1349. /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
  1350. (void) dfx_hw_dma_uninit(bp, PI_PDATA_A_RESET_M_SKIP_ST);
  1351. /*
  1352. * Flush any pending transmit buffers
  1353. *
  1354. * Note: It's important that we flush the transmit buffers
  1355. * BEFORE we clear our copy of the Type 2 register.
  1356. * Otherwise, we'll have no idea how many buffers
  1357. * we need to free.
  1358. */
  1359. dfx_xmt_flush(bp);
  1360. /*
  1361. * Clear Type 1 and Type 2 registers after adapter reset
  1362. *
  1363. * Note: Even though we're closing the adapter, it's
  1364. * possible that an interrupt will occur after
  1365. * dfx_close is called. Without some assurance to
  1366. * the contrary we want to make sure that we don't
  1367. * process receive and transmit LLC frames and update
  1368. * the Type 2 register with bad information.
  1369. */
  1370. bp->cmd_req_reg.lword = 0;
  1371. bp->cmd_rsp_reg.lword = 0;
  1372. bp->rcv_xmt_reg.lword = 0;
  1373. /* Clear consumer block for the same reason given above */
  1374. memset(bp->cons_block_virt, 0, sizeof(PI_CONSUMER_BLOCK));
  1375. /* Release all dynamically allocate skb in the receive ring. */
  1376. dfx_rcv_flush(bp);
  1377. /* Clear device structure flags */
  1378. netif_stop_queue(dev);
  1379. /* Deregister (free) IRQ */
  1380. free_irq(dev->irq, dev);
  1381. return 0;
  1382. }
  1383. /*
  1384. * ======================
  1385. * = dfx_int_pr_halt_id =
  1386. * ======================
  1387. *
  1388. * Overview:
  1389. * Displays halt id's in string form.
  1390. *
  1391. * Returns:
  1392. * None
  1393. *
  1394. * Arguments:
  1395. * bp - pointer to board information
  1396. *
  1397. * Functional Description:
  1398. * Determine current halt id and display appropriate string.
  1399. *
  1400. * Return Codes:
  1401. * None
  1402. *
  1403. * Assumptions:
  1404. * None
  1405. *
  1406. * Side Effects:
  1407. * None
  1408. */
  1409. static void dfx_int_pr_halt_id(DFX_board_t *bp)
  1410. {
  1411. PI_UINT32 port_status; /* PDQ port status register value */
  1412. PI_UINT32 halt_id; /* PDQ port status halt ID */
  1413. /* Read the latest port status */
  1414. dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
  1415. /* Display halt state transition information */
  1416. halt_id = (port_status & PI_PSTATUS_M_HALT_ID) >> PI_PSTATUS_V_HALT_ID;
  1417. switch (halt_id)
  1418. {
  1419. case PI_HALT_ID_K_SELFTEST_TIMEOUT:
  1420. printk("%s: Halt ID: Selftest Timeout\n", bp->dev->name);
  1421. break;
  1422. case PI_HALT_ID_K_PARITY_ERROR:
  1423. printk("%s: Halt ID: Host Bus Parity Error\n", bp->dev->name);
  1424. break;
  1425. case PI_HALT_ID_K_HOST_DIR_HALT:
  1426. printk("%s: Halt ID: Host-Directed Halt\n", bp->dev->name);
  1427. break;
  1428. case PI_HALT_ID_K_SW_FAULT:
  1429. printk("%s: Halt ID: Adapter Software Fault\n", bp->dev->name);
  1430. break;
  1431. case PI_HALT_ID_K_HW_FAULT:
  1432. printk("%s: Halt ID: Adapter Hardware Fault\n", bp->dev->name);
  1433. break;
  1434. case PI_HALT_ID_K_PC_TRACE:
  1435. printk("%s: Halt ID: FDDI Network PC Trace P