enic_main.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934
  1. /*
  2. * Copyright 2008 Cisco Systems, Inc. All rights reserved.
  3. * Copyright 2007 Nuova Systems, Inc. All rights reserved.
  4. *
  5. * This program is free software; you may redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; version 2 of the License.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  10. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  12. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  13. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  14. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  16. * SOFTWARE.
  17. *
  18. */
  19. #include <linux/module.h>
  20. #include <linux/kernel.h>
  21. #include <linux/string.h>
  22. #include <linux/errno.h>
  23. #include <linux/types.h>
  24. #include <linux/init.h>
  25. #include <linux/workqueue.h>
  26. #include <linux/pci.h>
  27. #include <linux/netdevice.h>
  28. #include <linux/etherdevice.h>
  29. #include <linux/if_ether.h>
  30. #include <linux/if_vlan.h>
  31. #include <linux/ethtool.h>
  32. #include <linux/in.h>
  33. #include <linux/ip.h>
  34. #include <linux/ipv6.h>
  35. #include <linux/tcp.h>
  36. #include "cq_enet_desc.h"
  37. #include "vnic_dev.h"
  38. #include "vnic_intr.h"
  39. #include "vnic_stats.h"
  40. #include "enic_res.h"
  41. #include "enic.h"
  42. #define ENIC_NOTIFY_TIMER_PERIOD (2 * HZ)
  43. /* Supported devices */
  44. static struct pci_device_id enic_id_table[] = {
  45. { PCI_VDEVICE(CISCO, 0x0043) },
  46. { 0, } /* end of table */
  47. };
  48. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  49. MODULE_AUTHOR("Scott Feldman <scofeldm@cisco.com>");
  50. MODULE_LICENSE("GPL");
  51. MODULE_VERSION(DRV_VERSION);
  52. MODULE_DEVICE_TABLE(pci, enic_id_table);
  53. struct enic_stat {
  54. char name[ETH_GSTRING_LEN];
  55. unsigned int offset;
  56. };
  57. #define ENIC_TX_STAT(stat) \
  58. { .name = #stat, .offset = offsetof(struct vnic_tx_stats, stat) / 8 }
  59. #define ENIC_RX_STAT(stat) \
  60. { .name = #stat, .offset = offsetof(struct vnic_rx_stats, stat) / 8 }
  61. static const struct enic_stat enic_tx_stats[] = {
  62. ENIC_TX_STAT(tx_frames_ok),
  63. ENIC_TX_STAT(tx_unicast_frames_ok),
  64. ENIC_TX_STAT(tx_multicast_frames_ok),
  65. ENIC_TX_STAT(tx_broadcast_frames_ok),
  66. ENIC_TX_STAT(tx_bytes_ok),
  67. ENIC_TX_STAT(tx_unicast_bytes_ok),
  68. ENIC_TX_STAT(tx_multicast_bytes_ok),
  69. ENIC_TX_STAT(tx_broadcast_bytes_ok),
  70. ENIC_TX_STAT(tx_drops),
  71. ENIC_TX_STAT(tx_errors),
  72. ENIC_TX_STAT(tx_tso),
  73. };
  74. static const struct enic_stat enic_rx_stats[] = {
  75. ENIC_RX_STAT(rx_frames_ok),
  76. ENIC_RX_STAT(rx_frames_total),
  77. ENIC_RX_STAT(rx_unicast_frames_ok),
  78. ENIC_RX_STAT(rx_multicast_frames_ok),
  79. ENIC_RX_STAT(rx_broadcast_frames_ok),
  80. ENIC_RX_STAT(rx_bytes_ok),
  81. ENIC_RX_STAT(rx_unicast_bytes_ok),
  82. ENIC_RX_STAT(rx_multicast_bytes_ok),
  83. ENIC_RX_STAT(rx_broadcast_bytes_ok),
  84. ENIC_RX_STAT(rx_drop),
  85. ENIC_RX_STAT(rx_no_bufs),
  86. ENIC_RX_STAT(rx_errors),
  87. ENIC_RX_STAT(rx_rss),
  88. ENIC_RX_STAT(rx_crc_errors),
  89. ENIC_RX_STAT(rx_frames_64),
  90. ENIC_RX_STAT(rx_frames_127),
  91. ENIC_RX_STAT(rx_frames_255),
  92. ENIC_RX_STAT(rx_frames_511),
  93. ENIC_RX_STAT(rx_frames_1023),
  94. ENIC_RX_STAT(rx_frames_1518),
  95. ENIC_RX_STAT(rx_frames_to_max),
  96. };
  97. static const unsigned int enic_n_tx_stats = ARRAY_SIZE(enic_tx_stats);
  98. static const unsigned int enic_n_rx_stats = ARRAY_SIZE(enic_rx_stats);
  99. static int enic_get_settings(struct net_device *netdev,
  100. struct ethtool_cmd *ecmd)
  101. {
  102. struct enic *enic = netdev_priv(netdev);
  103. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
  104. ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
  105. ecmd->port = PORT_FIBRE;
  106. ecmd->transceiver = XCVR_EXTERNAL;
  107. if (netif_carrier_ok(netdev)) {
  108. ecmd->speed = vnic_dev_port_speed(enic->vdev);
  109. ecmd->duplex = DUPLEX_FULL;
  110. } else {
  111. ecmd->speed = -1;
  112. ecmd->duplex = -1;
  113. }
  114. ecmd->autoneg = AUTONEG_DISABLE;
  115. return 0;
  116. }
  117. static void enic_get_drvinfo(struct net_device *netdev,
  118. struct ethtool_drvinfo *drvinfo)
  119. {
  120. struct enic *enic = netdev_priv(netdev);
  121. struct vnic_devcmd_fw_info *fw_info;
  122. spin_lock(&enic->devcmd_lock);
  123. vnic_dev_fw_info(enic->vdev, &fw_info);
  124. spin_unlock(&enic->devcmd_lock);
  125. strncpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
  126. strncpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
  127. strncpy(drvinfo->fw_version, fw_info->fw_version,
  128. sizeof(drvinfo->fw_version));
  129. strncpy(drvinfo->bus_info, pci_name(enic->pdev),
  130. sizeof(drvinfo->bus_info));
  131. }
  132. static void enic_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
  133. {
  134. unsigned int i;
  135. switch (stringset) {
  136. case ETH_SS_STATS:
  137. for (i = 0; i < enic_n_tx_stats; i++) {
  138. memcpy(data, enic_tx_stats[i].name, ETH_GSTRING_LEN);
  139. data += ETH_GSTRING_LEN;
  140. }
  141. for (i = 0; i < enic_n_rx_stats; i++) {
  142. memcpy(data, enic_rx_stats[i].name, ETH_GSTRING_LEN);
  143. data += ETH_GSTRING_LEN;
  144. }
  145. break;
  146. }
  147. }
  148. static int enic_get_sset_count(struct net_device *netdev, int sset)
  149. {
  150. switch (sset) {
  151. case ETH_SS_STATS:
  152. return enic_n_tx_stats + enic_n_rx_stats;
  153. default:
  154. return -EOPNOTSUPP;
  155. }
  156. }
  157. static void enic_get_ethtool_stats(struct net_device *netdev,
  158. struct ethtool_stats *stats, u64 *data)
  159. {
  160. struct enic *enic = netdev_priv(netdev);
  161. struct vnic_stats *vstats;
  162. unsigned int i;
  163. spin_lock(&enic->devcmd_lock);
  164. vnic_dev_stats_dump(enic->vdev, &vstats);
  165. spin_unlock(&enic->devcmd_lock);
  166. for (i = 0; i < enic_n_tx_stats; i++)
  167. *(data++) = ((u64 *)&vstats->tx)[enic_tx_stats[i].offset];
  168. for (i = 0; i < enic_n_rx_stats; i++)
  169. *(data++) = ((u64 *)&vstats->rx)[enic_rx_stats[i].offset];
  170. }
  171. static u32 enic_get_rx_csum(struct net_device *netdev)
  172. {
  173. struct enic *enic = netdev_priv(netdev);
  174. return enic->csum_rx_enabled;
  175. }
  176. static int enic_set_rx_csum(struct net_device *netdev, u32 data)
  177. {
  178. struct enic *enic = netdev_priv(netdev);
  179. if (data && !ENIC_SETTING(enic, RXCSUM))
  180. return -EINVAL;
  181. enic->csum_rx_enabled = !!data;
  182. return 0;
  183. }
  184. static int enic_set_tx_csum(struct net_device *netdev, u32 data)
  185. {
  186. struct enic *enic = netdev_priv(netdev);
  187. if (data && !ENIC_SETTING(enic, TXCSUM))
  188. return -EINVAL;
  189. if (data)
  190. netdev->features |= NETIF_F_HW_CSUM;
  191. else
  192. netdev->features &= ~NETIF_F_HW_CSUM;
  193. return 0;
  194. }
  195. static int enic_set_tso(struct net_device *netdev, u32 data)
  196. {
  197. struct enic *enic = netdev_priv(netdev);
  198. if (data && !ENIC_SETTING(enic, TSO))
  199. return -EINVAL;
  200. if (data)
  201. netdev->features |=
  202. NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN;
  203. else
  204. netdev->features &=
  205. ~(NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN);
  206. return 0;
  207. }
  208. static u32 enic_get_msglevel(struct net_device *netdev)
  209. {
  210. struct enic *enic = netdev_priv(netdev);
  211. return enic->msg_enable;
  212. }
  213. static void enic_set_msglevel(struct net_device *netdev, u32 value)
  214. {
  215. struct enic *enic = netdev_priv(netdev);
  216. enic->msg_enable = value;
  217. }
  218. static struct ethtool_ops enic_ethtool_ops = {
  219. .get_settings = enic_get_settings,
  220. .get_drvinfo = enic_get_drvinfo,
  221. .get_msglevel = enic_get_msglevel,
  222. .set_msglevel = enic_set_msglevel,
  223. .get_link = ethtool_op_get_link,
  224. .get_strings = enic_get_strings,
  225. .get_sset_count = enic_get_sset_count,
  226. .get_ethtool_stats = enic_get_ethtool_stats,
  227. .get_rx_csum = enic_get_rx_csum,
  228. .set_rx_csum = enic_set_rx_csum,
  229. .get_tx_csum = ethtool_op_get_tx_csum,
  230. .set_tx_csum = enic_set_tx_csum,
  231. .get_sg = ethtool_op_get_sg,
  232. .set_sg = ethtool_op_set_sg,
  233. .get_tso = ethtool_op_get_tso,
  234. .set_tso = enic_set_tso,
  235. };
  236. static void enic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf)
  237. {
  238. struct enic *enic = vnic_dev_priv(wq->vdev);
  239. if (buf->sop)
  240. pci_unmap_single(enic->pdev, buf->dma_addr,
  241. buf->len, PCI_DMA_TODEVICE);
  242. else
  243. pci_unmap_page(enic->pdev, buf->dma_addr,
  244. buf->len, PCI_DMA_TODEVICE);
  245. if (buf->os_buf)
  246. dev_kfree_skb_any(buf->os_buf);
  247. }
  248. static void enic_wq_free_buf(struct vnic_wq *wq,
  249. struct cq_desc *cq_desc, struct vnic_wq_buf *buf, void *opaque)
  250. {
  251. enic_free_wq_buf(wq, buf);
  252. }
  253. static int enic_wq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
  254. u8 type, u16 q_number, u16 completed_index, void *opaque)
  255. {
  256. struct enic *enic = vnic_dev_priv(vdev);
  257. spin_lock(&enic->wq_lock[q_number]);
  258. vnic_wq_service(&enic->wq[q_number], cq_desc,
  259. completed_index, enic_wq_free_buf,
  260. opaque);
  261. if (netif_queue_stopped(enic->netdev) &&
  262. vnic_wq_desc_avail(&enic->wq[q_number]) >= MAX_SKB_FRAGS + 1)
  263. netif_wake_queue(enic->netdev);
  264. spin_unlock(&enic->wq_lock[q_number]);
  265. return 0;
  266. }
  267. static void enic_log_q_error(struct enic *enic)
  268. {
  269. unsigned int i;
  270. u32 error_status;
  271. for (i = 0; i < enic->wq_count; i++) {
  272. error_status = vnic_wq_error_status(&enic->wq[i]);
  273. if (error_status)
  274. printk(KERN_ERR PFX "%s: WQ[%d] error_status %d\n",
  275. enic->netdev->name, i, error_status);
  276. }
  277. for (i = 0; i < enic->rq_count; i++) {
  278. error_status = vnic_rq_error_status(&enic->rq[i]);
  279. if (error_status)
  280. printk(KERN_ERR PFX "%s: RQ[%d] error_status %d\n",
  281. enic->netdev->name, i, error_status);
  282. }
  283. }
  284. static void enic_link_check(struct enic *enic)
  285. {
  286. int link_status = vnic_dev_link_status(enic->vdev);
  287. int carrier_ok = netif_carrier_ok(enic->netdev);
  288. if (link_status && !carrier_ok) {
  289. printk(KERN_INFO PFX "%s: Link UP\n", enic->netdev->name);
  290. netif_carrier_on(enic->netdev);
  291. } else if (!link_status && carrier_ok) {
  292. printk(KERN_INFO PFX "%s: Link DOWN\n", enic->netdev->name);
  293. netif_carrier_off(enic->netdev);
  294. }
  295. }
  296. static void enic_mtu_check(struct enic *enic)
  297. {
  298. u32 mtu = vnic_dev_mtu(enic->vdev);
  299. if (mtu != enic->port_mtu) {
  300. if (mtu < enic->netdev->mtu)
  301. printk(KERN_WARNING PFX
  302. "%s: interface MTU (%d) set higher "
  303. "than switch port MTU (%d)\n",
  304. enic->netdev->name, enic->netdev->mtu, mtu);
  305. enic->port_mtu = mtu;
  306. }
  307. }
  308. static void enic_msglvl_check(struct enic *enic)
  309. {
  310. u32 msg_enable = vnic_dev_msg_lvl(enic->vdev);
  311. if (msg_enable != enic->msg_enable) {
  312. printk(KERN_INFO PFX "%s: msg lvl changed from 0x%x to 0x%x\n",
  313. enic->netdev->name, enic->msg_enable, msg_enable);
  314. enic->msg_enable = msg_enable;
  315. }
  316. }
  317. static void enic_notify_check(struct enic *enic)
  318. {
  319. enic_msglvl_check(enic);
  320. enic_mtu_check(enic);
  321. enic_link_check(enic);
  322. }
  323. #define ENIC_TEST_INTR(pba, i) (pba & (1 << i))
  324. static irqreturn_t enic_isr_legacy(int irq, void *data)
  325. {
  326. struct net_device *netdev = data;
  327. struct enic *enic = netdev_priv(netdev);
  328. u32 pba;
  329. vnic_intr_mask(&enic->intr[ENIC_INTX_WQ_RQ]);
  330. pba = vnic_intr_legacy_pba(enic->legacy_pba);
  331. if (!pba) {
  332. vnic_intr_unmask(&enic->intr[ENIC_INTX_WQ_RQ]);
  333. return IRQ_NONE; /* not our interrupt */
  334. }
  335. if (ENIC_TEST_INTR(pba, ENIC_INTX_NOTIFY))
  336. enic_notify_check(enic);
  337. if (ENIC_TEST_INTR(pba, ENIC_INTX_ERR)) {
  338. enic_log_q_error(enic);
  339. /* schedule recovery from WQ/RQ error */
  340. schedule_work(&enic->reset);
  341. return IRQ_HANDLED;
  342. }
  343. if (ENIC_TEST_INTR(pba, ENIC_INTX_WQ_RQ)) {
  344. if (netif_rx_schedule_prep(netdev, &enic->napi))
  345. __netif_rx_schedule(netdev, &enic->napi);
  346. } else {
  347. vnic_intr_unmask(&enic->intr[ENIC_INTX_WQ_RQ]);
  348. }
  349. return IRQ_HANDLED;
  350. }
  351. static irqreturn_t enic_isr_msi(int irq, void *data)
  352. {
  353. struct enic *enic = data;
  354. /* With MSI, there is no sharing of interrupts, so this is
  355. * our interrupt and there is no need to ack it. The device
  356. * is not providing per-vector masking, so the OS will not
  357. * write to PCI config space to mask/unmask the interrupt.
  358. * We're using mask_on_assertion for MSI, so the device
  359. * automatically masks the interrupt when the interrupt is
  360. * generated. Later, when exiting polling, the interrupt
  361. * will be unmasked (see enic_poll).
  362. *
  363. * Also, the device uses the same PCIe Traffic Class (TC)
  364. * for Memory Write data and MSI, so there are no ordering
  365. * issues; the MSI will always arrive at the Root Complex
  366. * _after_ corresponding Memory Writes (i.e. descriptor
  367. * writes).
  368. */
  369. netif_rx_schedule(enic->netdev, &enic->napi);
  370. return IRQ_HANDLED;
  371. }
  372. static irqreturn_t enic_isr_msix_rq(int irq, void *data)
  373. {
  374. struct enic *enic = data;
  375. /* schedule NAPI polling for RQ cleanup */
  376. netif_rx_schedule(enic->netdev, &enic->napi);
  377. return IRQ_HANDLED;
  378. }
  379. static irqreturn_t enic_isr_msix_wq(int irq, void *data)
  380. {
  381. struct enic *enic = data;
  382. unsigned int wq_work_to_do = -1; /* no limit */
  383. unsigned int wq_work_done;
  384. wq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_WQ],
  385. wq_work_to_do, enic_wq_service, NULL);
  386. vnic_intr_return_credits(&enic->intr[ENIC_MSIX_WQ],
  387. wq_work_done,
  388. 1 /* unmask intr */,
  389. 1 /* reset intr timer */);
  390. return IRQ_HANDLED;
  391. }
  392. static irqreturn_t enic_isr_msix_err(int irq, void *data)
  393. {
  394. struct enic *enic = data;
  395. enic_log_q_error(enic);
  396. /* schedule recovery from WQ/RQ error */
  397. schedule_work(&enic->reset);
  398. return IRQ_HANDLED;
  399. }
  400. static irqreturn_t enic_isr_msix_notify(int irq, void *data)
  401. {
  402. struct enic *enic = data;
  403. enic_notify_check(enic);
  404. vnic_intr_unmask(&enic->intr[ENIC_MSIX_NOTIFY]);
  405. return IRQ_HANDLED;
  406. }
  407. static inline void enic_queue_wq_skb_cont(struct enic *enic,
  408. struct vnic_wq *wq, struct sk_buff *skb,
  409. unsigned int len_left)
  410. {
  411. skb_frag_t *frag;
  412. /* Queue additional data fragments */
  413. for (frag = skb_shinfo(skb)->frags; len_left; frag++) {
  414. len_left -= frag->size;
  415. enic_queue_wq_desc_cont(wq, skb,
  416. pci_map_page(enic->pdev, frag->page,
  417. frag->page_offset, frag->size,
  418. PCI_DMA_TODEVICE),
  419. frag->size,
  420. (len_left == 0)); /* EOP? */
  421. }
  422. }
  423. static inline void enic_queue_wq_skb_vlan(struct enic *enic,
  424. struct vnic_wq *wq, struct sk_buff *skb,
  425. int vlan_tag_insert, unsigned int vlan_tag)
  426. {
  427. unsigned int head_len = skb_headlen(skb);
  428. unsigned int len_left = skb->len - head_len;
  429. int eop = (len_left == 0);
  430. /* Queue the main skb fragment */
  431. enic_queue_wq_desc(wq, skb,
  432. pci_map_single(enic->pdev, skb->data,
  433. head_len, PCI_DMA_TODEVICE),
  434. head_len,
  435. vlan_tag_insert, vlan_tag,
  436. eop);
  437. if (!eop)
  438. enic_queue_wq_skb_cont(enic, wq, skb, len_left);
  439. }
  440. static inline void enic_queue_wq_skb_csum_l4(struct enic *enic,
  441. struct vnic_wq *wq, struct sk_buff *skb,
  442. int vlan_tag_insert, unsigned int vlan_tag)
  443. {
  444. unsigned int head_len = skb_headlen(skb);
  445. unsigned int len_left = skb->len - head_len;
  446. unsigned int hdr_len = skb_transport_offset(skb);
  447. unsigned int csum_offset = hdr_len + skb->csum_offset;
  448. int eop = (len_left == 0);
  449. /* Queue the main skb fragment */
  450. enic_queue_wq_desc_csum_l4(wq, skb,
  451. pci_map_single(enic->pdev, skb->data,
  452. head_len, PCI_DMA_TODEVICE),
  453. head_len,
  454. csum_offset,
  455. hdr_len,
  456. vlan_tag_insert, vlan_tag,
  457. eop);
  458. if (!eop)
  459. enic_queue_wq_skb_cont(enic, wq, skb, len_left);
  460. }
  461. static inline void enic_queue_wq_skb_tso(struct enic *enic,
  462. struct vnic_wq *wq, struct sk_buff *skb, unsigned int mss,
  463. int vlan_tag_insert, unsigned int vlan_tag)
  464. {
  465. unsigned int head_len = skb_headlen(skb);
  466. unsigned int len_left = skb->len - head_len;
  467. unsigned int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  468. int eop = (len_left == 0);
  469. /* Preload TCP csum field with IP pseudo hdr calculated
  470. * with IP length set to zero. HW will later add in length
  471. * to each TCP segment resulting from the TSO.
  472. */
  473. if (skb->protocol == __constant_htons(ETH_P_IP)) {
  474. ip_hdr(skb)->check = 0;
  475. tcp_hdr(skb)->check = ~csum_tcpudp_magic(ip_hdr(skb)->saddr,
  476. ip_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
  477. } else if (skb->protocol == __constant_htons(ETH_P_IPV6)) {
  478. tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  479. &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
  480. }
  481. /* Queue the main skb fragment */
  482. enic_queue_wq_desc_tso(wq, skb,
  483. pci_map_single(enic->pdev, skb->data,
  484. head_len, PCI_DMA_TODEVICE),
  485. head_len,
  486. mss, hdr_len,
  487. vlan_tag_insert, vlan_tag,
  488. eop);
  489. if (!eop)
  490. enic_queue_wq_skb_cont(enic, wq, skb, len_left);
  491. }
  492. static inline void enic_queue_wq_skb(struct enic *enic,
  493. struct vnic_wq *wq, struct sk_buff *skb)
  494. {
  495. unsigned int mss = skb_shinfo(skb)->gso_size;
  496. unsigned int vlan_tag = 0;
  497. int vlan_tag_insert = 0;
  498. if (enic->vlan_group && vlan_tx_tag_present(skb)) {
  499. /* VLAN tag from trunking driver */
  500. vlan_tag_insert = 1;
  501. vlan_tag = vlan_tx_tag_get(skb);
  502. }
  503. if (mss)
  504. enic_queue_wq_skb_tso(enic, wq, skb, mss,
  505. vlan_tag_insert, vlan_tag);
  506. else if (skb->ip_summed == CHECKSUM_PARTIAL)
  507. enic_queue_wq_skb_csum_l4(enic, wq, skb,
  508. vlan_tag_insert, vlan_tag);
  509. else
  510. enic_queue_wq_skb_vlan(enic, wq, skb,
  511. vlan_tag_insert, vlan_tag);
  512. }
  513. /* netif_tx_lock held, process context with BHs disabled */
  514. static int enic_hard_start_xmit(struct sk_buff *skb, struct net_device *netdev)
  515. {
  516. struct enic *enic = netdev_priv(netdev);
  517. struct vnic_wq *wq = &enic->wq[0];
  518. unsigned long flags;
  519. if (skb->len <= 0) {
  520. dev_kfree_skb(skb);
  521. return NETDEV_TX_OK;
  522. }
  523. /* Non-TSO sends must fit within ENIC_NON_TSO_MAX_DESC descs,
  524. * which is very likely. In the off chance it's going to take
  525. * more than * ENIC_NON_TSO_MAX_DESC, linearize the skb.
  526. */
  527. if (skb_shinfo(skb)->gso_size == 0 &&
  528. skb_shinfo(skb)->nr_frags + 1 > ENIC_NON_TSO_MAX_DESC &&
  529. skb_linearize(skb)) {
  530. dev_kfree_skb(skb);
  531. return NETDEV_TX_OK;
  532. }
  533. spin_lock_irqsave(&enic->wq_lock[0], flags);
  534. if (vnic_wq_desc_avail(wq) < skb_shinfo(skb)->nr_frags + 1) {
  535. netif_stop_queue(netdev);
  536. /* This is a hard error, log it */
  537. printk(KERN_ERR PFX "%s: BUG! Tx ring full when "
  538. "queue awake!\n", netdev->name);
  539. spin_unlock_irqrestore(&enic->wq_lock[0], flags);
  540. return NETDEV_TX_BUSY;
  541. }
  542. enic_queue_wq_skb(enic, wq, skb);
  543. if (vnic_wq_desc_avail(wq) < MAX_SKB_FRAGS + 1)
  544. netif_stop_queue(netdev);
  545. netdev->trans_start = jiffies;
  546. spin_unlock_irqrestore(&enic->wq_lock[0], flags);
  547. return NETDEV_TX_OK;
  548. }
  549. /* dev_base_lock rwlock held, nominally process context */
  550. static struct net_device_stats *enic_get_stats(struct net_device *netdev)
  551. {
  552. struct enic *enic = netdev_priv(netdev);
  553. struct net_device_stats *net_stats = &netdev->stats;
  554. struct vnic_stats *stats;
  555. spin_lock(&enic->devcmd_lock);
  556. vnic_dev_stats_dump(enic->vdev, &stats);
  557. spin_unlock(&enic->devcmd_lock);
  558. net_stats->tx_packets = stats->tx.tx_frames_ok;
  559. net_stats->tx_bytes = stats->tx.tx_bytes_ok;
  560. net_stats->tx_errors = stats->tx.tx_errors;
  561. net_stats->tx_dropped = stats->tx.tx_drops;
  562. net_stats->rx_packets = stats->rx.rx_frames_ok;
  563. net_stats->rx_bytes = stats->rx.rx_bytes_ok;
  564. net_stats->rx_errors = stats->rx.rx_errors;
  565. net_stats->multicast = stats->rx.rx_multicast_frames_ok;
  566. net_stats->rx_crc_errors = stats->rx.rx_crc_errors;
  567. net_stats->rx_dropped = stats->rx.rx_no_bufs;
  568. return net_stats;
  569. }
  570. static void enic_reset_mcaddrs(struct enic *enic)
  571. {
  572. enic->mc_count = 0;
  573. }
  574. static int enic_set_mac_addr(struct net_device *netdev, char *addr)
  575. {
  576. if (!is_valid_ether_addr(addr))
  577. return -EADDRNOTAVAIL;
  578. memcpy(netdev->dev_addr, addr, netdev->addr_len);
  579. return 0;
  580. }
  581. /* netif_tx_lock held, BHs disabled */
  582. static void enic_set_multicast_list(struct net_device *netdev)
  583. {
  584. struct enic *enic = netdev_priv(netdev);
  585. struct dev_mc_list *list = netdev->mc_list;
  586. int directed = 1;
  587. int multicast = (netdev->flags & IFF_MULTICAST) ? 1 : 0;
  588. int broadcast = (netdev->flags & IFF_BROADCAST) ? 1 : 0;
  589. int promisc = (netdev->flags & IFF_PROMISC) ? 1 : 0;
  590. int allmulti = (netdev->flags & IFF_ALLMULTI) ||
  591. (netdev->mc_count > ENIC_MULTICAST_PERFECT_FILTERS);
  592. u8 mc_addr[ENIC_MULTICAST_PERFECT_FILTERS][ETH_ALEN];
  593. unsigned int mc_count = netdev->mc_count;
  594. unsigned int i, j;
  595. if (mc_count > ENIC_MULTICAST_PERFECT_FILTERS)
  596. mc_count = ENIC_MULTICAST_PERFECT_FILTERS;
  597. spin_lock(&enic->devcmd_lock);
  598. vnic_dev_packet_filter(enic->vdev, directed,
  599. multicast, broadcast, promisc, allmulti);
  600. /* Is there an easier way? Trying to minimize to
  601. * calls to add/del multicast addrs. We keep the
  602. * addrs from the last call in enic->mc_addr and
  603. * look for changes to add/del.
  604. */
  605. for (i = 0; list && i < mc_count; i++) {
  606. memcpy(mc_addr[i], list->dmi_addr, ETH_ALEN);
  607. list = list->next;
  608. }
  609. for (i = 0; i < enic->mc_count; i++) {
  610. for (j = 0; j < mc_count; j++)
  611. if (compare_ether_addr(enic->mc_addr[i],
  612. mc_addr[j]) == 0)
  613. break;
  614. if (j == mc_count)
  615. enic_del_multicast_addr(enic, enic->mc_addr[i]);
  616. }
  617. for (i = 0; i < mc_count; i++) {
  618. for (j = 0; j < enic->mc_count; j++)
  619. if (compare_ether_addr(mc_addr[i],
  620. enic->mc_addr[j]) == 0)
  621. break;
  622. if (j == enic->mc_count)
  623. enic_add_multicast_addr(enic, mc_addr[i]);
  624. }
  625. /* Save the list to compare against next time
  626. */
  627. for (i = 0; i < mc_count; i++)
  628. memcpy(enic->mc_addr[i], mc_addr[i], ETH_ALEN);
  629. enic->mc_count = mc_count;
  630. spin_unlock(&enic->devcmd_lock);
  631. }
  632. /* rtnl lock is held */
  633. static void enic_vlan_rx_register(struct net_device *netdev,
  634. struct vlan_group *vlan_group)
  635. {
  636. struct enic *enic = netdev_priv(netdev);
  637. enic->vlan_group = vlan_group;
  638. }
  639. /* rtnl lock is held */
  640. static void enic_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
  641. {
  642. struct enic *enic = netdev_priv(netdev);
  643. spin_lock(&enic->devcmd_lock);
  644. enic_add_vlan(enic, vid);
  645. spin_unlock(&enic->devcmd_lock);
  646. }
  647. /* rtnl lock is held */
  648. static void enic_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
  649. {
  650. struct enic *enic = netdev_priv(netdev);
  651. spin_lock(&enic->devcmd_lock);
  652. enic_del_vlan(enic, vid);
  653. spin_unlock(&enic->devcmd_lock);
  654. }
  655. /* netif_tx_lock held, BHs disabled */
  656. static void enic_tx_timeout(struct net_device *netdev)
  657. {
  658. struct enic *enic = netdev_priv(netdev);
  659. schedule_work(&enic->reset);
  660. }
  661. static void enic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf)
  662. {
  663. struct enic *enic = vnic_dev_priv(rq->vdev);
  664. if (!buf->os_buf)
  665. return;
  666. pci_unmap_single(enic->pdev, buf->dma_addr,
  667. buf->len, PCI_DMA_FROMDEVICE);
  668. dev_kfree_skb_any(buf->os_buf);
  669. }
  670. static inline struct sk_buff *enic_rq_alloc_skb(unsigned int size)
  671. {
  672. struct sk_buff *skb;
  673. skb = dev_alloc_skb(size + NET_IP_ALIGN);
  674. if (skb)
  675. skb_reserve(skb, NET_IP_ALIGN);
  676. return skb;
  677. }
  678. static int enic_rq_alloc_buf(struct vnic_rq *rq)
  679. {
  680. struct enic *enic = vnic_dev_priv(rq->vdev);
  681. struct sk_buff *skb;
  682. unsigned int len = enic->netdev->mtu + ETH_HLEN;
  683. unsigned int os_buf_index = 0;
  684. dma_addr_t dma_addr;
  685. skb = enic_rq_alloc_skb(len);
  686. if (!skb)
  687. return -ENOMEM;
  688. dma_addr = pci_map_single(enic->pdev, skb->data,
  689. len, PCI_DMA_FROMDEVICE);
  690. enic_queue_rq_desc(rq, skb, os_buf_index,
  691. dma_addr, len);
  692. return 0;
  693. }
  694. static int enic_get_skb_header(struct sk_buff *skb, void **iphdr,
  695. void **tcph, u64 *hdr_flags, void *priv)
  696. {
  697. struct cq_enet_rq_desc *cq_desc = priv;
  698. unsigned int ip_len;
  699. struct iphdr *iph;
  700. u8 type, color, eop, sop, ingress_port, vlan_stripped;
  701. u8 fcoe, fcoe_sof, fcoe_fc_crc_ok, fcoe_enc_error, fcoe_eof;
  702. u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok;
  703. u8 ipv6, ipv4, ipv4_fragment, fcs_ok, rss_type, csum_not_calc;
  704. u8 packet_error;
  705. u16 q_number, completed_index, bytes_written, vlan, checksum;
  706. u32 rss_hash;
  707. cq_enet_rq_desc_dec(cq_desc,
  708. &type, &color, &q_number, &completed_index,
  709. &ingress_port, &fcoe, &eop, &sop, &rss_type,
  710. &csum_not_calc, &rss_hash, &bytes_written,
  711. &packet_error, &vlan_stripped, &vlan, &checksum,
  712. &fcoe_sof, &fcoe_fc_crc_ok, &fcoe_enc_error,
  713. &fcoe_eof, &tcp_udp_csum_ok, &udp, &tcp,
  714. &ipv4_csum_ok, &ipv6, &ipv4, &ipv4_fragment,
  715. &fcs_ok);
  716. if (!(ipv4 && tcp && !ipv4_fragment))
  717. return -1;
  718. skb_reset_network_header(skb);
  719. iph = ip_hdr(skb);
  720. ip_len = ip_hdrlen(skb);
  721. skb_set_transport_header(skb, ip_len);
  722. /* check if ip header and tcp header are complete */
  723. if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
  724. return -1;
  725. *hdr_flags = LRO_IPV4 | LRO_TCP;
  726. *tcph = tcp_hdr(skb);
  727. *iphdr = iph;
  728. return 0;
  729. }
  730. static void enic_rq_indicate_buf(struct vnic_rq *rq,
  731. struct cq_desc *cq_desc, struct vnic_rq_buf *buf,
  732. int skipped, void *opaque)
  733. {
  734. struct enic *enic = vnic_dev_priv(rq->vdev);
  735. struct sk_buff *skb;
  736. u8 type, color, eop, sop, ingress_port, vlan_stripped;
  737. u8 fcoe, fcoe_sof, fcoe_fc_crc_ok, fcoe_enc_error, fcoe_eof;
  738. u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok;
  739. u8 ipv6, ipv4, ipv4_fragment, fcs_ok, rss_type, csum_not_calc;
  740. u8 packet_error;
  741. u16 q_number, completed_index, bytes_written, vlan, checksum;
  742. u32 rss_hash;
  743. if (skipped)
  744. return;
  745. skb = buf->os_buf;
  746. prefetch(skb->data - NET_IP_ALIGN);
  747. pci_unmap_single(enic->pdev, buf->dma_addr,
  748. buf->len, PCI_DMA_FROMDEVICE);
  749. cq_enet_rq_desc_dec((struct cq_enet_rq_desc *)cq_desc,
  750. &type, &color, &q_number, &completed_index,
  751. &ingress_port, &fcoe, &eop, &sop, &rss_type,
  752. &csum_not_calc, &rss_hash, &bytes_written,
  753. &packet_error, &vlan_stripped, &vlan, &checksum,
  754. &fcoe_sof, &fcoe_fc_crc_ok, &fcoe_enc_error,
  755. &fcoe_eof, &tcp_udp_csum_ok, &udp, &tcp,
  756. &ipv4_csum_ok, &ipv6, &ipv4, &ipv4_fragment,
  757. &fcs_ok);
  758. if (packet_error) {
  759. if (bytes_written > 0 && !fcs_ok) {
  760. if (net_ratelimit())
  761. printk(KERN_ERR PFX
  762. "%s: packet error: bad FCS\n",
  763. enic->netdev->name);
  764. }
  765. dev_kfree_skb_any(skb);
  766. return;
  767. }
  768. if (eop && bytes_written > 0) {
  769. /* Good receive
  770. */
  771. skb_put(skb, bytes_written);
  772. skb->protocol = eth_type_trans(skb, enic->netdev);
  773. if (enic->csum_rx_enabled && !csum_not_calc) {
  774. skb->csum = htons(checksum);
  775. skb->ip_summed = CHECKSUM_COMPLETE;
  776. }
  777. skb->dev = enic->netdev;
  778. enic->netdev->last_rx = jiffies;
  779. if (enic->vlan_group && vlan_stripped) {
  780. if (ENIC_SETTING(enic, LRO) && ipv4)
  781. lro_vlan_hwaccel_receive_skb(&enic->lro_mgr,
  782. skb, enic->vlan_group,
  783. vlan, cq_desc);
  784. else
  785. vlan_hwaccel_receive_skb(skb,
  786. enic->vlan_group, vlan);
  787. } else {
  788. if (ENIC_SETTING(enic, LRO) && ipv4)
  789. lro_receive_skb(&enic->lro_mgr, skb, cq_desc);
  790. else
  791. netif_receive_skb(skb);
  792. }
  793. } else {
  794. /* Buffer overflow
  795. */
  796. dev_kfree_skb_any(skb);
  797. }
  798. }
  799. static int enic_rq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
  800. u8 type, u16 q_number, u16 completed_index, void *opaque)
  801. {
  802. struct enic *enic = vnic_dev_priv(vdev);
  803. vnic_rq_service(&enic->rq[q_number], cq_desc,
  804. completed_index, VNIC_RQ_RETURN_DESC,
  805. enic_rq_indicate_buf, opaque);
  806. return 0;
  807. }
  808. static void enic_rq_drop_buf(struct vnic_rq *rq,
  809. struct cq_desc *cq_desc, struct vnic_rq_buf *buf,
  810. int skipped, void *opaque)
  811. {
  812. struct enic *enic = vnic_dev_priv(rq->vdev);
  813. struct sk_buff *skb = buf->os_buf;
  814. if (skipped)
  815. return;
  816. pci_unmap_single(enic->pdev, buf->dma_addr,
  817. buf->len, PCI_DMA_FROMDEVICE);
  818. dev_kfree_skb_any(skb);
  819. }
  820. static int enic_rq_service_drop(struct vnic_dev *vdev, struct cq_desc *cq_desc,
  821. u8 type, u16 q_number, u16 completed_index, void *opaque)
  822. {
  823. struct enic *enic = vnic_dev_priv(vdev);
  824. vnic_rq_service(&enic->rq[q_number], cq_desc,
  825. completed_index, VNIC_RQ_RETURN_DESC,
  826. enic_rq_drop_buf, opaque);
  827. return 0;
  828. }
  829. static int enic_poll(struct napi_struct *napi, int budget)
  830. {
  831. struct enic *enic = container_of(napi, struct enic, napi);
  832. struct net_device *netdev = enic->netdev;
  833. unsigned int rq_work_to_do = budget;
  834. unsigned int wq_work_to_do = -1; /* no limit */
  835. unsigned int work_done, rq_work_done, wq_work_done;
  836. /* Service RQ (first) and WQ
  837. */
  838. rq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_RQ],
  839. rq_work_to_do, enic_rq_service, NULL);
  840. wq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_WQ],
  841. wq_work_to_do, enic_wq_service, NULL);
  842. /* Accumulate intr event credits for this polling
  843. * cycle. An intr event is the completion of a
  844. * a WQ or RQ packet.
  845. */
  846. work_done = rq_work_done + wq_work_done;
  847. if (work_done > 0)
  848. vnic_intr_return_credits(&enic->intr[ENIC_INTX_WQ_RQ],
  849. work_done,
  850. 0 /* don't unmask intr */,
  851. 0 /* don't reset intr timer */);
  852. if (rq_work_done > 0) {
  853. /* Replenish RQ
  854. */
  855. vnic_rq_fill(&enic->rq[0], enic_rq_alloc_buf);
  856. } else {
  857. /* If no work done, flush all LROs and exit polling
  858. */
  859. if (ENIC_SETTING(enic, LRO))
  860. lro_flush_all(&enic->lro_mgr);
  861. netif_rx_complete(netdev, napi);
  862. vnic_intr_unmask(&enic->intr[ENIC_MSIX_RQ]);
  863. }
  864. return rq_work_done;
  865. }
  866. static int enic_poll_msix(struct napi_struct *napi, int budget)
  867. {
  868. struct enic *enic = container_of(napi, struct enic, napi);
  869. struct net_device *netdev = enic->netdev;
  870. unsigned int work_to_do = budget;
  871. unsigned int work_done;
  872. /* Service RQ
  873. */
  874. work_done = vnic_cq_service(&enic->cq[ENIC_CQ_RQ],
  875. work_to_do, enic_rq_service, NULL);
  876. if (work_done > 0) {
  877. /* Replenish RQ
  878. */
  879. vnic_rq_fill(&enic->rq[0], enic_rq_alloc_buf);
  880. /* Accumulate intr event credits for this polling
  881. * cycle. An intr event is the completion of a
  882. * a WQ or RQ packet.
  883. */
  884. vnic_intr_return_credits(&enic->intr[ENIC_MSIX_RQ],
  885. work_done,
  886. 0 /* don't unmask intr */,
  887. 0 /* don't reset intr timer */);
  888. } else {
  889. /* If no work done, flush all LROs and exit polling
  890. */
  891. if (ENIC_SETTING(enic, LRO))
  892. lro_flush_all(&enic->lro_mgr);
  893. netif_rx_complete(netdev, napi);
  894. vnic_intr_unmask(&enic->intr[ENIC_MSIX_RQ]);
  895. }
  896. return work_done;
  897. }
  898. static void enic_notify_timer(unsigned long data)
  899. {
  900. struct enic *enic = (struct enic *)data;
  901. enic_notify_check(enic);
  902. mod_timer(&enic->notify_timer,
  903. round_jiffies(jiffies + ENIC_NOTIFY_TIMER_PERIOD));
  904. }
  905. static void enic_free_intr(struct enic *enic)
  906. {
  907. struct net_device *netdev = enic->netdev;
  908. unsigned int i;
  909. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  910. case VNIC_DEV_INTR_MODE_INTX:
  911. free_irq(enic->pdev->irq, netdev);
  912. break;
  913. case VNIC_DEV_INTR_MODE_MSI:
  914. free_irq(enic->pdev->irq, enic);
  915. break;
  916. case VNIC_DEV_INTR_MODE_MSIX:
  917. for (i = 0; i < ARRAY_SIZE(enic->msix); i++)
  918. if (enic->msix[i].requested)
  919. free_irq(enic->msix_entry[i].vector,
  920. enic->msix[i].devid);
  921. break;
  922. default:
  923. break;
  924. }
  925. }
  926. static int enic_request_intr(struct enic *enic)
  927. {
  928. struct net_device *netdev = enic->netdev;
  929. unsigned int i;
  930. int err = 0;
  931. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  932. case VNIC_DEV_INTR_MODE_INTX:
  933. err = request_irq(enic->pdev->irq, enic_isr_legacy,
  934. IRQF_SHARED, netdev->name, netdev);
  935. break;
  936. case VNIC_DEV_INTR_MODE_MSI:
  937. err = request_irq(enic->pdev->irq, enic_isr_msi,
  938. 0, netdev->name, enic);
  939. break;
  940. case VNIC_DEV_INTR_MODE_MSIX:
  941. sprintf(enic->msix[ENIC_MSIX_RQ].devname,
  942. "%.11s-rx-0", netdev->name);
  943. enic->msix[ENIC_MSIX_RQ].isr = enic_isr_msix_rq;
  944. enic->msix[ENIC_MSIX_RQ].devid = enic;
  945. sprintf(enic->msix[ENIC_MSIX_WQ].devname,
  946. "%.11s-tx-0", netdev->name);
  947. enic->msix[ENIC_MSIX_WQ].isr = enic_isr_msix_wq;
  948. enic->msix[ENIC_MSIX_WQ].devid = enic;
  949. sprintf(enic->msix[ENIC_MSIX_ERR].devname,
  950. "%.11s-err", netdev->name);
  951. enic->msix[ENIC_MSIX_ERR].isr = enic_isr_msix_err;
  952. enic->msix[ENIC_MSIX_ERR].devid = enic;
  953. sprintf(enic->msix[ENIC_MSIX_NOTIFY].devname,
  954. "%.11s-notify", netdev->name);
  955. enic->msix[ENIC_MSIX_NOTIFY].isr = enic_isr_msix_notify;
  956. enic->msix[ENIC_MSIX_NOTIFY].devid = enic;
  957. for (i = 0; i < ARRAY_SIZE(enic->msix); i++) {
  958. err = request_irq(enic->msix_entry[i].vector,
  959. enic->msix[i].isr, 0,
  960. enic->msix[i].devname,
  961. enic->msix[i].devid);
  962. if (err) {
  963. enic_free_intr(enic);
  964. break;
  965. }
  966. enic->msix[i].requested = 1;
  967. }
  968. break;
  969. default:
  970. break;
  971. }
  972. return err;
  973. }
  974. static int enic_notify_set(struct enic *enic)
  975. {
  976. int err;
  977. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  978. case VNIC_DEV_INTR_MODE_INTX:
  979. err = vnic_dev_notify_set(enic->vdev, ENIC_INTX_NOTIFY);
  980. break;
  981. case VNIC_DEV_INTR_MODE_MSIX:
  982. err = vnic_dev_notify_set(enic->vdev, ENIC_MSIX_NOTIFY);
  983. break;
  984. default:
  985. err = vnic_dev_notify_set(enic->vdev, -1 /* no intr */);
  986. break;
  987. }
  988. return err;
  989. }
  990. static void enic_notify_timer_start(struct enic *enic)
  991. {
  992. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  993. case VNIC_DEV_INTR_MODE_MSI:
  994. mod_timer(&enic->notify_timer, jiffies);
  995. break;
  996. default:
  997. /* Using intr for notification for INTx/MSI-X */
  998. break;
  999. };
  1000. }
  1001. /* rtnl lock is held, process context */
  1002. static int enic_open(struct net_device *netdev)
  1003. {
  1004. struct enic *enic = netdev_priv(netdev);
  1005. unsigned int i;
  1006. int err;
  1007. err = enic_request_intr(enic);
  1008. if (err) {
  1009. printk(KERN_ERR PFX "%s: Unable to request irq.\n",
  1010. netdev->name);
  1011. return err;
  1012. }
  1013. err = enic_notify_set(enic);
  1014. if (err) {
  1015. printk(KERN_ERR PFX
  1016. "%s: Failed to alloc notify buffer, aborting.\n",
  1017. netdev->name);
  1018. goto err_out_free_intr;
  1019. }
  1020. for (i = 0; i < enic->rq_count; i++) {
  1021. err = vnic_rq_fill(&enic->rq[i], enic_rq_alloc_buf);
  1022. if (err) {
  1023. printk(KERN_ERR PFX
  1024. "%s: Unable to alloc receive buffers.\n",
  1025. netdev->name);
  1026. goto err_out_notify_unset;
  1027. }
  1028. }
  1029. for (i = 0; i < enic->wq_count; i++)
  1030. vnic_wq_enable(&enic->wq[i]);
  1031. for (i = 0; i < enic->rq_count; i++)
  1032. vnic_rq_enable(&enic->rq[i]);
  1033. enic_add_station_addr(enic);
  1034. enic_set_multicast_list(netdev);
  1035. netif_wake_queue(netdev);
  1036. napi_enable(&enic->napi);
  1037. vnic_dev_enable(enic->vdev);
  1038. for (i = 0; i < enic->intr_count; i++)
  1039. vnic_intr_unmask(&enic->intr[i]);
  1040. enic_notify_timer_start(enic);
  1041. return 0;
  1042. err_out_notify_unset:
  1043. vnic_dev_notify_unset(enic->vdev);
  1044. err_out_free_intr:
  1045. enic_free_intr(enic);
  1046. return err;
  1047. }
  1048. /* rtnl lock is held, process context */
  1049. static int enic_stop(struct net_device *netdev)
  1050. {
  1051. struct enic *enic = netdev_priv(netdev);
  1052. unsigned int i;
  1053. int err;
  1054. del_timer_sync(&enic->notify_timer);
  1055. vnic_dev_disable(enic->vdev);
  1056. napi_disable(&enic->napi);
  1057. netif_stop_queue(netdev);
  1058. for (i = 0; i < enic->intr_count; i++)
  1059. vnic_intr_mask(&enic->intr[i]);
  1060. for (i = 0; i < enic->wq_count; i++) {
  1061. err = vnic_wq_disable(&enic->wq[i]);
  1062. if (err)
  1063. return err;
  1064. }
  1065. for (i = 0; i < enic->rq_count; i++) {
  1066. err = vnic_rq_disable(&enic->rq[i]);
  1067. if (err)
  1068. return err;
  1069. }
  1070. vnic_dev_notify_unset(enic->vdev);
  1071. enic_free_intr(enic);
  1072. (void)vnic_cq_service(&enic->cq[ENIC_CQ_RQ],
  1073. -1, enic_rq_service_drop, NULL);
  1074. (void)vnic_cq_service(&enic->cq[ENIC_CQ_WQ],
  1075. -1, enic_wq_service, NULL);
  1076. for (i = 0; i < enic->wq_count; i++)
  1077. vnic_wq_clean(&enic->wq[i], enic_free_wq_buf);
  1078. for (i = 0; i < enic->rq_count; i++)
  1079. vnic_rq_clean(&enic->rq[i], enic_free_rq_buf);
  1080. for (i = 0; i < enic->cq_count; i++)
  1081. vnic_cq_clean(&enic->cq[i]);
  1082. for (i = 0; i < enic->intr_count; i++)
  1083. vnic_intr_clean(&enic->intr[i]);
  1084. return 0;
  1085. }
  1086. static int enic_change_mtu(struct net_device *netdev, int new_mtu)
  1087. {
  1088. struct enic *enic = netdev_priv(netdev);
  1089. int running = netif_running(netdev);
  1090. if (new_mtu < ENIC_MIN_MTU || new_mtu > ENIC_MAX_MTU)
  1091. return -EINVAL;
  1092. if (running)
  1093. enic_stop(netdev);
  1094. netdev->mtu = new_mtu;
  1095. if (netdev->mtu > enic->port_mtu)
  1096. printk(KERN_WARNING PFX
  1097. "%s: interface MTU (%d) set higher "
  1098. "than port MTU (%d)\n",
  1099. netdev->name, netdev->mtu, enic->port_mtu);
  1100. if (running)
  1101. enic_open(netdev);
  1102. return 0;
  1103. }
  1104. #ifdef CONFIG_NET_POLL_CONTROLLER
  1105. static void enic_poll_controller(struct net_device *netdev)
  1106. {
  1107. struct enic *enic = netdev_priv(netdev);
  1108. struct vnic_dev *vdev = enic->vdev;
  1109. switch (vnic_dev_get_intr_mode(vdev)) {
  1110. case VNIC_DEV_INTR_MODE_MSIX:
  1111. enic_isr_msix_rq(enic->pdev->irq, enic);
  1112. enic_isr_msix_wq(enic->pdev->irq, enic);
  1113. break;
  1114. case VNIC_DEV_INTR_MODE_MSI:
  1115. enic_isr_msi(enic->pdev->irq, enic);
  1116. break;
  1117. case VNIC_DEV_INTR_MODE_INTX:
  1118. enic_isr_legacy(enic->pdev->irq, netdev);
  1119. break;
  1120. default:
  1121. break;
  1122. }
  1123. }
  1124. #endif
  1125. static int enic_dev_wait(struct vnic_dev *vdev,
  1126. int (*start)(struct vnic_dev *, int),
  1127. int (*finished)(struct vnic_dev *, int *),
  1128. int arg)
  1129. {
  1130. unsigned long time;
  1131. int done;
  1132. int err;
  1133. BUG_ON(in_interrupt());
  1134. err = start(vdev, arg);
  1135. if (err)
  1136. return err;
  1137. /* Wait for func to complete...2 seconds max
  1138. */
  1139. time = jiffies + (HZ * 2);
  1140. do {
  1141. err = finished(vdev, &done);
  1142. if (err)
  1143. return err;
  1144. if (done)
  1145. return 0;
  1146. schedule_timeout_uninterruptible(HZ / 10);
  1147. } while (time_after(time, jiffies));
  1148. return -ETIMEDOUT;
  1149. }
  1150. static int enic_dev_open(struct enic *enic)
  1151. {
  1152. int err;
  1153. err = enic_dev_wait(enic->vdev, vnic_dev_open,
  1154. vnic_dev_open_done, 0);
  1155. if (err)
  1156. printk(KERN_ERR PFX
  1157. "vNIC device open failed, err %d.\n", err);
  1158. return err;
  1159. }
  1160. static int enic_dev_soft_reset(struct enic *enic)
  1161. {
  1162. int err;
  1163. err = enic_dev_wait(enic->vdev, vnic_dev_soft_reset,
  1164. vnic_dev_soft_reset_done, 0);
  1165. if (err)
  1166. printk(KERN_ERR PFX
  1167. "vNIC soft reset failed, err %d.\n", err);
  1168. return err;
  1169. }
  1170. static void enic_reset(struct work_struct *work)
  1171. {
  1172. struct enic *enic = container_of(work, struct enic, reset);
  1173. if (!netif_running(enic->netdev))
  1174. return;
  1175. rtnl_lock();
  1176. spin_lock(&enic->devcmd_lock);
  1177. vnic_dev_hang_notify(enic->vdev);
  1178. spin_unlock(&enic->devcmd_lock);
  1179. enic_stop(enic->netdev);
  1180. enic_dev_soft_reset(enic);
  1181. enic_reset_mcaddrs(enic);
  1182. enic_init_vnic_resources(enic);
  1183. enic_open(enic->netdev);
  1184. rtnl_unlock();
  1185. }
  1186. static int enic_set_intr_mode(struct enic *enic)
  1187. {
  1188. unsigned int n = ARRAY_SIZE(enic->rq);
  1189. unsigned int m = ARRAY_SIZE(enic->wq);
  1190. unsigned int i;
  1191. /* Set interrupt mode (INTx, MSI, MSI-X) depending
  1192. * system capabilities.
  1193. *
  1194. * Try MSI-X first
  1195. *
  1196. * We need n RQs, m WQs, n+m CQs, and n+m+2 INTRs
  1197. * (the second to last INTR is used for WQ/RQ errors)
  1198. * (the last INTR is used for notifications)
  1199. */
  1200. BUG_ON(ARRAY_SIZE(enic->msix_entry) < n + m + 2);
  1201. for (i = 0; i < n + m + 2; i++)
  1202. enic->msix_entry[i].entry = i;
  1203. if (enic->config.intr_mode < 1 &&
  1204. enic->rq_count >= n &&
  1205. enic->wq_count >= m &&
  1206. enic->cq_count >= n + m &&
  1207. enic->intr_count >= n + m + 2 &&
  1208. !pci_enable_msix(enic->pdev, enic->msix_entry, n + m + 2)) {
  1209. enic->rq_count = n;
  1210. enic->wq_count = m;
  1211. enic->cq_count = n + m;
  1212. enic->intr_count = n + m + 2;
  1213. vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_MSIX);
  1214. return 0;
  1215. }
  1216. /* Next try MSI
  1217. *
  1218. * We need 1 RQ, 1 WQ, 2 CQs, and 1 INTR
  1219. */
  1220. if (enic->config.intr_mode < 2 &&
  1221. enic->rq_count >= 1 &&
  1222. enic->wq_count >= 1 &&
  1223. enic->cq_count >= 2 &&
  1224. enic->intr_count >= 1 &&
  1225. !pci_enable_msi(enic->pdev)) {
  1226. enic->rq_count = 1;
  1227. enic->wq_count = 1;
  1228. enic->cq_count = 2;
  1229. enic->intr_count = 1;
  1230. vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_MSI);
  1231. return 0;
  1232. }
  1233. /* Next try INTx
  1234. *
  1235. * We need 1 RQ, 1 WQ, 2 CQs, and 3 INTRs
  1236. * (the first INTR is used for WQ/RQ)
  1237. * (the second INTR is used for WQ/RQ errors)
  1238. * (the last INTR is used for notifications)
  1239. */
  1240. if (enic->config.intr_mode < 3 &&
  1241. enic->rq_count >= 1 &&
  1242. enic->wq_count >= 1 &&
  1243. enic->cq_count >= 2 &&
  1244. enic->intr_count >= 3) {
  1245. enic->rq_count = 1;
  1246. enic->wq_count = 1;
  1247. enic->cq_count = 2;
  1248. enic->intr_count = 3;
  1249. vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_INTX);
  1250. return 0;
  1251. }
  1252. vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN);
  1253. return -EINVAL;
  1254. }
  1255. static void enic_clear_intr_mode(struct enic *enic)
  1256. {
  1257. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  1258. case VNIC_DEV_INTR_MODE_MSIX:
  1259. pci_disable_msix(enic->pdev);
  1260. break;
  1261. case VNIC_DEV_INTR_MODE_MSI:
  1262. pci_disable_msi(enic->pdev);
  1263. break;
  1264. default:
  1265. break;
  1266. }
  1267. vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN);
  1268. }
  1269. static void enic_iounmap(struct enic *enic)
  1270. {
  1271. if (enic->bar0.vaddr)
  1272. iounmap(enic->bar0.vaddr);
  1273. }
  1274. static int __devinit enic_probe(struct pci_dev *pdev,
  1275. const struct pci_device_id *ent)
  1276. {
  1277. struct net_device *netdev;
  1278. struct enic *enic;
  1279. int using_dac = 0;
  1280. unsigned int i;
  1281. int err;
  1282. const u8 rss_default_cpu = 0;
  1283. const u8 rss_hash_type = 0;
  1284. const u8 rss_hash_bits = 0;
  1285. const u8 rss_base_cpu = 0;
  1286. const u8 rss_enable = 0;
  1287. const u8 tso_ipid_split_en = 0;
  1288. const u8 ig_vlan_strip_en = 1;
  1289. /* Allocate net device structure and initialize. Private
  1290. * instance data is initialized to zero.
  1291. */
  1292. netdev = alloc_etherdev(sizeof(struct enic));
  1293. if (!netdev) {
  1294. printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n");
  1295. return -ENOMEM;
  1296. }
  1297. pci_set_drvdata(pdev, netdev);
  1298. SET_NETDEV_DEV(netdev, &pdev->dev);
  1299. enic = netdev_priv(netdev);
  1300. enic->netdev = netdev;
  1301. enic->pdev = pdev;
  1302. /* Setup PCI resources
  1303. */
  1304. err = pci_enable_device(pdev);
  1305. if (err) {
  1306. printk(KERN_ERR PFX
  1307. "Cannot enable PCI device, aborting.\n");
  1308. goto err_out_free_netdev;
  1309. }
  1310. err = pci_request_regions(pdev, DRV_NAME);
  1311. if (err) {
  1312. printk(KERN_ERR PFX
  1313. "Cannot request PCI regions, aborting.\n");
  1314. goto err_out_disable_device;
  1315. }
  1316. pci_set_master(pdev);
  1317. /* Query PCI controller on system for DMA addressing
  1318. * limitation for the device. Try 40-bit first, and
  1319. * fail to 32-bit.
  1320. */
  1321. err = pci_set_dma_mask(pdev, DMA_40BIT_MASK);
  1322. if (err) {
  1323. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  1324. if (err) {
  1325. printk(KERN_ERR PFX
  1326. "No usable DMA configuration, aborting.\n");
  1327. goto err_out_release_regions;
  1328. }
  1329. err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  1330. if (err) {
  1331. printk(KERN_ERR PFX
  1332. "Unable to obtain 32-bit DMA "
  1333. "for consistent allocations, aborting.\n");
  1334. goto err_out_release_regions;
  1335. }
  1336. } else {
  1337. err = pci_set_consistent_dma_mask(pdev, DMA_40BIT_MASK);
  1338. if (err) {
  1339. printk(KERN_ERR PFX
  1340. "Unable to obtain 40-bit DMA "
  1341. "for consistent allocations, aborting.\n");
  1342. goto err_out_release_regions;
  1343. }
  1344. using_dac = 1;
  1345. }
  1346. /* Map vNIC resources from BAR0
  1347. */
  1348. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  1349. printk(KERN_ERR PFX
  1350. "BAR0 not memory-map'able, aborting.\n");
  1351. err = -ENODEV;
  1352. goto err_out_release_regions;
  1353. }
  1354. enic->bar0.vaddr = pci_iomap(pdev, 0, enic->bar0.len);
  1355. enic->bar0.bus_addr = pci_resource_start(pdev, 0);
  1356. enic->bar0.len = pci_resource_len(pdev, 0);
  1357. if (!enic->bar0.vaddr) {
  1358. printk(KERN_ERR PFX
  1359. "Cannot memory-map BAR0 res hdr, aborting.\n");
  1360. err = -ENODEV;
  1361. goto err_out_release_regions;
  1362. }
  1363. /* Register vNIC device
  1364. */
  1365. enic->vdev = vnic_dev_register(NULL, enic, pdev, &enic->bar0);
  1366. if (!enic->vdev) {
  1367. printk(KERN_ERR PFX
  1368. "vNIC registration failed, aborting.\n");
  1369. err = -ENODEV;
  1370. goto err_out_iounmap;
  1371. }
  1372. /* Issue device open to get device in known state
  1373. */
  1374. err = enic_dev_open(enic);
  1375. if (err) {
  1376. printk(KERN_ERR PFX
  1377. "vNIC dev open failed, aborting.\n");
  1378. goto err_out_vnic_unregister;
  1379. }
  1380. /* Issue device init to initialize the vnic-to-switch link.
  1381. * We'll start with carrier off and wait for link UP
  1382. * notification later to turn on carrier. We don't need
  1383. * to wait here for the vnic-to-switch link initialization
  1384. * to complete; link UP notification is the indication that
  1385. * the process is complete.
  1386. */
  1387. netif_carrier_off(netdev);
  1388. err = vnic_dev_init(enic->vdev, 0);
  1389. if (err) {
  1390. printk(KERN_ERR PFX
  1391. "vNIC dev init failed, aborting.\n");
  1392. goto err_out_dev_close;
  1393. }
  1394. /* Get vNIC configuration
  1395. */
  1396. err = enic_get_vnic_config(enic);
  1397. if (err) {
  1398. printk(KERN_ERR PFX
  1399. "Get vNIC configuration failed, aborting.\n");
  1400. goto err_out_dev_close;
  1401. }
  1402. /* Get available resource counts
  1403. */
  1404. enic_get_res_counts(enic);
  1405. /* Set interrupt mode based on resource counts and system
  1406. * capabilities
  1407. */
  1408. err = enic_set_intr_mode(enic);
  1409. if (err) {
  1410. printk(KERN_ERR PFX
  1411. "Failed to set intr mode, aborting.\n");
  1412. goto err_out_dev_close;
  1413. }
  1414. /* Allocate and configure vNIC resources
  1415. */
  1416. err = enic_alloc_vnic_resources(enic);
  1417. if (err) {
  1418. printk(KERN_ERR PFX
  1419. "Failed to alloc vNIC resources, aborting.\n");
  1420. goto err_out_free_vnic_resources;
  1421. }
  1422. enic_init_vnic_resources(enic);
  1423. /* Enable VLAN tag stripping. RSS not enabled (yet).
  1424. */
  1425. err = enic_set_nic_cfg(enic,
  1426. rss_default_cpu, rss_hash_type,
  1427. rss_hash_bits, rss_base_cpu,
  1428. rss_enable, tso_ipid_split_en,
  1429. ig_vlan_strip_en);
  1430. if (err) {
  1431. printk(KERN_ERR PFX
  1432. "Failed to config nic, aborting.\n");
  1433. goto err_out_free_vnic_resources;
  1434. }
  1435. /* Setup notification timer, HW reset task, and locks
  1436. */
  1437. init_timer(&enic->notify_timer);
  1438. enic->notify_timer.function = enic_notify_timer;
  1439. enic->notify_timer.data = (unsigned long)enic;
  1440. INIT_WORK(&enic->reset, enic_reset);
  1441. for (i = 0; i < enic->wq_count; i++)
  1442. spin_lock_init(&enic->wq_lock[i]);
  1443. spin_lock_init(&enic->devcmd_lock);
  1444. /* Register net device
  1445. */
  1446. enic->port_mtu = enic->config.mtu;
  1447. (void)enic_change_mtu(netdev, enic->port_mtu);
  1448. err = enic_set_mac_addr(netdev, enic->mac_addr);
  1449. if (err) {
  1450. printk(KERN_ERR PFX
  1451. "Invalid MAC address, aborting.\n");
  1452. goto err_out_free_vnic_resources;
  1453. }
  1454. netdev->open = enic_open;
  1455. netdev->stop = enic_stop;
  1456. netdev->hard_start_xmit = enic_hard_start_xmit;
  1457. netdev->get_stats = enic_get_stats;
  1458. netdev->set_multicast_list = enic_set_multicast_list;
  1459. netdev->change_mtu = enic_change_mtu;
  1460. netdev->vlan_rx_register = enic_vlan_rx_register;
  1461. netdev->vlan_rx_add_vid = enic_vlan_rx_add_vid;
  1462. netdev->vlan_rx_kill_vid = enic_vlan_rx_kill_vid;
  1463. netdev->tx_timeout = enic_tx_timeout;
  1464. netdev->watchdog_timeo = 2 * HZ;
  1465. netdev->ethtool_ops = &enic_ethtool_ops;
  1466. #ifdef CONFIG_NET_POLL_CONTROLLER
  1467. netdev->poll_controller = enic_poll_controller;
  1468. #endif
  1469. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  1470. default:
  1471. netif_napi_add(netdev, &enic->napi, enic_poll, 64);
  1472. break;
  1473. case VNIC_DEV_INTR_MODE_MSIX:
  1474. netif_napi_add(netdev, &enic->napi, enic_poll_msix, 64);
  1475. break;
  1476. }
  1477. netdev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  1478. if (ENIC_SETTING(enic, TXCSUM))
  1479. netdev->features |= NETIF_F_SG | NETIF_F_HW_CSUM;
  1480. if (ENIC_SETTING(enic, TSO))
  1481. netdev->features |= NETIF_F_TSO |
  1482. NETIF_F_TSO6 | NETIF_F_TSO_ECN;
  1483. if (using_dac)
  1484. netdev->features |= NETIF_F_HIGHDMA;
  1485. enic->csum_rx_enabled = ENIC_SETTING(enic, RXCSUM);
  1486. if (ENIC_SETTING(enic, LRO)) {
  1487. enic->lro_mgr.max_aggr = ENIC_LRO_MAX_AGGR;
  1488. enic->lro_mgr.max_desc = ENIC_LRO_MAX_DESC;
  1489. enic->lro_mgr.lro_arr = enic->lro_desc;
  1490. enic->lro_mgr.get_skb_header = enic_get_skb_header;
  1491. enic->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
  1492. enic->lro_mgr.dev = netdev;
  1493. enic->lro_mgr.ip_summed = CHECKSUM_COMPLETE;
  1494. enic->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
  1495. }
  1496. err = register_netdev(netdev);
  1497. if (err) {
  1498. printk(KERN_ERR PFX
  1499. "Cannot register net device, aborting.\n");
  1500. goto err_out_free_vnic_resources;
  1501. }
  1502. return 0;
  1503. err_out_free_vnic_resources:
  1504. enic_free_vnic_resources(enic);
  1505. err_out_dev_close:
  1506. vnic_dev_close(enic->vdev);
  1507. err_out_vnic_unregister:
  1508. enic_clear_intr_mode(enic);
  1509. vnic_dev_unregister(enic->vdev);
  1510. err_out_iounmap:
  1511. enic_iounmap(enic);
  1512. err_out_release_regions:
  1513. pci_release_regions(pdev);
  1514. err_out_disable_device:
  1515. pci_disable_device(pdev);
  1516. err_out_free_netdev:
  1517. pci_set_drvdata(pdev, NULL);
  1518. free_netdev(netdev);
  1519. return err;
  1520. }
  1521. static void __devexit enic_remove(struct pci_dev *pdev)
  1522. {
  1523. struct net_device *netdev = pci_get_drvdata(pdev);
  1524. if (netdev) {
  1525. struct enic *enic = netdev_priv(netdev);
  1526. flush_scheduled_work();
  1527. unregister_netdev(netdev);
  1528. enic_free_vnic_resources(enic);
  1529. vnic_dev_close(enic->vdev);
  1530. enic_clear_intr_mode(enic);
  1531. vnic_dev_unregister(enic->vdev);
  1532. enic_iounmap(enic);
  1533. pci_release_regions(pdev);
  1534. pci_disable_device(pdev);
  1535. pci_set_drvdata(pdev, NULL);
  1536. free_netdev(netdev);
  1537. }
  1538. }
  1539. static struct pci_driver enic_driver = {
  1540. .name = DRV_NAME,
  1541. .id_table = enic_id_table,
  1542. .probe = enic_probe,
  1543. .remove = __devexit_p(enic_remove),
  1544. };
  1545. static int __init enic_init_module(void)
  1546. {
  1547. printk(KERN_INFO PFX "%s, ver %s\n", DRV_DESCRIPTION, DRV_VERSION);
  1548. return pci_register_driver(&enic_driver);
  1549. }
  1550. static void __exit enic_cleanup_module(void)
  1551. {
  1552. pci_unregister_driver(&enic_driver);
  1553. }
  1554. module_init(enic_init_module);
  1555. module_exit(enic_cleanup_module);