Bcmnet.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. #include "headers.h"
  2. struct net_device *gblpnetdev;
  3. static INT bcm_open(struct net_device *dev)
  4. {
  5. PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
  6. if (Adapter->fw_download_done == FALSE) {
  7. pr_notice(PFX "%s: link up failed (download in progress)\n",
  8. dev->name);
  9. return -EBUSY;
  10. }
  11. if (netif_msg_ifup(Adapter))
  12. pr_info(PFX "%s: enabling interface\n", dev->name);
  13. if (Adapter->LinkUpStatus) {
  14. if (netif_msg_link(Adapter))
  15. pr_info(PFX "%s: link up\n", dev->name);
  16. netif_carrier_on(Adapter->dev);
  17. netif_start_queue(Adapter->dev);
  18. }
  19. return 0;
  20. }
  21. static INT bcm_close(struct net_device *dev)
  22. {
  23. PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
  24. if (netif_msg_ifdown(Adapter))
  25. pr_info(PFX "%s: disabling interface\n", dev->name);
  26. netif_carrier_off(dev);
  27. netif_stop_queue(dev);
  28. return 0;
  29. }
  30. static u16 bcm_select_queue(struct net_device *dev, struct sk_buff *skb)
  31. {
  32. return ClassifyPacket(netdev_priv(dev), skb);
  33. }
  34. /*******************************************************************
  35. * Function - bcm_transmit()
  36. *
  37. * Description - This is the main transmit function for our virtual
  38. * interface(eth0). It handles the ARP packets. It
  39. * clones this packet and then Queue it to a suitable
  40. * Queue. Then calls the transmit_packet().
  41. *
  42. * Parameter - skb - Pointer to the socket buffer structure
  43. * dev - Pointer to the virtual net device structure
  44. *
  45. *********************************************************************/
  46. static netdev_tx_t bcm_transmit(struct sk_buff *skb, struct net_device *dev)
  47. {
  48. PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
  49. u16 qindex = skb_get_queue_mapping(skb);
  50. if (Adapter->device_removed || !Adapter->LinkUpStatus)
  51. goto drop;
  52. if (Adapter->TransferMode != IP_PACKET_ONLY_MODE)
  53. goto drop;
  54. if (INVALID_QUEUE_INDEX == qindex)
  55. goto drop;
  56. if (Adapter->PackInfo[qindex].uiCurrentPacketsOnHost >=
  57. SF_MAX_ALLOWED_PACKETS_TO_BACKUP)
  58. return NETDEV_TX_BUSY;
  59. /* Now Enqueue the packet */
  60. if (netif_msg_tx_queued(Adapter))
  61. pr_info(PFX "%s: enqueueing packet to queue %d\n",
  62. dev->name, qindex);
  63. spin_lock(&Adapter->PackInfo[qindex].SFQueueLock);
  64. Adapter->PackInfo[qindex].uiCurrentBytesOnHost += skb->len;
  65. Adapter->PackInfo[qindex].uiCurrentPacketsOnHost++;
  66. *((B_UINT32 *) skb->cb + SKB_CB_LATENCY_OFFSET) = jiffies;
  67. ENQUEUEPACKET(Adapter->PackInfo[qindex].FirstTxQueue,
  68. Adapter->PackInfo[qindex].LastTxQueue, skb);
  69. atomic_inc(&Adapter->TotalPacketCount);
  70. spin_unlock(&Adapter->PackInfo[qindex].SFQueueLock);
  71. /* FIXME - this is racy and incorrect, replace with work queue */
  72. if (!atomic_read(&Adapter->TxPktAvail)) {
  73. atomic_set(&Adapter->TxPktAvail, 1);
  74. wake_up(&Adapter->tx_packet_wait_queue);
  75. }
  76. return NETDEV_TX_OK;
  77. drop:
  78. dev_kfree_skb(skb);
  79. return NETDEV_TX_OK;
  80. }
  81. /**
  82. @ingroup init_functions
  83. Register other driver entry points with the kernel
  84. */
  85. static const struct net_device_ops bcmNetDevOps = {
  86. .ndo_open = bcm_open,
  87. .ndo_stop = bcm_close,
  88. .ndo_start_xmit = bcm_transmit,
  89. .ndo_change_mtu = eth_change_mtu,
  90. .ndo_set_mac_address = eth_mac_addr,
  91. .ndo_validate_addr = eth_validate_addr,
  92. .ndo_select_queue = bcm_select_queue,
  93. };
  94. static struct device_type wimax_type = {
  95. .name = "wimax",
  96. };
  97. static int bcm_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  98. {
  99. cmd->supported = 0;
  100. cmd->advertising = 0;
  101. cmd->speed = SPEED_10000;
  102. cmd->duplex = DUPLEX_FULL;
  103. cmd->port = PORT_TP;
  104. cmd->phy_address = 0;
  105. cmd->transceiver = XCVR_INTERNAL;
  106. cmd->autoneg = AUTONEG_DISABLE;
  107. cmd->maxtxpkt = 0;
  108. cmd->maxrxpkt = 0;
  109. return 0;
  110. }
  111. static void bcm_get_drvinfo(struct net_device *dev,
  112. struct ethtool_drvinfo *info)
  113. {
  114. PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
  115. PS_INTERFACE_ADAPTER psIntfAdapter = Adapter->pvInterfaceAdapter;
  116. struct usb_device *udev = interface_to_usbdev(psIntfAdapter->interface);
  117. strcpy(info->driver, DRV_NAME);
  118. strcpy(info->version, DRV_VERSION);
  119. snprintf(info->fw_version, sizeof(info->fw_version), "%u.%u",
  120. Adapter->uiFlashLayoutMajorVersion,
  121. Adapter->uiFlashLayoutMinorVersion);
  122. usb_make_path(udev, info->bus_info, sizeof(info->bus_info));
  123. }
  124. static u32 bcm_get_link(struct net_device *dev)
  125. {
  126. PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
  127. return Adapter->LinkUpStatus;
  128. }
  129. static u32 bcm_get_msglevel(struct net_device *dev)
  130. {
  131. PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
  132. return Adapter->msg_enable;
  133. }
  134. static void bcm_set_msglevel(struct net_device *dev, u32 level)
  135. {
  136. PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
  137. Adapter->msg_enable = level;
  138. }
  139. static const struct ethtool_ops bcm_ethtool_ops = {
  140. .get_settings = bcm_get_settings,
  141. .get_drvinfo = bcm_get_drvinfo,
  142. .get_link = bcm_get_link,
  143. .get_msglevel = bcm_get_msglevel,
  144. .set_msglevel = bcm_set_msglevel,
  145. };
  146. int register_networkdev(PMINI_ADAPTER Adapter)
  147. {
  148. struct net_device *net = Adapter->dev;
  149. PS_INTERFACE_ADAPTER IntfAdapter = Adapter->pvInterfaceAdapter;
  150. struct usb_interface *udev = IntfAdapter->interface;
  151. struct usb_device *xdev = IntfAdapter->udev;
  152. int result;
  153. net->netdev_ops = &bcmNetDevOps;
  154. net->ethtool_ops = &bcm_ethtool_ops;
  155. net->mtu = MTU_SIZE; /* 1400 Bytes */
  156. net->tx_queue_len = TX_QLEN;
  157. net->flags |= IFF_NOARP;
  158. netif_carrier_off(net);
  159. SET_NETDEV_DEVTYPE(net, &wimax_type);
  160. /* Read the MAC Address from EEPROM */
  161. result = ReadMacAddressFromNVM(Adapter);
  162. if (result != STATUS_SUCCESS) {
  163. dev_err(&udev->dev,
  164. PFX "Error in Reading the mac Address: %d", result);
  165. return -EIO;
  166. }
  167. result = register_netdev(net);
  168. if (result)
  169. return result;
  170. gblpnetdev = Adapter->dev;
  171. if (netif_msg_probe(Adapter))
  172. dev_info(&udev->dev, PFX "%s: register usb-%s-%s %pM\n",
  173. net->name, xdev->bus->bus_name, xdev->devpath,
  174. net->dev_addr);
  175. return 0;
  176. }
  177. void unregister_networkdev(PMINI_ADAPTER Adapter)
  178. {
  179. struct net_device *net = Adapter->dev;
  180. PS_INTERFACE_ADAPTER IntfAdapter = Adapter->pvInterfaceAdapter;
  181. struct usb_interface *udev = IntfAdapter->interface;
  182. struct usb_device *xdev = IntfAdapter->udev;
  183. if (netif_msg_probe(Adapter))
  184. dev_info(&udev->dev, PFX "%s: unregister usb-%s%s\n",
  185. net->name, xdev->bus->bus_name, xdev->devpath);
  186. unregister_netdev(Adapter->dev);
  187. }