Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1656 lines
43 KiB

4 years ago
  1. /****************************************************************************
  2. *
  3. * DRV_INIT.C : Part of the FASTMAC TOOL-KIT (FTK)
  4. *
  5. * THE DRIVER MODULE (INITIALIZE / REMOVE)
  6. *
  7. * Copyright (c) Madge Networks Ltd. 1991-1994
  8. *
  9. * COMPANY CONFIDENTIAL
  10. *
  11. *****************************************************************************
  12. *
  13. * The driver module provides a simple interface to allow the use of
  14. * Fastmac in as general a setting as possible. It handles the downloading
  15. * of the Fastmac code and the initialization of the adapter card. It
  16. * provides simple transmit and receive routines. It is desgined to
  17. * quickly allow the implementation of Fastmac applications. It is not
  18. * designed as the fastest or most memory efficient solution.
  19. *
  20. * The DRV_INIT.C module contains the routines necessary to initialize
  21. * Fastmac and the adapter and remove, ie. terminate usage of, the
  22. * adapter. Upon adapter initialization the user is returned a handle
  23. * which is used to identify the adapter in all future accesses to the
  24. * driver module.
  25. *
  26. ****************************************************************************/
  27. /*---------------------------------------------------------------------------
  28. |
  29. | DEFINITIONS
  30. |
  31. ---------------------------------------------------------------------------*/
  32. #include "ftk_defs.h"
  33. /*---------------------------------------------------------------------------
  34. |
  35. | MODULE ENTRY POINTS
  36. |
  37. ---------------------------------------------------------------------------*/
  38. #include "ftk_intr.h" /* routines internal to FTK */
  39. #include "ftk_extr.h" /* routines provided or used by external FTK user */
  40. /*---------------------------------------------------------------------------
  41. |
  42. | LOCAL FUNCTIONS
  43. |
  44. ---------------------------------------------------------------------------*/
  45. local WBOOLEAN
  46. driver_wait_for_adapter_open(
  47. UINT * open_status,
  48. ADAPTER * adapter
  49. );
  50. local WORD
  51. driver_get_max_frame_size(
  52. ADAPTER * adapter,
  53. FASTMAC_INIT_PARMS * fastmac_parms
  54. );
  55. /*---------------------------------------------------------------------------
  56. |
  57. | GLOBAL VARIABLES
  58. |
  59. ---------------------------------------------------------------------------*/
  60. export ADAPTER * adapter_record[MAX_NUMBER_OF_ADAPTERS] = {NULL};
  61. #ifndef FTK_NO_PROBE
  62. /****************************************************************************
  63. *
  64. * driver_probe_card
  65. * =================
  66. *
  67. *
  68. * PARAMETERS :
  69. * ============
  70. *
  71. * WORD adapter_card_bus_type
  72. *
  73. * The bus type (card family) the adapters for which to search. e.g.
  74. * ADAPTER_CARD_ATULA_BUS_TYPE or ADAPTER_CARD_EISA_BUS_TYPE.
  75. *
  76. * PROBE * resources
  77. *
  78. * resources is an array structures used to identify and record specific
  79. * information about adapters found.
  80. *
  81. * UINT length
  82. *
  83. * length is the number of structures pointed to by reources.
  84. *
  85. * WORD * valid_locations
  86. *
  87. * valid_locations is an array of IO locations to examine for the presence
  88. * of an adapter. For ATULA based adapters with should be a subset of
  89. * {0x0a20, 0x1a20, 0x2a20, 0x3a20}.
  90. *
  91. * UINT number_locations
  92. *
  93. * This is the number of IO locations in the above list.
  94. *
  95. * BODY :
  96. * ======
  97. *
  98. * The hwi_atula_probe_card routine is called by hwi_probe_adapter. It
  99. * probes the adapter card for information such as DMA channel, IRQ number
  100. * etc. This information can then be supplied by the user when starting the
  101. * adapter.
  102. *
  103. *
  104. * RETURNS :
  105. * =========
  106. *
  107. * The routine returns the number of adapters found, or PROBE_FAILURE
  108. * if there's a problem.
  109. *
  110. ****************************************************************************/
  111. #ifdef FTK_INIT_FUNCTION
  112. #pragma FTK_INIT_FUNCTION(driver_probe_adapter)
  113. #endif
  114. export UINT
  115. driver_probe_adapter(
  116. WORD adapter_card_bus_type,
  117. PROBE * resources,
  118. UINT length,
  119. WORD * valid_locations,
  120. UINT number_locations
  121. )
  122. {
  123. return hwi_probe_adapter(
  124. adapter_card_bus_type,
  125. resources,
  126. length,
  127. valid_locations,
  128. number_locations
  129. );
  130. }
  131. /****************************************************************************
  132. *
  133. * driver_deprobe_adapter
  134. * ======================
  135. *
  136. * PARAMETERS :
  137. * ============
  138. *
  139. * PROBE * resources
  140. *
  141. * resources is an array structures used to identify and record specific
  142. * information about adapters found.
  143. *
  144. * UINT length
  145. *
  146. * length is the number of structures pointed to by reources.
  147. *
  148. * BODY :
  149. * ======
  150. *
  151. * This function frees any resources that were claimed by a call to
  152. * driver_probe_adapter. Every valid PROBE structure returned by
  153. * driver_probe_adapter MUST be passed to driver_deprobe adapter otherwise
  154. * resources that were claimed from the operating system by
  155. * driver_probe_adapter (such as PCMCIA sockets) will not be freed.
  156. *
  157. * RETURNS :
  158. * =========
  159. *
  160. * TRUE if everything worked or FALSE if it did not.
  161. *
  162. ****************************************************************************/
  163. #ifdef FTK_RES_FUNCTION
  164. #pragma FTK_RES_FUNCTION(driver_deprobe_adapter)
  165. #endif
  166. export WBOOLEAN
  167. driver_deprobe_adapter(
  168. PROBE * resources,
  169. UINT length
  170. )
  171. {
  172. return hwi_deprobe_adapter(
  173. resources,
  174. length
  175. );
  176. }
  177. #endif
  178. /****************************************************************************
  179. *
  180. * driver_prepare_adapter
  181. * ======================
  182. *
  183. *
  184. * PARAMETERS :
  185. * ============
  186. *
  187. * PREPARE_ARGS * arguments
  188. *
  189. * This is a pointer to the arguments structure set up by the user code.
  190. *
  191. * ADAPTER_HANDLE * returned_adapter_handle
  192. *
  193. * An adapter handle is returned that is used for all subsequent calls to
  194. * the driver to identify the particular adapter.
  195. *
  196. * BODY :
  197. * ======
  198. *
  199. * The driver_prepare_adapter routine firstly sets up the adapter structure
  200. * for this adapter. Then it gets memory for the status information
  201. * structure that is filled in by driver_get_status calls. It then
  202. * requests memory for the Fastmac transmit and receive buffers. This memory
  203. * must be static, it must not be swapped out to disk because of DMA issues.
  204. *
  205. * This routine should be called once for every adapter that is to have
  206. * Fastmac used on it.
  207. *
  208. * RETURNS :
  209. * =========
  210. *
  211. * The routine returns TRUE if it succeeds. If this routine fails (returns
  212. * FALSE) then a subsequent call to driver_explain_error with the returned
  213. * adapter handle will give an explanation.
  214. *
  215. ****************************************************************************/
  216. #ifdef FTK_INIT_FUNCTION
  217. #pragma FTK_INIT_FUNCTION(driver_prepare_adapter)
  218. #endif
  219. export WBOOLEAN
  220. driver_prepare_adapter(
  221. PREPARE_ARGS * arguments,
  222. ADAPTER_HANDLE * returned_adapter_handle
  223. )
  224. {
  225. ADAPTER_HANDLE adapter_handle;
  226. ADAPTER * adapter;
  227. FASTMAC_INIT_PARMS * fastmac_parms;
  228. WORD i;
  229. /*
  230. * Set up adapter handle which is an index to an array of pointers.
  231. * Find first a pointer not yet used.
  232. */
  233. for (i = 0; i < MAX_NUMBER_OF_ADAPTERS; i++)
  234. {
  235. if (adapter_record[i] == NULL)
  236. {
  237. break;
  238. }
  239. }
  240. /*
  241. * Set up returned adapter handle ( = index to adapter structure).
  242. * returned_adapter_handle is set up here before any failure.
  243. * This is so can use adapter handle for call to driver_explain_error.
  244. */
  245. adapter_handle = (ADAPTER_HANDLE) i;
  246. *returned_adapter_handle = adapter_handle;
  247. /*
  248. * If all pointers to adapter structures are used then return error.
  249. * Can not set up error record but see driver_explain_error.
  250. */
  251. if (i == MAX_NUMBER_OF_ADAPTERS)
  252. {
  253. return FALSE;
  254. }
  255. /*
  256. * Get memory for adapter structure.
  257. */
  258. adapter_record[adapter_handle] = (ADAPTER *)
  259. sys_alloc_adapter_structure(adapter_handle, sizeof(ADAPTER));
  260. /*
  261. * Check that the memory allocation was successful. Can not set up
  262. * error record but see driver_explain_error.
  263. */
  264. if (adapter_record[adapter_handle] == NULL)
  265. {
  266. return FALSE;
  267. }
  268. /*
  269. * Remember pointer to adapter structure.
  270. */
  271. adapter = adapter_record[adapter_handle];
  272. /*
  273. * Zero adapter structure memory.
  274. */
  275. util_zero_memory((BYTE *) adapter, sizeof(ADAPTER));
  276. /*
  277. * Save handle, so that HWI routines that need it can find it.
  278. */
  279. adapter->adapter_handle = adapter_handle;
  280. /*
  281. * Save the user's private information for the users sys_ functions.
  282. */
  283. adapter->user_information = arguments->user_information;
  284. #ifdef FMPLUS
  285. /*
  286. * Allocate memory for the FastMAC Plus to do its DMA tests.
  287. * This is now a byte longer to allocate the byte used
  288. * to handshake the DMA on a PCI(T) card with broken DMA.
  289. */
  290. if (!sys_alloc_dma_phys_buffer(
  291. adapter_handle,
  292. SCB_TEST_PATTERN_LENGTH + SSB_TEST_PATTERN_LENGTH + 1,
  293. &(adapter->dma_test_buf_phys),
  294. &(adapter->dma_test_buf_virt)))
  295. {
  296. adapter->error_record.type = ERROR_TYPE_DRIVER;
  297. adapter->error_record.value = DRIVER_E_12_FAIL_ALLOC_DMA_BUF;
  298. return FALSE;
  299. }
  300. #endif
  301. /*
  302. * Indicate no errors have occured for this adapter yet.
  303. */
  304. adapter->error_record.type = ERROR_TYPE_NONE;
  305. /*
  306. * Get memory for status information structure.
  307. */
  308. adapter->status_info = (STATUS_INFORMATION *)
  309. sys_alloc_status_structure(adapter_handle,sizeof(STATUS_INFORMATION));
  310. /*
  311. * Check that the memory allocation was successful.
  312. */
  313. if (adapter->status_info == NULL)
  314. {
  315. adapter->error_record.type = ERROR_TYPE_DRIVER;
  316. adapter->error_record.value = DRIVER_E_03_FAIL_ALLOC_STATUS;
  317. return FALSE;
  318. }
  319. /*
  320. * Zero status information structure memory.
  321. */
  322. util_zero_memory(
  323. (BYTE *) adapter->status_info,
  324. sizeof(STATUS_INFORMATION)
  325. );
  326. /*
  327. * Get memory for initialization block.
  328. */
  329. adapter->init_block = (INITIALIZATION_BLOCK *)
  330. sys_alloc_init_block(adapter_handle, sizeof(INITIALIZATION_BLOCK));
  331. /*
  332. * Check that the memory allocation was successful.
  333. */
  334. if (adapter->init_block == NULL)
  335. {
  336. adapter->error_record.type = ERROR_TYPE_DRIVER;
  337. adapter->error_record.value = DRIVER_E_04_FAIL_ALLOC_INIT;
  338. return FALSE;
  339. }
  340. /*
  341. * Zero initialization block memory.
  342. */
  343. util_zero_memory(
  344. (BYTE *) adapter->init_block,
  345. sizeof(INITIALIZATION_BLOCK)
  346. );
  347. /*
  348. * Get pointer to Fastmac init parameters for this adapter.
  349. */
  350. fastmac_parms = &adapter->init_block->fastmac_parms;
  351. /*
  352. * Ensure that the fastmac_parms->features reserved bits and the
  353. * fastmac_parms->int_flags reserved bits are zero (bits 4,11-15
  354. * of features, and bits 3-15 of int_flags).
  355. * (In fact they will be already from the above util_zero_memory.)
  356. */
  357. /*
  358. * Now fill in all of the hardware independant non-zero fields in the
  359. * Fastmac part of init block.
  360. */
  361. /*
  362. * Check that the frame size requested in within the bounds
  363. * of possibility.
  364. */
  365. if (arguments->max_frame_size < MIN_FRAME_SIZE ||
  366. arguments->max_frame_size > MAX_FRAME_SIZE_16_MBITS)
  367. {
  368. adapter->error_record.type = ERROR_TYPE_DRIVER;
  369. adapter->error_record.value = DRIVER_E_13_BAD_FRAME_SIZE;
  370. return FALSE;
  371. }
  372. /*
  373. * Make a note of the maximum frame size requested.
  374. */
  375. fastmac_parms->max_frame_size = arguments->max_frame_size;
  376. #ifndef FMPLUS
  377. /*
  378. * Set up the header.
  379. */
  380. fastmac_parms->header.length = sizeof(FASTMAC_INIT_PARMS);
  381. fastmac_parms->header.signature = FASTMAC_INIT_HEADER_SIGNATURE;
  382. fastmac_parms->header.version = FASTMAC_INIT_HEADER_VERSION;
  383. /*
  384. * Now set up the interrupt options.
  385. */
  386. #ifdef FTK_TX_WITH_COMPLETION
  387. fastmac_parms->int_flags |= INT_FLAG_TX_BUF_EMPTY;
  388. #endif
  389. /*
  390. * Check have sensible value for Fastmac receive buffer size.
  391. */
  392. if ((arguments->receive_buffer_byte_size < FASTMAC_MINIMUM_BUFFER_SIZE) ||
  393. (arguments->receive_buffer_byte_size > FASTMAC_MAXIMUM_BUFFER_SIZE))
  394. {
  395. adapter->error_record.type = ERROR_TYPE_DRIVER;
  396. adapter->error_record.value = DRIVER_E_0A_RX_BUF_BAD_SIZE;
  397. return FALSE;
  398. }
  399. /*
  400. * Get memory for the receive buffer.
  401. */
  402. if (!sys_alloc_dma_phys_buffer(
  403. adapter_handle,
  404. arguments->receive_buffer_byte_size,
  405. &adapter->rx_buffer_phys,
  406. &adapter->rx_buffer_virt))
  407. {
  408. adapter->error_record.type = ERROR_TYPE_DRIVER;
  409. adapter->error_record.value = DRIVER_E_05_FAIL_ALLOC_RX_BUF;
  410. return FALSE;
  411. }
  412. fastmac_parms->rx_buf_physaddr = adapter->rx_buffer_phys;
  413. /*
  414. * Check that Fastmac receive buffer begins on a DWORD boundary.
  415. */
  416. if ((fastmac_parms->rx_buf_physaddr & 0x00000003) != 0L)
  417. {
  418. adapter->error_record.type = ERROR_TYPE_DRIVER;
  419. adapter->error_record.value = DRIVER_E_0B_RX_BUF_NOT_DWORD;
  420. return FALSE;
  421. }
  422. /*
  423. * Fill in Fastmac receive buffer size.
  424. */
  425. fastmac_parms->rx_buf_size = arguments->receive_buffer_byte_size;
  426. /*
  427. * Check have sensible value for Fastmac transmit buffer size.
  428. */
  429. if ((arguments->transmit_buffer_byte_size < FASTMAC_MINIMUM_BUFFER_SIZE) ||
  430. (arguments->transmit_buffer_byte_size > FASTMAC_MAXIMUM_BUFFER_SIZE))
  431. {
  432. adapter->error_record.type = ERROR_TYPE_DRIVER;
  433. adapter->error_record.value = DRIVER_E_0C_TX_BUF_BAD_SIZE;
  434. return FALSE;
  435. }
  436. /*
  437. * Get memory for the transmit buffer.
  438. */
  439. if (!sys_alloc_dma_phys_buffer(
  440. adapter_handle,
  441. arguments->receive_buffer_byte_size,
  442. &adapter->tx_buffer_phys,
  443. &adapter->tx_buffer_virt))
  444. {
  445. adapter->error_record.type = ERROR_TYPE_DRIVER;
  446. adapter->error_record.value = DRIVER_E_06_FAIL_ALLOC_TX_BUF;
  447. return FALSE;
  448. }
  449. fastmac_parms->tx_buf_physaddr = adapter->tx_buffer_phys;
  450. /*
  451. * Check that Fastmac transmit buffer begins on a DWORD boundary.
  452. */
  453. if ((fastmac_parms->tx_buf_physaddr & 0x00000003) != 0L)
  454. {
  455. adapter->error_record.type = ERROR_TYPE_DRIVER;
  456. adapter->error_record.value = DRIVER_E_0D_TX_BUF_NOT_DWORD;
  457. return FALSE;
  458. }
  459. /*
  460. * Fill in Fastmac transmit buffer size.
  461. */
  462. fastmac_parms->tx_buf_size = arguments->transmit_buffer_byte_size;
  463. /*
  464. * Mark adapter structure as containing details of initialized Fastmac
  465. * and indicate that SRB is free.
  466. */
  467. adapter->adapter_status = ADAPTER_PREPARED_FOR_START;
  468. adapter->srb_status = SRB_FREE;
  469. #else
  470. /*
  471. * Set set up the header.
  472. */
  473. fastmac_parms->header.length = sizeof(FASTMAC_INIT_PARMS);
  474. fastmac_parms->header.signature = FMPLUS_INIT_HEADER_SIGNATURE;
  475. fastmac_parms->header.version = FMPLUS_INIT_HEADER_VERSION;
  476. /*
  477. * Now set up the interrupt options.
  478. */
  479. #ifdef FTK_RX_OUT_OF_INTERRUPTS
  480. fastmac_parms->int_flags |= INT_FLAG_RX;
  481. #endif
  482. #ifdef FTK_RX_BY_SCHEDULED_PROCESS
  483. fastmac_parms->int_flags |= INT_FLAG_RX;
  484. #endif
  485. #ifdef FTK_TX_WITH_COMPLETION
  486. fastmac_parms->int_flags |= INT_FLAG_LARGE_DMA;
  487. #endif
  488. /*
  489. * Now fill in the number of slots that are required. These are user
  490. * specified, since the numbers are host dependent (each slot must have
  491. * a maximum frame sized buffer on the host).
  492. */
  493. if (arguments->number_of_rx_slots < FMPLUS_MIN_RX_SLOTS ||
  494. arguments->number_of_rx_slots > FMPLUS_MAX_RX_SLOTS)
  495. {
  496. adapter->error_record.type = ERROR_TYPE_DRIVER;
  497. adapter->error_record.value = DRIVER_E_10_BAD_RX_SLOT_NUMBER;
  498. return FALSE;
  499. }
  500. fastmac_parms->rx_slots = arguments->number_of_rx_slots;
  501. if (arguments->number_of_tx_slots < FMPLUS_MIN_TX_SLOTS ||
  502. arguments->number_of_tx_slots > FMPLUS_MAX_TX_SLOTS)
  503. {
  504. adapter->error_record.type = ERROR_TYPE_DRIVER;
  505. adapter->error_record.value = DRIVER_E_11_BAD_TX_SLOT_NUMBER;
  506. return FALSE;
  507. }
  508. fastmac_parms->tx_slots = arguments->number_of_tx_slots;
  509. /*
  510. * Allocate the receive slot buffers.
  511. */
  512. if (!rxtx_allocate_rx_buffers(
  513. adapter,
  514. arguments->max_frame_size,
  515. arguments->number_of_rx_slots
  516. ))
  517. {
  518. adapter->error_record.type = ERROR_TYPE_DRIVER;
  519. adapter->error_record.value = DRIVER_E_05_FAIL_ALLOC_RX_BUF;
  520. return FALSE;
  521. }
  522. /*
  523. * Allocate the transmit slot buffers.
  524. */
  525. if (!rxtx_allocate_tx_buffers(
  526. adapter,
  527. arguments->max_frame_size,
  528. arguments->number_of_tx_slots
  529. ))
  530. {
  531. adapter->error_record.type = ERROR_TYPE_DRIVER;
  532. adapter->error_record.value = DRIVER_E_06_FAIL_ALLOC_TX_BUF;
  533. return FALSE;
  534. }
  535. /*
  536. * Mark adapter structure as containing details of initialized Fastmac
  537. * and indicate that SRB is free.
  538. */
  539. adapter->adapter_status = ADAPTER_PREPARED_FOR_START;
  540. adapter->srb_status = SRB_FREE;
  541. #endif
  542. /*
  543. * Complete successfully.
  544. */
  545. return TRUE;
  546. }
  547. /****************************************************************************
  548. *
  549. * driver_start_adapter
  550. * ====================
  551. *
  552. * PARAMETERS :
  553. * ============
  554. *
  555. * ADAPTER_HANDLE adapter_handle
  556. *
  557. * This handle identifies the adapter to be initialized. This should be a
  558. * handle returned by a call to driver_prepare_adapter.
  559. *
  560. * START_ARGS * arguments
  561. *
  562. * This is a pointer to the arguments structure set up by the user code.
  563. *
  564. * NODE_ADDRESS * returned_permanent_address
  565. *
  566. * The node address pointed to is always filled in with the BIA PROM node
  567. * address of the adapter. This is so the user of the FTK can fill in MAC
  568. * headers etc. with the source node address (unless the user has supplied
  569. * an opening address to driver_prepare_adapter which they should then use
  570. * instead).
  571. *
  572. *
  573. * BODY :
  574. * ======
  575. *
  576. * The driver_start_adapter routine is called once per adapter after a call
  577. * to driver_prepare_adapter. It takes the user supplied adapter
  578. * information and passes it in a form usable by the HWI so that the HWI
  579. * can install and then initialize the adapter (that is initialize
  580. * registers on the card, download the Fastmac image and set up the IRQ and
  581. * DMA channels if necessary). After initialization, this routine waits for
  582. * the adapter to open if the auto-open option is enabled.
  583. *
  584. * RETURNS :
  585. * =========
  586. *
  587. * The routine returns TRUE if it succeeds. If this routine fails (returns
  588. * FALSE) then a subsequent call to driver_explain_error with the same
  589. * adapter handle will give an explanation.
  590. *
  591. ****************************************************************************/
  592. #ifdef FTK_INIT_FUNCTION
  593. #pragma FTK_INIT_FUNCTION(driver_start_adapter)
  594. #endif
  595. export WBOOLEAN
  596. driver_start_adapter(
  597. ADAPTER_HANDLE adapter_handle,
  598. START_ARGS * arguments,
  599. NODE_ADDRESS * returned_permanent_address
  600. )
  601. {
  602. ADAPTER * adapter;
  603. FASTMAC_INIT_PARMS * fastmac_parms;
  604. WBOOLEAN init_success;
  605. WORD max_frame_size;
  606. UINT i;
  607. #ifdef FMPLUS
  608. RX_SLOT * next_rx_slot;
  609. TX_SLOT * next_tx_slot;
  610. RX_SLOT * * rx_slot_array;
  611. TX_SLOT * * tx_slot_array;
  612. UINT slot_index;
  613. #endif
  614. /*
  615. * Check adapter handle and status of adapter for validity.
  616. * If routine fails return failure (error record already filled in).
  617. */
  618. if (!driver_check_adapter(
  619. adapter_handle,
  620. ADAPTER_PREPARED_FOR_START,
  621. SRB_ANY_STATE
  622. ))
  623. {
  624. return FALSE;
  625. }
  626. /*
  627. * Get pointer to adapter structure.
  628. */
  629. adapter = adapter_record[adapter_handle];
  630. /*
  631. * Fill user supplied info into adapter structure.
  632. */
  633. adapter->mmio_base_address = arguments->mmio_base_address;
  634. adapter->adapter_card_bus_type = arguments->adapter_card_bus_type;
  635. adapter->io_location = arguments->io_location;
  636. adapter->dma_channel = arguments->dma_channel;
  637. adapter->transfer_mode = arguments->transfer_mode;
  638. adapter->interrupt_number = arguments->interrupt_number;
  639. adapter->set_dma = arguments->set_dma_channel;
  640. adapter->set_irq = arguments->set_interrupt_number;
  641. adapter->set_ring_speed = arguments->set_ring_speed;
  642. adapter->download_image = arguments->code;
  643. adapter->pci_handle = arguments->pci_handle;
  644. #ifdef FMPLUS
  645. /*
  646. * Need these values later.
  647. */
  648. rx_slot_array = adapter->rx_slot_array;
  649. tx_slot_array = adapter->tx_slot_array;
  650. #endif
  651. /*
  652. * Call the HWI routine to install the adapter. This also downloads
  653. * the Fastmac image to the adapter. If routine fails return failure
  654. * (error record already filled in). DMA and IRQ are only enabled
  655. * if hwi_install_adapter succeeds.
  656. */
  657. /*
  658. * WARNING: we must mark the adapter as running NOW, before downloading
  659. * the microcode, because on AT cards in PIO mode ONLY, bring
  660. * up diagnostics on the card fail when carrying out DMA tests.
  661. * This occurs because the interrupt handling routine ignores
  662. * all interrupts from the card until it is marked as running,
  663. * but this unfortunately masks off PIO interrupts too.
  664. */
  665. /*
  666. * Mark adapter structure that adapter is now going to be running.
  667. * Hence hwi_interrupt_entry will check adapter for interrupts
  668. */
  669. adapter->adapter_status = ADAPTER_RUNNING;
  670. if (!hwi_install_adapter(adapter, adapter->download_image))
  671. {
  672. /*
  673. * Now that initial installation has failed, we can turn off the
  674. * above indication that the card is running.
  675. */
  676. adapter->adapter_status = ADAPTER_PREPARED_FOR_START;
  677. return FALSE;
  678. }
  679. /*
  680. * Get pointer to Fastmac init parameters for this adapter.
  681. */
  682. fastmac_parms = &adapter->init_block->fastmac_parms;
  683. /*
  684. * Now fill in max frame size in init block that Fastmac should support.
  685. * This is based on the size of the Fastmac buffers and
  686. * max frame size supported by adapter because of ring speed. We
  687. * put the requested max frame is into fastmac_parms->max_frame_size
  688. * in driver_prepare_adapter.
  689. */
  690. max_frame_size = driver_get_max_frame_size(adapter, fastmac_parms);
  691. fastmac_parms->max_frame_size =
  692. min(max_frame_size, fastmac_parms->max_frame_size);
  693. /*
  694. * Write the actual max frame size back up to the caller, so they know
  695. * what it is too.
  696. */
  697. arguments->max_frame_size = fastmac_parms->max_frame_size;
  698. #ifdef FMPLUS
  699. /*
  700. * Set up the user selected RX/TX buffer size. This will be changed
  701. * in hwi_gen.c if the value given is not sensible.
  702. */
  703. adapter->init_block->smart_parms.rx_tx_buffer_size =
  704. arguments->rx_tx_buffer_size;
  705. #endif
  706. /*
  707. * If auto open option is on then put necessary info into init block.
  708. */
  709. if (arguments->auto_open_option)
  710. {
  711. #ifndef FMPLUS
  712. /*
  713. * Use delay_rx to prevent race condition occuring whereby
  714. * on auto-open an interrupt could occur before the host
  715. * code has had a chance to read the location of the status
  716. * block on the card. The other half of the code to fix this
  717. * problem is in driver_start_adapter, where the ARB is freed.
  718. */
  719. fastmac_parms->feature_flags =
  720. FEATURE_FLAG_AUTO_OPEN | FEATURE_FLAG_DELAY_RX;
  721. #else
  722. fastmac_parms->feature_flags = FEATURE_FLAG_AUTO_OPEN;
  723. #endif
  724. fastmac_parms->open_options = arguments->open_options;
  725. /*
  726. * Check if auto-opening node address is set (ie. not all zeroes).
  727. */
  728. for (i = 0; i < sizeof(NODE_ADDRESS); i++)
  729. {
  730. if (arguments->opening_node_address.byte[i] != 0)
  731. {
  732. break;
  733. }
  734. }
  735. /*
  736. * If opening node address not set up use BIA PROM address.
  737. */
  738. if (i == sizeof(NODE_ADDRESS))
  739. {
  740. fastmac_parms->open_address = adapter->permanent_address;
  741. }
  742. else
  743. {
  744. fastmac_parms->open_address = arguments->opening_node_address;
  745. }
  746. fastmac_parms->group_address = arguments->opening_group_address;
  747. fastmac_parms->functional_address = arguments->opening_functional_address;
  748. }
  749. /*
  750. * Call the HWI routine to initialize the adapter. This downloads the
  751. * init block to the adapter. Leaves EAGLE_SIFADRX=0x0001 so driver
  752. * never use extended SIF regs. If routine fails return failure
  753. * (error record already filled in).
  754. */
  755. if (!hwi_initialize_adapter(adapter, adapter->init_block))
  756. {
  757. return FALSE;
  758. }
  759. /*
  760. * At this stage the actual adapter card type is known.
  761. * Get the IO location of the first SIF register for the adapter.
  762. * Inform the system about the IO ports we are going to access.
  763. */
  764. #ifndef FTK_NO_IO_ENABLE
  765. macro_enable_io(adapter);
  766. #endif
  767. /*
  768. * Get the DIO addresses of the Fastmac SSB and STB (ststus block).
  769. * Only use non-extended SIF regs (EAGLE_SIFADR and EAGLE_SIFDAT_INC).
  770. * Hence can use same code for all adapter card types.
  771. */
  772. sys_outsw(adapter_handle, adapter->sif_adr, DIO_LOCATION_SRB_POINTER);
  773. adapter->srb_dio_addr = (SRB_HEADER *) (card_t)
  774. sys_insw(adapter_handle, adapter->sif_datinc);
  775. sys_outsw(adapter_handle, adapter->sif_adr, DIO_LOCATION_STB_POINTER);
  776. adapter->stb_dio_addr = (FASTMAC_STATUS_BLOCK *) (card_t)
  777. sys_insw(adapter_handle, adapter->sif_datinc);
  778. #ifndef FMPLUS
  779. /*
  780. * In the case of auto-open :
  781. * Free the ARB to enable data to be received from here on... This only
  782. * occurs now because it is only now that we know where to look for the
  783. * pointers in the status block that will tell us whether data has come
  784. * in or not.
  785. */
  786. if (arguments->auto_open_option)
  787. {
  788. sys_outsw(adapter_handle, adapter->sif_int, EAGLE_ARB_FREE_CODE);
  789. }
  790. #else
  791. /*
  792. * Now recover the receive slot and transmit slot chains.
  793. */
  794. /*
  795. * Start with the receive slot chain. We must poll the location in the
  796. * status block that holds the start address until it is non-zero. It
  797. * is then safe to run down the chain finding the other slots.
  798. */
  799. sys_outsw(
  800. adapter_handle,
  801. adapter->sif_adr,
  802. (WORD) (card_t) &adapter->stb_dio_addr->rx_slot_start
  803. );
  804. /*
  805. * Poll this address until it is non-zero.
  806. */
  807. do
  808. {
  809. rx_slot_array[0] = (RX_SLOT *) (card_t)
  810. sys_insw(adapter_handle, adapter->sif_dat);
  811. }
  812. while (rx_slot_array[0] == 0);
  813. /*
  814. * Recover all the other slots by running down the chain.
  815. */
  816. slot_index = 0;
  817. do
  818. {
  819. sys_outsw(
  820. adapter_handle,
  821. adapter->sif_adr,
  822. (WORD) (card_t) &rx_slot_array[slot_index]->next_slot
  823. );
  824. next_rx_slot = (RX_SLOT *) (card_t)
  825. sys_insw(adapter_handle, adapter->sif_dat);
  826. if (next_rx_slot != rx_slot_array[0])
  827. {
  828. rx_slot_array[++slot_index] = next_rx_slot;
  829. }
  830. }
  831. while (next_rx_slot != rx_slot_array[0]);
  832. /*
  833. * Now do the same for the transmit slots.
  834. */
  835. sys_outsw(
  836. adapter_handle,
  837. adapter->sif_adr,
  838. (WORD) (card_t) &adapter->stb_dio_addr->tx_slot_start
  839. );
  840. /*
  841. * Poll this address until it is non-zero.
  842. */
  843. do
  844. {
  845. tx_slot_array[0] = (TX_SLOT *) (card_t)
  846. sys_insw(adapter_handle, adapter->sif_dat);
  847. }
  848. while (tx_slot_array[0] == 0);
  849. /*
  850. * Now recover all the other slots by running down the chain.
  851. */
  852. slot_index = 0;
  853. do
  854. {
  855. sys_outsw(
  856. adapter_handle,
  857. adapter->sif_adr,
  858. (WORD) (card_t) &tx_slot_array[slot_index]->next_slot
  859. );
  860. next_tx_slot = (TX_SLOT *) (card_t)
  861. sys_insw(adapter_handle, adapter->sif_dat);
  862. if (next_tx_slot != tx_slot_array[0])
  863. {
  864. tx_slot_array[++slot_index] = next_tx_slot;
  865. }
  866. }
  867. while (next_tx_slot != tx_slot_array[0]);
  868. /*
  869. * Now that we have the slot locations on the card, we can associate
  870. * buffers with each of them. The user needs to supply a routine that
  871. * set up the slots from the host buffers previously allocated as
  872. * we don't enforce an organisation on the allocation of multiple
  873. * slot buffers. We tell the user routine if it should program the
  874. * adapter slots with physical addresses (for DMA) or virtual
  875. * addresses (for PIO or MMIO).
  876. */
  877. rxtx_setup_rx_buffers(
  878. adapter,
  879. (WBOOLEAN) (adapter->transfer_mode == DMA_DATA_TRANSFER_MODE),
  880. fastmac_parms->rx_slots
  881. );
  882. rxtx_setup_tx_buffers(
  883. adapter,
  884. (WBOOLEAN) (adapter->transfer_mode == DMA_DATA_TRANSFER_MODE),
  885. fastmac_parms->tx_slots
  886. );
  887. #endif
  888. /*
  889. * Let the system know we have finished accessing the IO ports.
  890. */
  891. #ifndef FTK_NO_IO_ENABLE
  892. macro_disable_io( adapter);
  893. #endif
  894. /*
  895. * Check that Fastmac has correctly installed. Do this by reading
  896. * node address from Fastmac status block. If routine fails return
  897. * failure (error record already filled in). Note for EISA cards,
  898. * this is actually first time get node address.
  899. */
  900. if (!hwi_get_node_address_check(adapter))
  901. {
  902. return FALSE;
  903. }
  904. /*
  905. * Copy permanent BIA PROM node address into user supplied node address.
  906. */
  907. *returned_permanent_address = adapter->permanent_address;
  908. /*
  909. * If the auto open option is on then wait to see if adapter opens okay.
  910. * Enable and disable accessing IO locations around check.
  911. * If adapter open routine fails then error record already filled in.
  912. */
  913. if (arguments->auto_open_option)
  914. {
  915. #ifndef FTK_NO_IO_ENABLE
  916. macro_enable_io( adapter);
  917. #endif
  918. init_success = driver_wait_for_adapter_open(
  919. &(arguments->open_status),
  920. adapter
  921. );
  922. #ifndef FTK_NO_IO_ENABLE
  923. macro_disable_io( adapter);
  924. #endif
  925. }
  926. else
  927. {
  928. init_success = TRUE;
  929. }
  930. /*
  931. * Initialization completed.
  932. */
  933. return init_success;
  934. }
  935. #ifdef FMPLUS
  936. /****************************************************************************
  937. *
  938. * driver_start_receive_process
  939. * ============================
  940. *
  941. * PARAMETERS :
  942. * ============
  943. *
  944. * ADAPTER_HANDLE adapter_handle
  945. *
  946. * This handle identifies the adapter to be initialized. This should be a
  947. * handle returned by a call to driver_prepare_adapter.
  948. *
  949. * BODY :
  950. * ======
  951. *
  952. * The driver_start_adapter routine is called once per adapter after a call
  953. * to driver_start_adapter. It uses the supplied handle to identify which
  954. * adapter it should affect : by writing a zero into the Fastmac Plus init-
  955. * ialization block on the adapter (as specified in the manual), the card
  956. * will start to receive frames and pass them up to the host.
  957. *
  958. * NOTE: If SRBs are going to be used, this MUST be called first.
  959. *
  960. * RETURNS :
  961. * =========
  962. *
  963. * The routine returns TRUE if it succeeds. If this routine fails (returns
  964. * FALSE) then a subsequent call to driver_explain_error with the same
  965. * adapter handle will give an explanation.
  966. *
  967. ****************************************************************************/
  968. #ifdef FTK_INIT_FUNCTION
  969. #pragma FTK_INIT_FUNCTION(driver_start_receive_process)
  970. #endif
  971. export WBOOLEAN
  972. driver_start_receive_process(
  973. ADAPTER_HANDLE adapter_handle
  974. )
  975. {
  976. ADAPTER * adapter;
  977. /*
  978. * Adapter handle is invalid if greater than max number of adapters.
  979. * Can not set up error record but see driver_explain_error.
  980. */
  981. if (adapter_handle >= MAX_NUMBER_OF_ADAPTERS)
  982. {
  983. return FALSE;
  984. }
  985. /*
  986. * Adapter handle is invalid when no adapter structure for handle.
  987. * Can not set up error record but see driver_explain_error.
  988. */
  989. if (adapter_record[adapter_handle] == NULL)
  990. {
  991. return FALSE;
  992. }
  993. /*
  994. * Get pointer to adapter structure.
  995. */
  996. adapter = adapter_record[adapter_handle];
  997. /*
  998. * Inform the system about the IO ports we are going to access.
  999. */
  1000. #ifndef FTK_NO_IO_ENABLE
  1001. macro_enable_io(adapter);
  1002. #endif
  1003. /*
  1004. * Let's fire off the receive process from here then...
  1005. */
  1006. sys_outsw(
  1007. adapter_handle,
  1008. adapter->sif_adr,
  1009. (WORD) (card_t) &adapter->stb_dio_addr->rx_slot_start
  1010. );
  1011. sys_outsw(adapter_handle, adapter->sif_dat, 0);
  1012. /*
  1013. * Let the system know we have finished accessing the IO ports.
  1014. */
  1015. #ifndef FTK_NO_IO_ENABLE
  1016. macro_disable_io(adapter);
  1017. #endif
  1018. return TRUE;
  1019. }
  1020. #endif
  1021. /****************************************************************************
  1022. *
  1023. * driver_remove_adapter
  1024. * =====================
  1025. *
  1026. * PARAMETERS :
  1027. * ============
  1028. *
  1029. * ADAPTER_HANDLE adapter_handle
  1030. *
  1031. * This handle identifies the adapter to be removed.
  1032. *
  1033. * BODY :
  1034. * ======
  1035. *
  1036. * The driver_remove_adapter routine is written such that, whatever the
  1037. * current state of the adapter, a call to driver_remove_adapter will place
  1038. * the adapter in a state whereby driver_prepare_adapter must be called to
  1039. * start using the adapter once more. Hence, on ANY fatal adapter error, a
  1040. * call to driver_remove adapter is needed before installing the adapter
  1041. * again.
  1042. *
  1043. * The routine calls the HWI to reset the required adapter if the adapter
  1044. * has been running. It also calls certain system routines in order to
  1045. * free the memory used by the Fastmac receive and transmit buffers as well
  1046. * as that used by the adapter structure. However, it only does this when
  1047. * the allocate calls were successful.
  1048. *
  1049. * RETURNS :
  1050. * =========
  1051. *
  1052. * The routine always succeeds. Even if the adapter handle is invalid then
  1053. * the routine does not fail it just does nothing.
  1054. *
  1055. ****************************************************************************/
  1056. #ifdef FTK_RES_FUNCTION
  1057. #pragma FTK_RES_FUNCTION(driver_remove_adapter)
  1058. #endif
  1059. export WBOOLEAN
  1060. driver_remove_adapter(
  1061. ADAPTER_HANDLE adapter_handle
  1062. )
  1063. {
  1064. ADAPTER * adapter;
  1065. FASTMAC_INIT_PARMS * fastmac_parms;
  1066. /*
  1067. * Adapter handle is invalid if greater than max number of adapters.
  1068. * Can not set up error record but see driver_explain_error.
  1069. */
  1070. if (adapter_handle >= MAX_NUMBER_OF_ADAPTERS)
  1071. {
  1072. return FALSE;
  1073. }
  1074. /*
  1075. * Adapter handle is invalid when no adapter structure for handle.
  1076. * Can not set up error record but see driver_explain_error.
  1077. */
  1078. if (adapter_record[adapter_handle] == NULL)
  1079. {
  1080. return FALSE;
  1081. }
  1082. /*
  1083. * Get pointer to adapter structure.
  1084. */
  1085. adapter = adapter_record[adapter_handle];
  1086. /*
  1087. * Call the HWI routine to kill the adapter (DMA channel, IRQ number).
  1088. * Only call it if either DMA or interrupts are enabled at adapter.
  1089. * Note in this case the actual adapter card type is known.
  1090. */
  1091. if (adapter->interrupts_on || adapter->dma_on)
  1092. {
  1093. hwi_remove_adapter(adapter);
  1094. }
  1095. /*
  1096. * Free all memory that was allocated for handling use of this adapter.
  1097. * Includes Fastmac buffers, init block and adapter structure.
  1098. * Only free memory if allocate memory calls were successful.
  1099. */
  1100. if (adapter->init_block != NULL)
  1101. {
  1102. /*
  1103. * Initialize variable used for freeing memory.
  1104. */
  1105. fastmac_parms = &adapter->init_block->fastmac_parms;
  1106. #ifndef FMPLUS
  1107. /*
  1108. * Free transmit buffer space if allocated.
  1109. */
  1110. if (adapter->tx_buffer_phys != NULL_PHYSADDR)
  1111. {
  1112. sys_free_dma_phys_buffer(
  1113. adapter_handle,
  1114. fastmac_parms->tx_buf_size,
  1115. adapter->tx_buffer_phys,
  1116. adapter->tx_buffer_virt
  1117. );
  1118. }
  1119. /*
  1120. * Free receive buffer space if allocated.
  1121. */
  1122. if (adapter->rx_buffer_phys != NULL_PHYSADDR)
  1123. {
  1124. sys_free_dma_phys_buffer(
  1125. adapter_handle,
  1126. fastmac_parms->rx_buf_size,
  1127. adapter->rx_buffer_phys,
  1128. adapter->rx_buffer_virt
  1129. );
  1130. }
  1131. #else
  1132. /*
  1133. * Free receive buffer space if allocated.
  1134. */
  1135. rxtx_free_rx_buffers(
  1136. adapter,
  1137. fastmac_parms->max_frame_size,
  1138. fastmac_parms->rx_slots
  1139. );
  1140. /*
  1141. * Free transmit buffer space if allocated.
  1142. */
  1143. rxtx_free_tx_buffers(
  1144. adapter,
  1145. fastmac_parms->max_frame_size,
  1146. fastmac_parms->tx_slots
  1147. );
  1148. #endif
  1149. /*
  1150. * Free the initialization block allocated memory.
  1151. */
  1152. sys_free_init_block(
  1153. adapter_handle,
  1154. (BYTE *) adapter->init_block,
  1155. sizeof(INITIALIZATION_BLOCK)
  1156. );
  1157. }
  1158. /*
  1159. * Free status structure if allocated.
  1160. */
  1161. if (adapter->status_info != NULL)
  1162. {
  1163. sys_free_status_structure(
  1164. adapter_handle,
  1165. (BYTE *) adapter->status_info,
  1166. sizeof(STATUS_INFORMATION)
  1167. );
  1168. }
  1169. #ifdef FMPLUS
  1170. if (adapter->dma_test_buf_virt != 0)
  1171. {
  1172. sys_free_dma_phys_buffer(
  1173. adapter->adapter_handle,
  1174. SCB_TEST_PATTERN_LENGTH + SSB_TEST_PATTERN_LENGTH + 1,
  1175. adapter->dma_test_buf_phys,
  1176. adapter->dma_test_buf_virt
  1177. );
  1178. }
  1179. #endif
  1180. /*
  1181. * Already know adapter allocate was successful hence always free it.
  1182. */
  1183. sys_free_adapter_structure(
  1184. adapter_handle,
  1185. (BYTE *) adapter,
  1186. sizeof(ADAPTER)
  1187. );
  1188. /*
  1189. * Clear entry in adapter pointers array.
  1190. */
  1191. adapter_record[adapter_handle] = NULL;
  1192. /*
  1193. * Complete successfully.
  1194. */
  1195. return TRUE;
  1196. }
  1197. /*---------------------------------------------------------------------------
  1198. |
  1199. | driver_wait_for_adapter_open
  1200. | ============================
  1201. |
  1202. | The driver_wait_for_adapter_open routine waits at least 40 seconds for
  1203. | the adapter to open. It discovers whether the adapter has opened
  1204. | successfully or not by looking in the Fastmac status block (STB). If the
  1205. | adapter fails to open then this routine fills in the adapter error
  1206. | record.
  1207. |
  1208. ---------------------------------------------------------------------------*/
  1209. #ifdef FTK_INIT_FUNCTION
  1210. #pragma FTK_INIT_FUNCTION(driver_wait_for_adapter_open)
  1211. #endif
  1212. local WBOOLEAN
  1213. driver_wait_for_adapter_open(
  1214. UINT * open_status,
  1215. ADAPTER * adapter
  1216. )
  1217. {
  1218. ADAPTER_HANDLE adapter_handle = adapter->adapter_handle;
  1219. WBOOLEAN open_okay;
  1220. UINT open_error;
  1221. UINT index;
  1222. /*
  1223. * Wait at least a total of 40 seconds for adapter to open.
  1224. */
  1225. for (index = 0; index < 160; index++)
  1226. {
  1227. /*
  1228. * Set up DIO address to open status field in STB (status block).
  1229. */
  1230. sys_outsw(
  1231. adapter_handle,
  1232. adapter->sif_adr,
  1233. (WORD) (card_t) &adapter->stb_dio_addr->adapter_open
  1234. );
  1235. /*
  1236. * Read open status field from DIO space. If successfully
  1237. * opened then complete successfully.
  1238. */
  1239. open_okay = (WBOOLEAN) sys_insw(
  1240. adapter_handle,
  1241. adapter->sif_datinc
  1242. );
  1243. if (open_okay)
  1244. {
  1245. *open_status = EAGLE_OPEN_ERROR_SUCCESS;
  1246. return TRUE;
  1247. }
  1248. /*
  1249. * If not opened, see if an error has occured to prevent opening.
  1250. */
  1251. open_error = sys_insw(adapter_handle, adapter->sif_datinc);
  1252. *open_status = open_error;
  1253. if (open_error != EAGLE_OPEN_ERROR_SUCCESS)
  1254. {
  1255. adapter->error_record.type = ERROR_TYPE_AUTO_OPEN;
  1256. adapter->error_record.value = AUTO_OPEN_E_01_OPEN_ERROR;
  1257. return FALSE;
  1258. }
  1259. /*
  1260. * Opening procedure not completed. Wait at least 250 milliseconds
  1261. * before checkig again. Disable and re-enable accessing IO locations
  1262. * around wait so delay can reschedule this task and not effect others
  1263. * running.
  1264. */
  1265. #ifndef FTK_NO_IO_ENABLE
  1266. macro_disable_io( adapter);
  1267. #endif
  1268. sys_wait_at_least_milliseconds(250);
  1269. #ifndef FTK_NO_IO_ENABLE
  1270. macro_enable_io( adapter);
  1271. #endif
  1272. }
  1273. /*
  1274. * At least 40 seconds have gone so return time out failure.
  1275. */
  1276. adapter->error_record.type = ERROR_TYPE_AUTO_OPEN;
  1277. adapter->error_record.value = AUTO_OPEN_E_80_TIME_OUT;
  1278. return FALSE;
  1279. }
  1280. /*---------------------------------------------------------------------------
  1281. |
  1282. | driver_get_max_frame_size
  1283. | =========================
  1284. |
  1285. | The driver_get_max_frame_size routine calculates the maximum sized frame
  1286. | that can be transmitted or received. This calculation is based on the
  1287. | maximum frame size determined by ring speed alone, the size of the
  1288. | Fastmac buffers, and the fact that Fastmac pointers have to be DWORD
  1289. | aligned.
  1290. |
  1291. ---------------------------------------------------------------------------*/
  1292. #ifdef FTK_INIT_FUNCTION
  1293. #pragma FTK_INIT_FUNCTION(driver_get_max_frame_size)
  1294. #endif
  1295. local WORD
  1296. driver_get_max_frame_size(
  1297. ADAPTER * adapter,
  1298. FASTMAC_INIT_PARMS * fastmac_parms
  1299. )
  1300. {
  1301. #ifdef FMPLUS
  1302. return adapter->max_frame_size;
  1303. #else
  1304. WORD tx_max_frame_size;
  1305. WORD rx_max_frame_size;
  1306. WORD max_frame_size;
  1307. /*
  1308. * Calculate max transmit frame size from size of buffer, size of
  1309. * header and knowing that one frame must leave space such that host
  1310. * and adapter ptrs into buffer are not the same.
  1311. */
  1312. tx_max_frame_size =
  1313. fastmac_parms->tx_buf_size - macro_dword_align(
  1314. FASTMAC_BUFFER_HEADER_SIZE +
  1315. fastmac_parms->tx_buf_space +
  1316. sizeof(DWORD)
  1317. );
  1318. /*
  1319. * Calculate max receive frame size from size of buffer, size of
  1320. * header and knowing that one frame must leave space such that host
  1321. * and adapter ptrs into buffer are not the same.
  1322. */
  1323. rx_max_frame_size =
  1324. fastmac_parms->rx_buf_size - macro_dword_align(
  1325. FASTMAC_BUFFER_HEADER_SIZE +
  1326. fastmac_parms->rx_buf_space +
  1327. sizeof(DWORD)
  1328. );
  1329. /*
  1330. * Actual max frame size is minimum of max transmit and receive frame
  1331. * sizes and max frame size for adapter (ring speed dependent).
  1332. */
  1333. max_frame_size = util_minimum(
  1334. tx_max_frame_size,
  1335. rx_max_frame_size,
  1336. adapter->max_frame_size
  1337. );
  1338. return max_frame_size;
  1339. #endif
  1340. }
  1341. /**** End of DRV_INIT.C file ***********************************************/