enic_main.c 46 KB

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