enic_main.c 46 KB

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