PageRenderTime 68ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/staging/wlags49_h2/wl_netdev.c

https://bitbucket.org/slukk/jb-tsm-kernel-4.2
C | 2037 lines | 953 code | 282 blank | 802 comment | 162 complexity | fc6867309f307f87b2d59e0b09bee68e MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /*******************************************************************************
  2. * Agere Systems Inc.
  3. * Wireless device driver for Linux (wlags49).
  4. *
  5. * Copyright (c) 1998-2003 Agere Systems Inc.
  6. * All rights reserved.
  7. * http://www.agere.com
  8. *
  9. * Initially developed by TriplePoint, Inc.
  10. * http://www.triplepoint.com
  11. *
  12. *------------------------------------------------------------------------------
  13. *
  14. * This file contains handler functions registered with the net_device
  15. * structure.
  16. *
  17. *------------------------------------------------------------------------------
  18. *
  19. * SOFTWARE LICENSE
  20. *
  21. * This software is provided subject to the following terms and conditions,
  22. * which you should read carefully before using the software. Using this
  23. * software indicates your acceptance of these terms and conditions. If you do
  24. * not agree with these terms and conditions, do not use the software.
  25. *
  26. * Copyright © 2003 Agere Systems Inc.
  27. * All rights reserved.
  28. *
  29. * Redistribution and use in source or binary forms, with or without
  30. * modifications, are permitted provided that the following conditions are met:
  31. *
  32. * . Redistributions of source code must retain the above copyright notice, this
  33. * list of conditions and the following Disclaimer as comments in the code as
  34. * well as in the documentation and/or other materials provided with the
  35. * distribution.
  36. *
  37. * . Redistributions in binary form must reproduce the above copyright notice,
  38. * this list of conditions and the following Disclaimer in the documentation
  39. * and/or other materials provided with the distribution.
  40. *
  41. * . Neither the name of Agere Systems Inc. nor the names of the contributors
  42. * may be used to endorse or promote products derived from this software
  43. * without specific prior written permission.
  44. *
  45. * Disclaimer
  46. *
  47. * THIS SOFTWARE IS PROVIDED “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES,
  48. * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
  49. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY
  50. * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
  51. * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
  52. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  53. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  54. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  55. * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
  56. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  57. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  58. * DAMAGE.
  59. *
  60. ******************************************************************************/
  61. /*******************************************************************************
  62. * include files
  63. ******************************************************************************/
  64. #include <wl_version.h>
  65. #include <linux/module.h>
  66. #include <linux/slab.h>
  67. #include <linux/types.h>
  68. #include <linux/kernel.h>
  69. // #include <linux/sched.h>
  70. // #include <linux/ptrace.h>
  71. // #include <linux/slab.h>
  72. // #include <linux/ctype.h>
  73. // #include <linux/string.h>
  74. //#include <linux/timer.h>
  75. // #include <linux/interrupt.h>
  76. // #include <linux/in.h>
  77. // #include <linux/delay.h>
  78. // #include <linux/skbuff.h>
  79. // #include <asm/io.h>
  80. // #include <asm/system.h>
  81. // #include <asm/bitops.h>
  82. #include <linux/netdevice.h>
  83. #include <linux/ethtool.h>
  84. #include <linux/etherdevice.h>
  85. // #include <linux/skbuff.h>
  86. // #include <linux/if_arp.h>
  87. // #include <linux/ioport.h>
  88. #include <debug.h>
  89. #include <hcf.h>
  90. #include <dhf.h>
  91. // #include <hcfdef.h>
  92. #include <wl_if.h>
  93. #include <wl_internal.h>
  94. #include <wl_util.h>
  95. #include <wl_priv.h>
  96. #include <wl_main.h>
  97. #include <wl_netdev.h>
  98. #include <wl_wext.h>
  99. #ifdef USE_PROFILE
  100. #include <wl_profile.h>
  101. #endif /* USE_PROFILE */
  102. #ifdef BUS_PCMCIA
  103. #include <wl_cs.h>
  104. #endif /* BUS_PCMCIA */
  105. #ifdef BUS_PCI
  106. #include <wl_pci.h>
  107. #endif /* BUS_PCI */
  108. /*******************************************************************************
  109. * global variables
  110. ******************************************************************************/
  111. #if DBG
  112. extern dbg_info_t *DbgInfo;
  113. #endif /* DBG */
  114. #if HCF_ENCAP
  115. #define MTU_MAX (HCF_MAX_MSG - ETH_HLEN - 8)
  116. #else
  117. #define MTU_MAX (HCF_MAX_MSG - ETH_HLEN)
  118. #endif
  119. //static int mtu = MTU_MAX;
  120. //MODULE_PARM(mtu, "i");
  121. //MODULE_PARM_DESC(mtu, "MTU");
  122. /*******************************************************************************
  123. * macros
  124. ******************************************************************************/
  125. #define BLOCK_INPUT(buf, len) \
  126. desc->buf_addr = buf; \
  127. desc->BUF_SIZE = len; \
  128. status = hcf_rcv_msg(&(lp->hcfCtx), desc, 0)
  129. #define BLOCK_INPUT_DMA(buf, len) memcpy( buf, desc_next->buf_addr, pktlen )
  130. /*******************************************************************************
  131. * function prototypes
  132. ******************************************************************************/
  133. /*******************************************************************************
  134. * wl_init()
  135. *******************************************************************************
  136. *
  137. * DESCRIPTION:
  138. *
  139. * We never need to do anything when a "Wireless" device is "initialized"
  140. * by the net software, because we only register already-found cards.
  141. *
  142. * PARAMETERS:
  143. *
  144. * dev - a pointer to the device's net_device structure
  145. *
  146. * RETURNS:
  147. *
  148. * 0 on success
  149. * errno value otherwise
  150. *
  151. ******************************************************************************/
  152. int wl_init( struct net_device *dev )
  153. {
  154. // unsigned long flags;
  155. // struct wl_private *lp = wl_priv(dev);
  156. /*------------------------------------------------------------------------*/
  157. DBG_FUNC( "wl_init" );
  158. DBG_ENTER( DbgInfo );
  159. DBG_PARAM( DbgInfo, "dev", "%s (0x%p)", dev->name, dev );
  160. /* Nothing to do, but grab the spinlock anyway just in case we ever need
  161. this routine */
  162. // wl_lock( lp, &flags );
  163. // wl_unlock( lp, &flags );
  164. DBG_LEAVE( DbgInfo );
  165. return 0;
  166. } // wl_init
  167. /*============================================================================*/
  168. /*******************************************************************************
  169. * wl_config()
  170. *******************************************************************************
  171. *
  172. * DESCRIPTION:
  173. *
  174. * Implement the SIOCSIFMAP interface.
  175. *
  176. * PARAMETERS:
  177. *
  178. * dev - a pointer to the device's net_device structure
  179. * map - a pointer to the device's ifmap structure
  180. *
  181. * RETURNS:
  182. *
  183. * 0 on success
  184. * errno otherwise
  185. *
  186. ******************************************************************************/
  187. int wl_config( struct net_device *dev, struct ifmap *map )
  188. {
  189. DBG_FUNC( "wl_config" );
  190. DBG_ENTER( DbgInfo );
  191. DBG_PARAM( DbgInfo, "dev", "%s (0x%p)", dev->name, dev );
  192. DBG_PARAM( DbgInfo, "map", "0x%p", map );
  193. /* The only thing we care about here is a port change. Since this not needed,
  194. ignore the request. */
  195. DBG_TRACE( DbgInfo, "%s: %s called.\n", dev->name, __FUNC__ );
  196. DBG_LEAVE( DbgInfo );
  197. return 0;
  198. } // wl_config
  199. /*============================================================================*/
  200. /*******************************************************************************
  201. * wl_stats()
  202. *******************************************************************************
  203. *
  204. * DESCRIPTION:
  205. *
  206. * Return the current device statistics.
  207. *
  208. * PARAMETERS:
  209. *
  210. * dev - a pointer to the device's net_device structure
  211. *
  212. * RETURNS:
  213. *
  214. * a pointer to a net_device_stats structure containing the network
  215. * statistics.
  216. *
  217. ******************************************************************************/
  218. struct net_device_stats *wl_stats( struct net_device *dev )
  219. {
  220. #ifdef USE_WDS
  221. int count;
  222. #endif /* USE_WDS */
  223. unsigned long flags;
  224. struct net_device_stats *pStats;
  225. struct wl_private *lp = wl_priv(dev);
  226. /*------------------------------------------------------------------------*/
  227. //DBG_FUNC( "wl_stats" );
  228. //DBG_ENTER( DbgInfo );
  229. //DBG_PARAM( DbgInfo, "dev", "%s (0x%p)", dev->name, dev );
  230. pStats = NULL;
  231. wl_lock( lp, &flags );
  232. #ifdef USE_RTS
  233. if( lp->useRTS == 1 ) {
  234. wl_unlock( lp, &flags );
  235. //DBG_LEAVE( DbgInfo );
  236. return NULL;
  237. }
  238. #endif /* USE_RTS */
  239. /* Return the statistics for the appropriate device */
  240. #ifdef USE_WDS
  241. for( count = 0; count < NUM_WDS_PORTS; count++ ) {
  242. if( dev == lp->wds_port[count].dev ) {
  243. pStats = &( lp->wds_port[count].stats );
  244. }
  245. }
  246. #endif /* USE_WDS */
  247. /* If pStats is still NULL, then the device is not a WDS port */
  248. if( pStats == NULL ) {
  249. pStats = &( lp->stats );
  250. }
  251. wl_unlock( lp, &flags );
  252. //DBG_LEAVE( DbgInfo );
  253. return pStats;
  254. } // wl_stats
  255. /*============================================================================*/
  256. /*******************************************************************************
  257. * wl_open()
  258. *******************************************************************************
  259. *
  260. * DESCRIPTION:
  261. *
  262. * Open the device.
  263. *
  264. * PARAMETERS:
  265. *
  266. * dev - a pointer to the device's net_device structure
  267. *
  268. * RETURNS:
  269. *
  270. * 0 on success
  271. * errno otherwise
  272. *
  273. ******************************************************************************/
  274. int wl_open(struct net_device *dev)
  275. {
  276. int status = HCF_SUCCESS;
  277. struct wl_private *lp = wl_priv(dev);
  278. unsigned long flags;
  279. /*------------------------------------------------------------------------*/
  280. DBG_FUNC( "wl_open" );
  281. DBG_ENTER( DbgInfo );
  282. wl_lock( lp, &flags );
  283. #ifdef USE_RTS
  284. if( lp->useRTS == 1 ) {
  285. DBG_TRACE( DbgInfo, "Skipping device open, in RTS mode\n" );
  286. wl_unlock( lp, &flags );
  287. DBG_LEAVE( DbgInfo );
  288. return -EIO;
  289. }
  290. #endif /* USE_RTS */
  291. #ifdef USE_PROFILE
  292. parse_config( dev );
  293. #endif
  294. if( lp->portState == WVLAN_PORT_STATE_DISABLED ) {
  295. DBG_TRACE( DbgInfo, "Enabling Port 0\n" );
  296. status = wl_enable( lp );
  297. if( status != HCF_SUCCESS ) {
  298. DBG_TRACE( DbgInfo, "Enable port 0 failed: 0x%x\n", status );
  299. }
  300. }
  301. // Holding the lock too long, make a gap to allow other processes
  302. wl_unlock(lp, &flags);
  303. wl_lock( lp, &flags );
  304. if ( strlen( lp->fw_image_filename ) ) {
  305. DBG_TRACE( DbgInfo, ";???? Kludgy way to force a download\n" );
  306. status = wl_go( lp );
  307. } else {
  308. status = wl_apply( lp );
  309. }
  310. // Holding the lock too long, make a gap to allow other processes
  311. wl_unlock(lp, &flags);
  312. wl_lock( lp, &flags );
  313. if( status != HCF_SUCCESS ) {
  314. // Unsuccessful, try reset of the card to recover
  315. status = wl_reset( dev );
  316. }
  317. // Holding the lock too long, make a gap to allow other processes
  318. wl_unlock(lp, &flags);
  319. wl_lock( lp, &flags );
  320. if( status == HCF_SUCCESS ) {
  321. netif_carrier_on( dev );
  322. WL_WDS_NETIF_CARRIER_ON( lp );
  323. lp->is_handling_int = WL_HANDLING_INT; // Start handling interrupts
  324. wl_act_int_on( lp );
  325. netif_start_queue( dev );
  326. WL_WDS_NETIF_START_QUEUE( lp );
  327. } else {
  328. wl_hcf_error( dev, status ); /* Report the error */
  329. netif_device_detach( dev ); /* Stop the device and queue */
  330. }
  331. wl_unlock( lp, &flags );
  332. DBG_LEAVE( DbgInfo );
  333. return status;
  334. } // wl_open
  335. /*============================================================================*/
  336. /*******************************************************************************
  337. * wl_close()
  338. *******************************************************************************
  339. *
  340. * DESCRIPTION:
  341. *
  342. * Close the device.
  343. *
  344. * PARAMETERS:
  345. *
  346. * dev - a pointer to the device's net_device structure
  347. *
  348. * RETURNS:
  349. *
  350. * 0 on success
  351. * errno otherwise
  352. *
  353. ******************************************************************************/
  354. int wl_close( struct net_device *dev )
  355. {
  356. struct wl_private *lp = wl_priv(dev);
  357. unsigned long flags;
  358. /*------------------------------------------------------------------------*/
  359. DBG_FUNC("wl_close");
  360. DBG_ENTER(DbgInfo);
  361. DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
  362. /* Mark the adapter as busy */
  363. netif_stop_queue( dev );
  364. WL_WDS_NETIF_STOP_QUEUE( lp );
  365. netif_carrier_off( dev );
  366. WL_WDS_NETIF_CARRIER_OFF( lp );
  367. /* Shutdown the adapter:
  368. Disable adapter interrupts
  369. Stop Tx/Rx
  370. Update statistics
  371. Set low power mode
  372. */
  373. wl_lock( lp, &flags );
  374. wl_act_int_off( lp );
  375. lp->is_handling_int = WL_NOT_HANDLING_INT; // Stop handling interrupts
  376. #ifdef USE_RTS
  377. if( lp->useRTS == 1 ) {
  378. DBG_TRACE( DbgInfo, "Skipping device close, in RTS mode\n" );
  379. wl_unlock( lp, &flags );
  380. DBG_LEAVE( DbgInfo );
  381. return -EIO;
  382. }
  383. #endif /* USE_RTS */
  384. /* Disable the ports */
  385. wl_disable( lp );
  386. wl_unlock( lp, &flags );
  387. DBG_LEAVE( DbgInfo );
  388. return 0;
  389. } // wl_close
  390. /*============================================================================*/
  391. static void wl_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  392. {
  393. strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
  394. strncpy(info->version, DRV_VERSION_STR, sizeof(info->version) - 1);
  395. // strncpy(info.fw_version, priv->fw_name,
  396. // sizeof(info.fw_version) - 1);
  397. if (dev->dev.parent) {
  398. dev_set_name(dev->dev.parent, "%s", info->bus_info);
  399. //strncpy(info->bus_info, dev->dev.parent->bus_id,
  400. // sizeof(info->bus_info) - 1);
  401. } else {
  402. snprintf(info->bus_info, sizeof(info->bus_info) - 1,
  403. "PCMCIA FIXME");
  404. // "PCMCIA 0x%lx", priv->hw.iobase);
  405. }
  406. } // wl_get_drvinfo
  407. static struct ethtool_ops wl_ethtool_ops = {
  408. .get_drvinfo = wl_get_drvinfo,
  409. .get_link = ethtool_op_get_link,
  410. };
  411. /*******************************************************************************
  412. * wl_ioctl()
  413. *******************************************************************************
  414. *
  415. * DESCRIPTION:
  416. *
  417. * The IOCTL handler for the device.
  418. *
  419. * PARAMETERS:
  420. *
  421. * dev - a pointer to the device's net_device struct.
  422. * rq - a pointer to the IOCTL request buffer.
  423. * cmd - the IOCTL command code.
  424. *
  425. * RETURNS:
  426. *
  427. * 0 on success
  428. * errno value otherwise
  429. *
  430. ******************************************************************************/
  431. int wl_ioctl( struct net_device *dev, struct ifreq *rq, int cmd )
  432. {
  433. struct wl_private *lp = wl_priv(dev);
  434. unsigned long flags;
  435. int ret = 0;
  436. /*------------------------------------------------------------------------*/
  437. DBG_FUNC( "wl_ioctl" );
  438. DBG_ENTER(DbgInfo);
  439. DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
  440. DBG_PARAM(DbgInfo, "rq", "0x%p", rq);
  441. DBG_PARAM(DbgInfo, "cmd", "0x%04x", cmd);
  442. wl_lock( lp, &flags );
  443. wl_act_int_off( lp );
  444. #ifdef USE_RTS
  445. if( lp->useRTS == 1 ) {
  446. /* Handle any RTS IOCTL here */
  447. if( cmd == WL_IOCTL_RTS ) {
  448. DBG_TRACE( DbgInfo, "IOCTL: WL_IOCTL_RTS\n" );
  449. ret = wvlan_rts( (struct rtsreq *)rq, dev->base_addr );
  450. } else {
  451. DBG_TRACE( DbgInfo, "IOCTL not supported in RTS mode: 0x%X\n", cmd );
  452. ret = -EOPNOTSUPP;
  453. }
  454. goto out_act_int_on_unlock;
  455. }
  456. #endif /* USE_RTS */
  457. /* Only handle UIL IOCTL requests when the UIL has the system blocked. */
  458. if( !(( lp->flags & WVLAN2_UIL_BUSY ) && ( cmd != WVLAN2_IOCTL_UIL ))) {
  459. #ifdef USE_UIL
  460. struct uilreq *urq = (struct uilreq *)rq;
  461. #endif /* USE_UIL */
  462. switch( cmd ) {
  463. // ================== Private IOCTLs (up to 16) ==================
  464. #ifdef USE_UIL
  465. case WVLAN2_IOCTL_UIL:
  466. DBG_TRACE( DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL\n" );
  467. ret = wvlan_uil( urq, lp );
  468. break;
  469. #endif /* USE_UIL */
  470. default:
  471. DBG_TRACE(DbgInfo, "IOCTL CODE NOT SUPPORTED: 0x%X\n", cmd );
  472. ret = -EOPNOTSUPP;
  473. break;
  474. }
  475. } else {
  476. DBG_WARNING( DbgInfo, "DEVICE IS BUSY, CANNOT PROCESS REQUEST\n" );
  477. ret = -EBUSY;
  478. }
  479. #ifdef USE_RTS
  480. out_act_int_on_unlock:
  481. #endif /* USE_RTS */
  482. wl_act_int_on( lp );
  483. wl_unlock( lp, &flags );
  484. DBG_LEAVE( DbgInfo );
  485. return ret;
  486. } // wl_ioctl
  487. /*============================================================================*/
  488. #ifdef CONFIG_NET_POLL_CONTROLLER
  489. void wl_poll(struct net_device *dev)
  490. {
  491. struct wl_private *lp = wl_priv(dev);
  492. unsigned long flags;
  493. struct pt_regs regs;
  494. wl_lock( lp, &flags );
  495. wl_isr(dev->irq, dev, &regs);
  496. wl_unlock( lp, &flags );
  497. }
  498. #endif
  499. /*******************************************************************************
  500. * wl_tx_timeout()
  501. *******************************************************************************
  502. *
  503. * DESCRIPTION:
  504. *
  505. * The handler called when, for some reason, a Tx request is not completed.
  506. *
  507. * PARAMETERS:
  508. *
  509. * dev - a pointer to the device's net_device struct.
  510. *
  511. * RETURNS:
  512. *
  513. * N/A
  514. *
  515. ******************************************************************************/
  516. void wl_tx_timeout( struct net_device *dev )
  517. {
  518. #ifdef USE_WDS
  519. int count;
  520. #endif /* USE_WDS */
  521. unsigned long flags;
  522. struct wl_private *lp = wl_priv(dev);
  523. struct net_device_stats *pStats = NULL;
  524. /*------------------------------------------------------------------------*/
  525. DBG_FUNC( "wl_tx_timeout" );
  526. DBG_ENTER( DbgInfo );
  527. DBG_WARNING( DbgInfo, "%s: Transmit timeout.\n", dev->name );
  528. wl_lock( lp, &flags );
  529. #ifdef USE_RTS
  530. if( lp->useRTS == 1 ) {
  531. DBG_TRACE( DbgInfo, "Skipping tx_timeout handler, in RTS mode\n" );
  532. wl_unlock( lp, &flags );
  533. DBG_LEAVE( DbgInfo );
  534. return;
  535. }
  536. #endif /* USE_RTS */
  537. /* Figure out which device (the "root" device or WDS port) this timeout
  538. is for */
  539. #ifdef USE_WDS
  540. for( count = 0; count < NUM_WDS_PORTS; count++ ) {
  541. if( dev == lp->wds_port[count].dev ) {
  542. pStats = &( lp->wds_port[count].stats );
  543. /* Break the loop so that we can use the counter to access WDS
  544. information in the private structure */
  545. break;
  546. }
  547. }
  548. #endif /* USE_WDS */
  549. /* If pStats is still NULL, then the device is not a WDS port */
  550. if( pStats == NULL ) {
  551. pStats = &( lp->stats );
  552. }
  553. /* Accumulate the timeout error */
  554. pStats->tx_errors++;
  555. wl_unlock( lp, &flags );
  556. DBG_LEAVE( DbgInfo );
  557. return;
  558. } // wl_tx_timeout
  559. /*============================================================================*/
  560. /*******************************************************************************
  561. * wl_send()
  562. *******************************************************************************
  563. *
  564. * DESCRIPTION:
  565. *
  566. * The routine which performs data transmits.
  567. *
  568. * PARAMETERS:
  569. *
  570. * lp - a pointer to the device's wl_private struct.
  571. *
  572. * RETURNS:
  573. *
  574. * 0 on success
  575. * 1 on error
  576. *
  577. ******************************************************************************/
  578. int wl_send( struct wl_private *lp )
  579. {
  580. int status;
  581. DESC_STRCT *desc;
  582. WVLAN_LFRAME *txF = NULL;
  583. struct list_head *element;
  584. int len;
  585. /*------------------------------------------------------------------------*/
  586. DBG_FUNC( "wl_send" );
  587. if( lp == NULL ) {
  588. DBG_ERROR( DbgInfo, "Private adapter struct is NULL\n" );
  589. return FALSE;
  590. }
  591. if( lp->dev == NULL ) {
  592. DBG_ERROR( DbgInfo, "net_device struct in wl_private is NULL\n" );
  593. return FALSE;
  594. }
  595. /* Check for the availability of FIDs; if none are available, don't take any
  596. frames off the txQ */
  597. if( lp->hcfCtx.IFB_RscInd == 0 ) {
  598. return FALSE;
  599. }
  600. /* Reclaim the TxQ Elements and place them back on the free queue */
  601. if( !list_empty( &( lp->txQ[0] ))) {
  602. element = lp->txQ[0].next;
  603. txF = (WVLAN_LFRAME * )list_entry( element, WVLAN_LFRAME, node );
  604. if( txF != NULL ) {
  605. lp->txF.skb = txF->frame.skb;
  606. lp->txF.port = txF->frame.port;
  607. txF->frame.skb = NULL;
  608. txF->frame.port = 0;
  609. list_del( &( txF->node ));
  610. list_add( element, &( lp->txFree ));
  611. lp->txQ_count--;
  612. if( lp->txQ_count < TX_Q_LOW_WATER_MARK ) {
  613. if( lp->netif_queue_on == FALSE ) {
  614. DBG_TX( DbgInfo, "Kickstarting Q: %d\n", lp->txQ_count );
  615. netif_wake_queue( lp->dev );
  616. WL_WDS_NETIF_WAKE_QUEUE( lp );
  617. lp->netif_queue_on = TRUE;
  618. }
  619. }
  620. }
  621. }
  622. if( lp->txF.skb == NULL ) {
  623. return FALSE;
  624. }
  625. /* If the device has resources (FIDs) available, then Tx the packet */
  626. /* Format the TxRequest and send it to the adapter */
  627. len = lp->txF.skb->len < ETH_ZLEN ? ETH_ZLEN : lp->txF.skb->len;
  628. desc = &( lp->desc_tx );
  629. desc->buf_addr = lp->txF.skb->data;
  630. desc->BUF_CNT = len;
  631. desc->next_desc_addr = NULL;
  632. status = hcf_send_msg( &( lp->hcfCtx ), desc, lp->txF.port );
  633. if( status == HCF_SUCCESS ) {
  634. lp->dev->trans_start = jiffies;
  635. DBG_TX( DbgInfo, "Transmit...\n" );
  636. if( lp->txF.port == HCF_PORT_0 ) {
  637. lp->stats.tx_packets++;
  638. lp->stats.tx_bytes += lp->txF.skb->len;
  639. }
  640. #ifdef USE_WDS
  641. else
  642. {
  643. lp->wds_port[(( lp->txF.port >> 8 ) - 1)].stats.tx_packets++;
  644. lp->wds_port[(( lp->txF.port >> 8 ) - 1)].stats.tx_bytes += lp->txF.skb->len;
  645. }
  646. #endif /* USE_WDS */
  647. /* Free the skb and perform queue cleanup, as the buffer was
  648. transmitted successfully */
  649. dev_kfree_skb( lp->txF.skb );
  650. lp->txF.skb = NULL;
  651. lp->txF.port = 0;
  652. }
  653. return TRUE;
  654. } // wl_send
  655. /*============================================================================*/
  656. /*******************************************************************************
  657. * wl_tx()
  658. *******************************************************************************
  659. *
  660. * DESCRIPTION:
  661. *
  662. * The Tx handler function for the network layer.
  663. *
  664. * PARAMETERS:
  665. *
  666. * skb - a pointer to the sk_buff structure containing the data to transfer.
  667. * dev - a pointer to the device's net_device structure.
  668. *
  669. * RETURNS:
  670. *
  671. * 0 on success
  672. * 1 on error
  673. *
  674. ******************************************************************************/
  675. int wl_tx( struct sk_buff *skb, struct net_device *dev, int port )
  676. {
  677. unsigned long flags;
  678. struct wl_private *lp = wl_priv(dev);
  679. WVLAN_LFRAME *txF = NULL;
  680. struct list_head *element;
  681. /*------------------------------------------------------------------------*/
  682. DBG_FUNC( "wl_tx" );
  683. /* Grab the spinlock */
  684. wl_lock( lp, &flags );
  685. if( lp->flags & WVLAN2_UIL_BUSY ) {
  686. DBG_WARNING( DbgInfo, "UIL has device blocked\n" );
  687. /* Start dropping packets here??? */
  688. wl_unlock( lp, &flags );
  689. return 1;
  690. }
  691. #ifdef USE_RTS
  692. if( lp->useRTS == 1 ) {
  693. DBG_PRINT( "RTS: we're getting a Tx...\n" );
  694. wl_unlock( lp, &flags );
  695. return 1;
  696. }
  697. #endif /* USE_RTS */
  698. if( !lp->use_dma ) {
  699. /* Get an element from the queue */
  700. element = lp->txFree.next;
  701. txF = (WVLAN_LFRAME *)list_entry( element, WVLAN_LFRAME, node );
  702. if( txF == NULL ) {
  703. DBG_ERROR( DbgInfo, "Problem with list_entry\n" );
  704. wl_unlock( lp, &flags );
  705. return 1;
  706. }
  707. /* Fill out the frame */
  708. txF->frame.skb = skb;
  709. txF->frame.port = port;
  710. /* Move the frame to the txQ */
  711. /* NOTE: Here's where we would do priority queueing */
  712. list_del( &( txF->node ));
  713. list_add( &( txF->node ), &( lp->txQ[0] ));
  714. lp->txQ_count++;
  715. if( lp->txQ_count >= DEFAULT_NUM_TX_FRAMES ) {
  716. DBG_TX( DbgInfo, "Q Full: %d\n", lp->txQ_count );
  717. if( lp->netif_queue_on == TRUE ) {
  718. netif_stop_queue( lp->dev );
  719. WL_WDS_NETIF_STOP_QUEUE( lp );
  720. lp->netif_queue_on = FALSE;
  721. }
  722. }
  723. }
  724. wl_act_int_off( lp ); /* Disable Interrupts */
  725. /* Send the data to the hardware using the appropriate method */
  726. #ifdef ENABLE_DMA
  727. if( lp->use_dma ) {
  728. wl_send_dma( lp, skb, port );
  729. }
  730. else
  731. #endif
  732. {
  733. wl_send( lp );
  734. }
  735. /* Re-enable Interrupts, release the spinlock and return */
  736. wl_act_int_on( lp );
  737. wl_unlock( lp, &flags );
  738. return 0;
  739. } // wl_tx
  740. /*============================================================================*/
  741. /*******************************************************************************
  742. * wl_rx()
  743. *******************************************************************************
  744. *
  745. * DESCRIPTION:
  746. *
  747. * The routine which performs data reception.
  748. *
  749. * PARAMETERS:
  750. *
  751. * dev - a pointer to the device's net_device structure.
  752. *
  753. * RETURNS:
  754. *
  755. * 0 on success
  756. * 1 on error
  757. *
  758. ******************************************************************************/
  759. int wl_rx(struct net_device *dev)
  760. {
  761. int port;
  762. struct sk_buff *skb;
  763. struct wl_private *lp = wl_priv(dev);
  764. int status;
  765. hcf_16 pktlen;
  766. hcf_16 hfs_stat;
  767. DESC_STRCT *desc;
  768. /*------------------------------------------------------------------------*/
  769. DBG_FUNC("wl_rx")
  770. DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
  771. if(!( lp->flags & WVLAN2_UIL_BUSY )) {
  772. #ifdef USE_RTS
  773. if( lp->useRTS == 1 ) {
  774. DBG_PRINT( "RTS: We're getting an Rx...\n" );
  775. return -EIO;
  776. }
  777. #endif /* USE_RTS */
  778. /* Read the HFS_STAT register from the lookahead buffer */
  779. hfs_stat = (hcf_16)(( lp->lookAheadBuf[HFS_STAT] ) |
  780. ( lp->lookAheadBuf[HFS_STAT + 1] << 8 ));
  781. /* Make sure the frame isn't bad */
  782. if(( hfs_stat & HFS_STAT_ERR ) != HCF_SUCCESS ) {
  783. DBG_WARNING( DbgInfo, "HFS_STAT_ERROR (0x%x) in Rx Packet\n",
  784. lp->lookAheadBuf[HFS_STAT] );
  785. return -EIO;
  786. }
  787. /* Determine what port this packet is for */
  788. port = ( hfs_stat >> 8 ) & 0x0007;
  789. DBG_RX( DbgInfo, "Rx frame for port %d\n", port );
  790. pktlen = lp->hcfCtx.IFB_RxLen;
  791. if (pktlen != 0) {
  792. skb = ALLOC_SKB(pktlen);
  793. if (skb != NULL) {
  794. /* Set the netdev based on the port */
  795. switch( port ) {
  796. #ifdef USE_WDS
  797. case 1:
  798. case 2:
  799. case 3:
  800. case 4:
  801. case 5:
  802. case 6:
  803. skb->dev = lp->wds_port[port-1].dev;
  804. break;
  805. #endif /* USE_WDS */
  806. case 0:
  807. default:
  808. skb->dev = dev;
  809. break;
  810. }
  811. desc = &( lp->desc_rx );
  812. desc->next_desc_addr = NULL;
  813. /*
  814. #define BLOCK_INPUT(buf, len) \
  815. desc->buf_addr = buf; \
  816. desc->BUF_SIZE = len; \
  817. status = hcf_rcv_msg(&(lp->hcfCtx), desc, 0)
  818. */
  819. GET_PACKET( skb->dev, skb, pktlen );
  820. if( status == HCF_SUCCESS ) {
  821. netif_rx( skb );
  822. if( port == 0 ) {
  823. lp->stats.rx_packets++;
  824. lp->stats.rx_bytes += pktlen;
  825. }
  826. #ifdef USE_WDS
  827. else
  828. {
  829. lp->wds_port[port-1].stats.rx_packets++;
  830. lp->wds_port[port-1].stats.rx_bytes += pktlen;
  831. }
  832. #endif /* USE_WDS */
  833. dev->last_rx = jiffies;
  834. #ifdef WIRELESS_EXT
  835. #ifdef WIRELESS_SPY
  836. if( lp->spydata.spy_number > 0 ) {
  837. char *srcaddr = skb->mac.raw + MAC_ADDR_SIZE;
  838. wl_spy_gather( dev, srcaddr );
  839. }
  840. #endif /* WIRELESS_SPY */
  841. #endif /* WIRELESS_EXT */
  842. } else {
  843. DBG_ERROR( DbgInfo, "Rx request to card FAILED\n" );
  844. if( port == 0 ) {
  845. lp->stats.rx_dropped++;
  846. }
  847. #ifdef USE_WDS
  848. else
  849. {
  850. lp->wds_port[port-1].stats.rx_dropped++;
  851. }
  852. #endif /* USE_WDS */
  853. dev_kfree_skb( skb );
  854. }
  855. } else {
  856. DBG_ERROR( DbgInfo, "Could not alloc skb\n" );
  857. if( port == 0 ) {
  858. lp->stats.rx_dropped++;
  859. }
  860. #ifdef USE_WDS
  861. else
  862. {
  863. lp->wds_port[port-1].stats.rx_dropped++;
  864. }
  865. #endif /* USE_WDS */
  866. }
  867. }
  868. }
  869. return 0;
  870. } // wl_rx
  871. /*============================================================================*/
  872. /*******************************************************************************
  873. * wl_multicast()
  874. *******************************************************************************
  875. *
  876. * DESCRIPTION:
  877. *
  878. * Function to handle multicast packets
  879. *
  880. * PARAMETERS:
  881. *
  882. * dev - a pointer to the device's net_device structure.
  883. *
  884. * RETURNS:
  885. *
  886. * N/A
  887. *
  888. ******************************************************************************/
  889. #ifdef NEW_MULTICAST
  890. void wl_multicast( struct net_device *dev )
  891. {
  892. #if 1 //;? (HCF_TYPE) & HCF_TYPE_STA //;?should we return an error status in AP mode
  893. //;?seems reasonable that even an AP-only driver could afford this small additional footprint
  894. int x;
  895. struct netdev_hw_addr *ha;
  896. struct wl_private *lp = wl_priv(dev);
  897. unsigned long flags;
  898. /*------------------------------------------------------------------------*/
  899. DBG_FUNC( "wl_multicast" );
  900. DBG_ENTER( DbgInfo );
  901. DBG_PARAM( DbgInfo, "dev", "%s (0x%p)", dev->name, dev );
  902. if( !wl_adapter_is_open( dev )) {
  903. DBG_LEAVE( DbgInfo );
  904. return;
  905. }
  906. #if DBG
  907. if( DBG_FLAGS( DbgInfo ) & DBG_PARAM_ON ) {
  908. DBG_PRINT(" flags: %s%s%s\n",
  909. ( dev->flags & IFF_PROMISC ) ? "Promiscous " : "",
  910. ( dev->flags & IFF_MULTICAST ) ? "Multicast " : "",
  911. ( dev->flags & IFF_ALLMULTI ) ? "All-Multicast" : "" );
  912. DBG_PRINT( " mc_count: %d\n", netdev_mc_count(dev));
  913. netdev_for_each_mc_addr(ha, dev)
  914. DBG_PRINT(" %pM (%d)\n", ha->addr, dev->addr_len);
  915. }
  916. #endif /* DBG */
  917. if(!( lp->flags & WVLAN2_UIL_BUSY )) {
  918. #ifdef USE_RTS
  919. if( lp->useRTS == 1 ) {
  920. DBG_TRACE( DbgInfo, "Skipping multicast, in RTS mode\n" );
  921. DBG_LEAVE( DbgInfo );
  922. return;
  923. }
  924. #endif /* USE_RTS */
  925. wl_lock( lp, &flags );
  926. wl_act_int_off( lp );
  927. if ( CNV_INT_TO_LITTLE( lp->hcfCtx.IFB_FWIdentity.comp_id ) == COMP_ID_FW_STA ) {
  928. if( dev->flags & IFF_PROMISC ) {
  929. /* Enable promiscuous mode */
  930. lp->ltvRecord.len = 2;
  931. lp->ltvRecord.typ = CFG_PROMISCUOUS_MODE;
  932. lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( 1 );
  933. DBG_PRINT( "Enabling Promiscuous mode (IFF_PROMISC)\n" );
  934. hcf_put_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));
  935. }
  936. else if ((netdev_mc_count(dev) > HCF_MAX_MULTICAST) ||
  937. ( dev->flags & IFF_ALLMULTI )) {
  938. /* Shutting off this filter will enable all multicast frames to
  939. be sent up from the device; however, this is a static RID, so
  940. a call to wl_apply() is needed */
  941. lp->ltvRecord.len = 2;
  942. lp->ltvRecord.typ = CFG_CNF_RX_ALL_GROUP_ADDR;
  943. lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( 0 );
  944. DBG_PRINT( "Enabling all multicast mode (IFF_ALLMULTI)\n" );
  945. hcf_put_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));
  946. wl_apply( lp );
  947. }
  948. else if (!netdev_mc_empty(dev)) {
  949. /* Set the multicast addresses */
  950. lp->ltvRecord.len = ( netdev_mc_count(dev) * 3 ) + 1;
  951. lp->ltvRecord.typ = CFG_GROUP_ADDR;
  952. x = 0;
  953. netdev_for_each_mc_addr(ha, dev)
  954. memcpy(&(lp->ltvRecord.u.u8[x++ * ETH_ALEN]),
  955. ha->addr, ETH_ALEN);
  956. DBG_PRINT( "Setting multicast list\n" );
  957. hcf_put_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));
  958. } else {
  959. /* Disable promiscuous mode */
  960. lp->ltvRecord.len = 2;
  961. lp->ltvRecord.typ = CFG_PROMISCUOUS_MODE;
  962. lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( 0 );
  963. DBG_PRINT( "Disabling Promiscuous mode\n" );
  964. hcf_put_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));
  965. /* Disable multicast mode */
  966. lp->ltvRecord.len = 2;
  967. lp->ltvRecord.typ = CFG_GROUP_ADDR;
  968. DBG_PRINT( "Disabling Multicast mode\n" );
  969. hcf_put_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));
  970. /* Turning on this filter will prevent all multicast frames from
  971. being sent up from the device; however, this is a static RID,
  972. so a call to wl_apply() is needed */
  973. lp->ltvRecord.len = 2;
  974. lp->ltvRecord.typ = CFG_CNF_RX_ALL_GROUP_ADDR;
  975. lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( 1 );
  976. DBG_PRINT( "Disabling all multicast mode (IFF_ALLMULTI)\n" );
  977. hcf_put_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));
  978. wl_apply( lp );
  979. }
  980. }
  981. wl_act_int_on( lp );
  982. wl_unlock( lp, &flags );
  983. }
  984. DBG_LEAVE( DbgInfo );
  985. #endif /* HCF_STA */
  986. } // wl_multicast
  987. /*============================================================================*/
  988. #else /* NEW_MULTICAST */
  989. void wl_multicast( struct net_device *dev, int num_addrs, void *addrs )
  990. {
  991. DBG_FUNC( "wl_multicast");
  992. DBG_ENTER(DbgInfo);
  993. DBG_PARAM( DbgInfo, "dev", "%s (0x%p)", dev->name, dev );
  994. DBG_PARAM( DbgInfo, "num_addrs", "%d", num_addrs );
  995. DBG_PARAM( DbgInfo, "addrs", "0x%p", addrs );
  996. #error Obsolete set multicast interface!
  997. DBG_LEAVE( DbgInfo );
  998. } // wl_multicast
  999. /*============================================================================*/
  1000. #endif /* NEW_MULTICAST */
  1001. static const struct net_device_ops wl_netdev_ops =
  1002. {
  1003. .ndo_start_xmit = &wl_tx_port0,
  1004. .ndo_set_config = &wl_config,
  1005. .ndo_get_stats = &wl_stats,
  1006. .ndo_set_multicast_list = &wl_multicast,
  1007. .ndo_init = &wl_insert,
  1008. .ndo_open = &wl_adapter_open,
  1009. .ndo_stop = &wl_adapter_close,
  1010. .ndo_do_ioctl = &wl_ioctl,
  1011. .ndo_tx_timeout = &wl_tx_timeout,
  1012. #ifdef CONFIG_NET_POLL_CONTROLLER
  1013. .ndo_poll_controller = wl_poll,
  1014. #endif
  1015. };
  1016. /*******************************************************************************
  1017. * wl_device_alloc()
  1018. *******************************************************************************
  1019. *
  1020. * DESCRIPTION:
  1021. *
  1022. * Create instances of net_device and wl_private for the new adapter
  1023. * and register the device's entry points in the net_device structure.
  1024. *
  1025. * PARAMETERS:
  1026. *
  1027. * N/A
  1028. *
  1029. * RETURNS:
  1030. *
  1031. * a pointer to an allocated and initialized net_device struct for this
  1032. * device.
  1033. *
  1034. ******************************************************************************/
  1035. struct net_device * wl_device_alloc( void )
  1036. {
  1037. struct net_device *dev = NULL;
  1038. struct wl_private *lp = NULL;
  1039. /*------------------------------------------------------------------------*/
  1040. DBG_FUNC( "wl_device_alloc" );
  1041. DBG_ENTER( DbgInfo );
  1042. /* Alloc a net_device struct */
  1043. dev = alloc_etherdev(sizeof(struct wl_private));
  1044. if (!dev)
  1045. return NULL;
  1046. /* Initialize the 'next' pointer in the struct. Currently only used for PCI,
  1047. but do it here just in case it's used for other buses in the future */
  1048. lp = wl_priv(dev);
  1049. /* Check MTU */
  1050. if( dev->mtu > MTU_MAX )
  1051. {
  1052. DBG_WARNING( DbgInfo, "%s: MTU set too high, limiting to %d.\n",
  1053. dev->name, MTU_MAX );
  1054. dev->mtu = MTU_MAX;
  1055. }
  1056. /* Setup the function table in the device structure. */
  1057. dev->wireless_handlers = (struct iw_handler_def *)&wl_iw_handler_def;
  1058. lp->wireless_data.spy_data = &lp->spy_data;
  1059. dev->wireless_data = &lp->wireless_data;
  1060. dev->netdev_ops = &wl_netdev_ops;
  1061. dev->watchdog_timeo = TX_TIMEOUT;
  1062. dev->ethtool_ops = &wl_ethtool_ops;
  1063. netif_stop_queue( dev );
  1064. /* Allocate virutal devices for WDS support if needed */
  1065. WL_WDS_DEVICE_ALLOC( lp );
  1066. DBG_LEAVE( DbgInfo );
  1067. return dev;
  1068. } // wl_device_alloc
  1069. /*============================================================================*/
  1070. /*******************************************************************************
  1071. * wl_device_dealloc()
  1072. *******************************************************************************
  1073. *
  1074. * DESCRIPTION:
  1075. *
  1076. * Free instances of net_device and wl_private strcutres for an adapter
  1077. * and perform basic cleanup.
  1078. *
  1079. * PARAMETERS:
  1080. *
  1081. * dev - a pointer to the device's net_device structure.
  1082. *
  1083. * RETURNS:
  1084. *
  1085. * N/A
  1086. *
  1087. ******************************************************************************/
  1088. void wl_device_dealloc( struct net_device *dev )
  1089. {
  1090. // struct wl_private *lp = wl_priv(dev);
  1091. /*------------------------------------------------------------------------*/
  1092. DBG_FUNC( "wl_device_dealloc" );
  1093. DBG_ENTER( DbgInfo );
  1094. /* Dealloc the WDS ports */
  1095. WL_WDS_DEVICE_DEALLOC( lp );
  1096. free_netdev( dev );
  1097. DBG_LEAVE( DbgInfo );
  1098. return;
  1099. } // wl_device_dealloc
  1100. /*============================================================================*/
  1101. /*******************************************************************************
  1102. * wl_tx_port0()
  1103. *******************************************************************************
  1104. *
  1105. * DESCRIPTION:
  1106. *
  1107. * The handler routine for Tx over HCF_PORT_0.
  1108. *
  1109. * PARAMETERS:
  1110. *
  1111. * skb - a pointer to the sk_buff to transmit.
  1112. * dev - a pointer to a net_device structure representing HCF_PORT_0.
  1113. *
  1114. * RETURNS:
  1115. *
  1116. * N/A
  1117. *
  1118. ******************************************************************************/
  1119. int wl_tx_port0( struct sk_buff *skb, struct net_device *dev )
  1120. {
  1121. DBG_TX( DbgInfo, "Tx on Port 0\n" );
  1122. return wl_tx( skb, dev, HCF_PORT_0 );
  1123. #ifdef ENABLE_DMA
  1124. return wl_tx_dma( skb, dev, HCF_PORT_0 );
  1125. #endif
  1126. } // wl_tx_port0
  1127. /*============================================================================*/
  1128. #ifdef USE_WDS
  1129. /*******************************************************************************
  1130. * wl_tx_port1()
  1131. *******************************************************************************
  1132. *
  1133. * DESCRIPTION:
  1134. *
  1135. * The handler routine for Tx over HCF_PORT_1.
  1136. *
  1137. * PARAMETERS:
  1138. *
  1139. * skb - a pointer to the sk_buff to transmit.
  1140. * dev - a pointer to a net_device structure representing HCF_PORT_1.
  1141. *
  1142. * RETURNS:
  1143. *
  1144. * N/A
  1145. *
  1146. ******************************************************************************/
  1147. int wl_tx_port1( struct sk_buff *skb, struct net_device *dev )
  1148. {
  1149. DBG_TX( DbgInfo, "Tx on Port 1\n" );
  1150. return wl_tx( skb, dev, HCF_PORT_1 );
  1151. } // wl_tx_port1
  1152. /*============================================================================*/
  1153. /*******************************************************************************
  1154. * wl_tx_port2()
  1155. *******************************************************************************
  1156. *
  1157. * DESCRIPTION:
  1158. *
  1159. * The handler routine for Tx over HCF_PORT_2.
  1160. *
  1161. * PARAMETERS:
  1162. *
  1163. * skb - a pointer to the sk_buff to transmit.
  1164. * dev - a pointer to a net_device structure representing HCF_PORT_2.
  1165. *
  1166. * RETURNS:
  1167. *
  1168. * N/A
  1169. *
  1170. ******************************************************************************/
  1171. int wl_tx_port2( struct sk_buff *skb, struct net_device *dev )
  1172. {
  1173. DBG_TX( DbgInfo, "Tx on Port 2\n" );
  1174. return wl_tx( skb, dev, HCF_PORT_2 );
  1175. } // wl_tx_port2
  1176. /*============================================================================*/
  1177. /*******************************************************************************
  1178. * wl_tx_port3()
  1179. *******************************************************************************
  1180. *
  1181. * DESCRIPTION:
  1182. *
  1183. * The handler routine for Tx over HCF_PORT_3.
  1184. *
  1185. * PARAMETERS:
  1186. *
  1187. * skb - a pointer to the sk_buff to transmit.
  1188. * dev - a pointer to a net_device structure representing HCF_PORT_3.
  1189. *
  1190. * RETURNS:
  1191. *
  1192. * N/A
  1193. *
  1194. ******************************************************************************/
  1195. int wl_tx_port3( struct sk_buff *skb, struct net_device *dev )
  1196. {
  1197. DBG_TX( DbgInfo, "Tx on Port 3\n" );
  1198. return wl_tx( skb, dev, HCF_PORT_3 );
  1199. } // wl_tx_port3
  1200. /*============================================================================*/
  1201. /*******************************************************************************
  1202. * wl_tx_port4()
  1203. *******************************************************************************
  1204. *
  1205. * DESCRIPTION:
  1206. *
  1207. * The handler routine for Tx over HCF_PORT_4.
  1208. *
  1209. * PARAMETERS:
  1210. *
  1211. * skb - a pointer to the sk_buff to transmit.
  1212. * dev - a pointer to a net_device structure representing HCF_PORT_4.
  1213. *
  1214. * RETURNS:
  1215. *
  1216. * N/A
  1217. *
  1218. ******************************************************************************/
  1219. int wl_tx_port4( struct sk_buff *skb, struct net_device *dev )
  1220. {
  1221. DBG_TX( DbgInfo, "Tx on Port 4\n" );
  1222. return wl_tx( skb, dev, HCF_PORT_4 );
  1223. } // wl_tx_port4
  1224. /*============================================================================*/
  1225. /*******************************************************************************
  1226. * wl_tx_port5()
  1227. *******************************************************************************
  1228. *
  1229. * DESCRIPTION:
  1230. *
  1231. * The handler routine for Tx over HCF_PORT_5.
  1232. *
  1233. * PARAMETERS:
  1234. *
  1235. * skb - a pointer to the sk_buff to transmit.
  1236. * dev - a pointer to a net_device structure representing HCF_PORT_5.
  1237. *
  1238. * RETURNS:
  1239. *
  1240. * N/A
  1241. *
  1242. ******************************************************************************/
  1243. int wl_tx_port5( struct sk_buff *skb, struct net_device *dev )
  1244. {
  1245. DBG_TX( DbgInfo, "Tx on Port 5\n" );
  1246. return wl_tx( skb, dev, HCF_PORT_5 );
  1247. } // wl_tx_port5
  1248. /*============================================================================*/
  1249. /*******************************************************************************
  1250. * wl_tx_port6()
  1251. *******************************************************************************
  1252. *
  1253. * DESCRIPTION:
  1254. *
  1255. * The handler routine for Tx over HCF_PORT_6.
  1256. *
  1257. * PARAMETERS:
  1258. *
  1259. * skb - a pointer to the sk_buff to transmit.
  1260. * dev - a pointer to a net_device structure representing HCF_PORT_6.
  1261. *
  1262. * RETURNS:
  1263. *
  1264. * N/A
  1265. *
  1266. ******************************************************************************/
  1267. int wl_tx_port6( struct sk_buff *skb, struct net_device *dev )
  1268. {
  1269. DBG_TX( DbgInfo, "Tx on Port 6\n" );
  1270. return wl_tx( skb, dev, HCF_PORT_6 );
  1271. } // wl_tx_port6
  1272. /*============================================================================*/
  1273. /*******************************************************************************
  1274. * wl_wds_device_alloc()
  1275. *******************************************************************************
  1276. *
  1277. * DESCRIPTION:
  1278. *
  1279. * Create instances of net_device to represent the WDS ports, and register
  1280. * the device's entry points in the net_device structure.
  1281. *
  1282. * PARAMETERS:
  1283. *
  1284. * lp - a pointer to the device's private adapter structure
  1285. *
  1286. * RETURNS:
  1287. *
  1288. * N/A, but will place pointers to the allocated and initialized net_device
  1289. * structs in the private adapter structure.
  1290. *
  1291. ******************************************************************************/
  1292. void wl_wds_device_alloc( struct wl_private *lp )
  1293. {
  1294. int count;
  1295. /*------------------------------------------------------------------------*/
  1296. DBG_FUNC( "wl_wds_device_alloc" );
  1297. DBG_ENTER( DbgInfo );
  1298. /* WDS support requires additional net_device structs to be allocated,
  1299. so that user space apps can use these virtual devices to specify the
  1300. port on which to Tx/Rx */
  1301. for( count = 0; count < NUM_WDS_PORTS; count++ ) {
  1302. struct net_device *dev_wds = NULL;
  1303. dev_wds = kmalloc( sizeof( struct net_device ), GFP_KERNEL );
  1304. memset( dev_wds, 0, sizeof( struct net_device ));
  1305. ether_setup( dev_wds );
  1306. lp->wds_port[count].dev = dev_wds;
  1307. /* Re-use wl_init for all the devices, as it currently does nothing, but
  1308. is required. Re-use the stats/tx_timeout handler for all as well; the
  1309. WDS port which is requesting these operations can be determined by
  1310. the net_device pointer. Set the private member of all devices to point
  1311. to the same net_device struct; that way, all information gets
  1312. funnelled through the one "real" net_device. Name the WDS ports
  1313. "wds<n>" */
  1314. lp->wds_port[count].dev->init = &wl_init;
  1315. lp->wds_port[count].dev->get_stats = &wl_stats;
  1316. lp->wds_port[count].dev->tx_timeout = &wl_tx_timeout;
  1317. lp->wds_port[count].dev->watchdog_timeo = TX_TIMEOUT;
  1318. lp->wds_port[count].dev->priv = lp;
  1319. sprintf( lp->wds_port[count].dev->name, "wds%d", count );
  1320. }
  1321. /* Register the Tx handlers */
  1322. lp->wds_port[0].dev->hard_start_xmit = &wl_tx_port1;
  1323. lp->wds_port[1].dev->hard_start_xmit = &wl_tx_port2;
  1324. lp->wds_port[2].dev->hard_start_xmit = &wl_tx_port3;
  1325. lp->wds_port[3].dev->hard_start_xmit = &wl_tx_port4;
  1326. lp->wds_port[4].dev->hard_start_xmit = &wl_tx_port5;
  1327. lp->wds_port[5].dev->hard_start_xmit = &wl_tx_port6;
  1328. WL_WDS_NETIF_STOP_QUEUE( lp );
  1329. DBG_LEAVE( DbgInfo );
  1330. return;
  1331. } // wl_wds_device_alloc
  1332. /*============================================================================*/
  1333. /*******************************************************************************
  1334. * wl_wds_device_dealloc()
  1335. *******************************************************************************
  1336. *
  1337. * DESCRIPTION:
  1338. *
  1339. * Free instances of net_device structures used to support WDS.
  1340. *
  1341. * PARAMETERS:
  1342. *
  1343. * lp - a pointer to the device's private adapter structure
  1344. *
  1345. * RETURNS:
  1346. *
  1347. * N/A
  1348. *
  1349. ******************************************************************************/
  1350. void wl_wds_device_dealloc( struct wl_private *lp )
  1351. {
  1352. int count;
  1353. /*------------------------------------------------------------------------*/
  1354. DBG_FUNC( "wl_wds_device_dealloc" );
  1355. DBG_ENTER( DbgInfo );
  1356. for( count = 0; count < NUM_WDS_PORTS; count++ ) {
  1357. struct net_device *dev_wds = NULL;
  1358. dev_wds = lp->wds_port[count].dev;
  1359. if( dev_wds != NULL ) {
  1360. if( dev_wds->flags & IFF_UP ) {
  1361. dev_close( dev_wds );
  1362. dev_wds->flags &= ~( IFF_UP | IFF_RUNNING );
  1363. }
  1364. free_netdev(dev_wds);
  1365. lp->wds_port[count].dev = NULL;
  1366. }
  1367. }
  1368. DBG_LEAVE( DbgInfo );
  1369. return;
  1370. } // wl_wds_device_dealloc
  1371. /*============================================================================*/
  1372. /*******************************************************************************
  1373. * wl_wds_netif_start_queue()
  1374. *******************************************************************************
  1375. *
  1376. * DESCRIPTION:
  1377. *
  1378. * Used to start the netif queues of all the "virtual" network devices
  1379. * which repesent the WDS ports.
  1380. *
  1381. * PARAMETERS:
  1382. *
  1383. * lp - a pointer to the device's private adapter structure
  1384. *
  1385. * RETURNS:
  1386. *
  1387. * N/A
  1388. *
  1389. ******************************************************************************/
  1390. void wl_wds_netif_start_queue( struct wl_private *lp )
  1391. {
  1392. int count;
  1393. /*------------------------------------------------------------------------*/
  1394. if( lp != NULL ) {
  1395. for( count = 0; count < NUM_WDS_PORTS; count++ ) {
  1396. if( lp->wds_port[count].is_registered &&
  1397. lp->wds_port[count].netif_queue_on == FALSE ) {
  1398. netif_start_queue( lp->wds_port[count].dev );
  1399. lp->wds_port[count].netif_queue_on = TRUE;
  1400. }
  1401. }
  1402. }
  1403. return;
  1404. } // wl_wds_netif_start_queue
  1405. /*============================================================================*/
  1406. /*******************************************************************************
  1407. * wl_wds_netif_stop_queue()
  1408. *******************************************************************************
  1409. *
  1410. * DESCRIPTION:
  1411. *
  1412. * Used to stop the netif queues of all the "virtual" network devices
  1413. * which repesent the WDS ports.
  1414. *
  1415. * PARAMETERS:
  1416. *
  1417. * lp - a pointer to the device's private adapter structure
  1418. *
  1419. * RETURNS:
  1420. *
  1421. * N/A
  1422. *
  1423. ******************************************************************************/
  1424. void wl_wds_netif_stop_queue( struct wl_private *lp )
  1425. {
  1426. int count;
  1427. /*------------------------------------------------------------------------*/
  1428. if( lp != NULL ) {
  1429. for( count = 0; count < NUM_WDS_PORTS; count++ ) {
  1430. if( lp->wds_port[count].is_registered &&
  1431. lp->wds_port[count].netif_queue_on == TRUE ) {
  1432. netif_stop_queue( lp->wds_port[count].dev );
  1433. lp->wds_port[count].netif_queue_on = FALSE;
  1434. }
  1435. }
  1436. }
  1437. return;
  1438. } // wl_wds_netif_stop_queue
  1439. /*============================================================================*/
  1440. /*******************************************************************************
  1441. * wl_wds_netif_wake_queue()
  1442. *******************************************************************************
  1443. *
  1444. * DESCRIPTION:
  1445. *
  1446. * Used to wake the netif queues of all the "virtual" network devices
  1447. * which repesent the WDS ports.
  1448. *
  1449. * PARAMETERS:
  1450. *
  1451. * lp - a pointer to the device's private adapter structure
  1452. *
  1453. * RETURNS:
  1454. *
  1455. * N/A
  1456. *
  1457. ******************************************************************************/
  1458. void wl_wds_netif_wake_queue( struct wl_private *lp )
  1459. {
  1460. int count;
  1461. /*------------------------------------------------------------------------*/
  1462. if( lp != NULL ) {
  1463. for( count = 0; count < NUM_WDS_PORTS; count++ ) {
  1464. if( lp->wds_port[count].is_registered &&
  1465. lp->wds_port[count].netif_queue_on == FALSE ) {
  1466. netif_wake_queue( lp->wds_port[count].dev );
  1467. lp->wds_port[count].netif_queue_on = TRUE;
  1468. }
  1469. }
  1470. }
  1471. return;
  1472. } // wl_wds_netif_wake_queue
  1473. /*============================================================================*/
  1474. /*******************************************************************************
  1475. * wl_wds_netif_carrier_on()
  1476. *******************************************************************************
  1477. *
  1478. * DESCRIPTION:
  1479. *
  1480. * Used to signal the network layer that carrier is present on all of the
  1481. * "virtual" network devices which repesent the WDS ports.
  1482. *
  1483. * PARAMETERS:
  1484. *
  1485. * lp - a pointer to the device's private adapter structure
  1486. *
  1487. * RETURNS:
  1488. *
  1489. * N/A
  1490. *
  1491. ******************************************************************************/
  1492. void wl_wds_netif_carrier_on( struct wl_private *lp )
  1493. {
  1494. int count;
  1495. /*------------------------------------------------------------------------*/
  1496. if( lp != NULL ) {
  1497. for( count = 0; count < NUM_WDS_PORTS; count++ ) {
  1498. if( lp->wds_port[count].is_registered ) {
  1499. netif_carrier_on( lp->wds_port[count].dev );
  1500. }
  1501. }
  1502. }
  1503. return;
  1504. } // wl_wds_netif_carrier_on
  1505. /*============================================================================*/
  1506. /*******************************************************************************
  1507. * wl_wds_netif_carrier_off()
  1508. *******************************************************************************
  1509. *
  1510. * DESCRIPTION:
  1511. *
  1512. * Used to signal the network layer that carrier is NOT present on all of
  1513. * the "virtual" network devices which repesent the WDS ports.
  1514. *
  1515. * PARAMETERS:
  1516. *
  1517. * lp - a pointer to the device's private adapter structure
  1518. *
  1519. * RETURNS:
  1520. *
  1521. * N/A
  1522. *
  1523. ******************************************************************************/
  1524. void wl_wds_netif_carrier_off( struct wl_private *lp )
  1525. {
  1526. int count;
  1527. /*------------------------------------------------------------------------*/
  1528. if( lp != NULL ) {
  1529. for( count = 0; count < NUM_WDS_PORTS; count++ ) {
  1530. if( lp->wds_port[count].is_registered ) {
  1531. netif_carrier_off( lp->wds_port[count].dev );
  1532. }
  1533. }
  1534. }
  1535. return;
  1536. } // wl_wds_netif_carrier_off
  1537. /*============================================================================*/
  1538. #endif /* USE_WDS */
  1539. #ifdef ENABLE_DMA
  1540. /*******************************************************************************
  1541. * wl_send_dma()
  1542. *******************************************************************************
  1543. *
  1544. * DESCRIPTION:
  1545. *
  1546. * The routine which performs data transmits when using busmaster DMA.
  1547. *
  1548. * PARAMETERS:
  1549. *
  1550. * lp - a pointer to the device's wl_private struct.
  1551. * skb - a pointer to the network layer's data buffer.
  1552. * port - the Hermes port on which to transmit.
  1553. *
  1554. * RETURNS:
  1555. *
  1556. * 0 on success
  1557. * 1 on error
  1558. *
  1559. ******************************************************************************/
  1560. int wl_send_dma( struct wl_private *lp, struct sk_buff *skb, int port )
  1561. {
  1562. int len;
  1563. DESC_STRCT *desc = NULL;
  1564. DESC_STRCT *desc_next = NULL;
  1565. /*------------------------------------------------------------------------*/
  1566. DBG_FUNC( "wl_send_dma" );
  1567. if( lp == NULL )
  1568. {
  1569. DBG_ERROR( DbgInfo, "Private adapter struct is NULL\n" );
  1570. return FALSE;
  1571. }
  1572. if( lp->dev == NULL )
  1573. {
  1574. DBG_ERROR( DbgInfo, "net_device struct in wl_private is NULL\n" );
  1575. return FALSE;
  1576. }
  1577. /* AGAIN, ALL THE QUEUEING DONE HERE IN I/O MODE IS NOT PERFORMED */
  1578. if( skb == NULL )
  1579. {
  1580. DBG_WARNING (DbgInfo, "Nothing to send.\n");
  1581. return FALSE;
  1582. }
  1583. len = skb->len;
  1584. /* Get a free descriptor */
  1585. desc = wl_pci_dma_get_tx_packet( lp );
  1586. if( desc == NULL )
  1587. {
  1588. if( lp->netif_queue_on == TRUE ) {
  1589. netif_stop_queue( lp->dev );
  1590. WL_WDS_NETIF_STOP_QUEUE( lp );
  1591. lp->netif_queue_on = FALSE;
  1592. dev_kfree_skb( skb );
  1593. return 0;
  1594. }
  1595. }
  1596. SET_BUF_CNT( desc, /*HCF_DMA_FD_CNT*/HFS_ADDR_DEST );
  1597. SET_BUF_SIZE( desc, HCF_DMA_TX_BUF1_SIZE );
  1598. desc_next = desc->next_desc_addr;
  1599. if( desc_next->buf_addr == NULL )
  1600. {
  1601. DBG_ERROR( DbgInfo, "DMA descriptor buf_addr is NULL\n" );
  1602. return FALSE;
  1603. }
  1604. /* Copy the payload into the DMA packet */
  1605. memcpy( desc_next->buf_addr, skb->data, len );
  1606. SET_BUF_CNT( desc_next, len );
  1607. SET_BUF_SIZE( desc_next, HCF_MAX_PACKET_SIZE );
  1608. hcf_dma_tx_put( &( lp->hcfCtx ), desc, 0 );
  1609. /* Free the skb and perform queue cleanup, as the buffer was
  1610. transmitted successfully */
  1611. dev_kfree_skb( skb );
  1612. return TRUE;
  1613. } // wl_send_dma
  1614. /*============================================================================*/
  1615. /*******************************************************************************
  1616. * wl_rx_dma()
  1617. *******************************************************************************
  1618. *
  1619. * DESCRIPTION:
  1620. *
  1621. * The routine which performs data reception when using busmaster DMA.
  1622. *
  1623. * PARAMETERS:
  1624. *
  1625. * dev - a pointer to the device's net_device structure.
  1626. *
  1627. * RETURNS:
  1628. *
  1629. * 0 on success
  1630. * 1 on error
  1631. *
  1632. ******************************************************************************/
  1633. int wl_rx_dma( struct net_device *dev )
  1634. {
  1635. int port;
  1636. hcf_16 pktlen;
  1637. hcf_16 hfs_stat;
  1638. struct sk_buff *skb;
  1639. struct wl_private *lp = NULL;
  1640. DESC_STRCT *desc, *desc_next;
  1641. //CFG_MB_INFO_RANGE2_STRCT x;
  1642. /*------------------------------------------------------------------------*/
  1643. DBG_FUNC("wl_rx")
  1644. DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
  1645. if((( lp = dev->priv ) != NULL ) &&
  1646. !( lp->flags & WVLAN2_UIL_BUSY )) {
  1647. #ifdef USE_RTS
  1648. if( lp->useRTS == 1 ) {
  1649. DBG_PRINT( "RTS: We're getting an Rx...\n" );
  1650. return -EIO;
  1651. }
  1652. #endif /* USE_RTS */
  1653. //if( lp->dma.status == 0 )
  1654. //{
  1655. desc = hcf_dma_rx_get( &( lp->hcfCtx ));
  1656. if( desc != NULL )
  1657. {
  1658. /* Check and see if we rcvd. a WMP frame */
  1659. /*
  1660. if((( *(hcf_8 *)&desc->buf_addr[HFS_STAT] ) &
  1661. ( HFS_STAT_MSG_TYPE | HFS_STAT_ERR )) == HFS_STAT_WMP_MSG )
  1662. {
  1663. DBG_TRACE( DbgInfo, "Got a WMP frame\n" );
  1664. x.len = sizeof( CFG_MB_INFO_RANGE2_STRCT ) / sizeof( hcf_16 );
  1665. x.typ = CFG_MB_INFO;
  1666. x.base_typ = CFG_WMP;
  1667. x.frag_cnt = 2;
  1668. x.frag_buf[0].frag_len = GET_BUF_CNT( descp ) / sizeof( hcf_16 );
  1669. x.frag_buf[0].frag_addr = (hcf_8 *) descp->buf_addr ;
  1670. x.frag_buf[1].frag_len = ( GET_BUF_CNT( descp->next_desc_addr ) + 1 ) / sizeof( hcf_16 );
  1671. x.frag_buf[1].frag_addr = (hcf_8 *) descp->next_desc_addr->buf_addr ;
  1672. hcf_put_info( &( lp->hcfCtx ), (LTVP)&x );
  1673. }
  1674. */
  1675. desc_next = desc->next_desc_addr;
  1676. /* Make sure the buffer isn't empty */
  1677. if( GET_BUF_CNT( desc ) == 0 ) {
  1678. DBG_WARNING( DbgInfo, "Buffer is empty!\n" );
  1679. /* Give the descriptor back to the HCF */
  1680. hcf_dma_rx_put( &( lp->hcfCtx ), desc );
  1681. return -EIO;
  1682. }
  1683. /* Read the HFS_STAT register from the lookahead buffer */
  1684. hfs_stat = (hcf_16)( desc->buf_addr[HFS_STAT/2] );
  1685. /* Make sure the frame isn't bad */
  1686. if(( hfs_stat & HFS_STAT_ERR ) != HCF_SUCCESS )
  1687. {
  1688. DBG_WARNING( DbgInfo, "HFS_STAT_ERROR (0x%x) in Rx Packet\n",
  1689. desc->buf_addr[HFS_STAT/2] );
  1690. /* Give the descriptor back to the HCF */
  1691. hcf_dma_rx_put( &( lp->hcfCtx ), desc );
  1692. return -EIO;
  1693. }
  1694. /* Determine what port this packet is for */
  1695. port = ( hfs_stat >> 8 ) & 0x0007;
  1696. DBG_RX( DbgInfo, "Rx frame for port %d\n", port );
  1697. pktlen = GET_BUF_CNT(desc_next);
  1698. if (pktlen != 0) {
  1699. skb = ALLOC_SKB(pktlen);
  1700. if (skb != NULL) {
  1701. switch( port ) {
  1702. #ifdef USE_WDS
  1703. case 1:
  1704. case 2:
  1705. case 3:
  1706. case 4:
  1707. case 5:
  1708. case 6:
  1709. skb->dev = lp->wds_port[port-1].dev;
  1710. break;
  1711. #endif /* USE_WDS */
  1712. case 0:
  1713. default:
  1714. skb->dev = dev;
  1715. break;
  1716. }
  1717. GET_PACKET_DMA( skb->dev, skb, pktlen );
  1718. /* Give the descriptor back to the HCF */
  1719. hcf_dma_rx_put( &( lp->hcfCtx ), desc );
  1720. netif_rx( skb );
  1721. if( port == 0 ) {
  1722. lp->stats.rx_packets++;
  1723. lp->stats.rx_bytes += pktlen;
  1724. }
  1725. #ifdef USE_WDS
  1726. else
  1727. {
  1728. lp->wds_port[port-1].stats.rx_packets++;
  1729. lp->wds_port[port-1].stats.rx_bytes += pktlen;
  1730. }
  1731. #endif /* USE_WDS */
  1732. dev->last_rx = jiffies;
  1733. } else {
  1734. DBG_ERROR( DbgInfo, "Could not alloc skb\n" );
  1735. if( port == 0 )
  1736. {
  1737. lp->stats.rx_dropped++;
  1738. }
  1739. #ifdef USE_WDS
  1740. else
  1741. {
  1742. lp->wds_port[port-1].stats.rx_dropped++;
  1743. }
  1744. #endif /* USE_WDS */
  1745. }
  1746. }
  1747. }
  1748. //}
  1749. }
  1750. return 0;
  1751. } // wl_rx_dma
  1752. /*============================================================================*/
  1753. #endif // ENABLE_DMA