enic_main.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464
  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/if_link.h>
  32. #include <linux/ethtool.h>
  33. #include <linux/in.h>
  34. #include <linux/ip.h>
  35. #include <linux/ipv6.h>
  36. #include <linux/tcp.h>
  37. #include <net/ip6_checksum.h>
  38. #include "cq_enet_desc.h"
  39. #include "vnic_dev.h"
  40. #include "vnic_intr.h"
  41. #include "vnic_stats.h"
  42. #include "vnic_vic.h"
  43. #include "enic_res.h"
  44. #include "enic.h"
  45. #define ENIC_NOTIFY_TIMER_PERIOD (2 * HZ)
  46. #define WQ_ENET_MAX_DESC_LEN (1 << WQ_ENET_LEN_BITS)
  47. #define MAX_TSO (1 << 16)
  48. #define ENIC_DESC_MAX_SPLITS (MAX_TSO / WQ_ENET_MAX_DESC_LEN + 1)
  49. #define PCI_DEVICE_ID_CISCO_VIC_ENET 0x0043 /* ethernet vnic */
  50. #define PCI_DEVICE_ID_CISCO_VIC_ENET_DYN 0x0044 /* enet dynamic vnic */
  51. /* Supported devices */
  52. static DEFINE_PCI_DEVICE_TABLE(enic_id_table) = {
  53. { PCI_VDEVICE(CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET) },
  54. { PCI_VDEVICE(CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET_DYN) },
  55. { 0, } /* end of table */
  56. };
  57. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  58. MODULE_AUTHOR("Scott Feldman <scofeldm@cisco.com>");
  59. MODULE_LICENSE("GPL");
  60. MODULE_VERSION(DRV_VERSION);
  61. MODULE_DEVICE_TABLE(pci, enic_id_table);
  62. struct enic_stat {
  63. char name[ETH_GSTRING_LEN];
  64. unsigned int offset;
  65. };
  66. #define ENIC_TX_STAT(stat) \
  67. { .name = #stat, .offset = offsetof(struct vnic_tx_stats, stat) / 8 }
  68. #define ENIC_RX_STAT(stat) \
  69. { .name = #stat, .offset = offsetof(struct vnic_rx_stats, stat) / 8 }
  70. static const struct enic_stat enic_tx_stats[] = {
  71. ENIC_TX_STAT(tx_frames_ok),
  72. ENIC_TX_STAT(tx_unicast_frames_ok),
  73. ENIC_TX_STAT(tx_multicast_frames_ok),
  74. ENIC_TX_STAT(tx_broadcast_frames_ok),
  75. ENIC_TX_STAT(tx_bytes_ok),
  76. ENIC_TX_STAT(tx_unicast_bytes_ok),
  77. ENIC_TX_STAT(tx_multicast_bytes_ok),
  78. ENIC_TX_STAT(tx_broadcast_bytes_ok),
  79. ENIC_TX_STAT(tx_drops),
  80. ENIC_TX_STAT(tx_errors),
  81. ENIC_TX_STAT(tx_tso),
  82. };
  83. static const struct enic_stat enic_rx_stats[] = {
  84. ENIC_RX_STAT(rx_frames_ok),
  85. ENIC_RX_STAT(rx_frames_total),
  86. ENIC_RX_STAT(rx_unicast_frames_ok),
  87. ENIC_RX_STAT(rx_multicast_frames_ok),
  88. ENIC_RX_STAT(rx_broadcast_frames_ok),
  89. ENIC_RX_STAT(rx_bytes_ok),
  90. ENIC_RX_STAT(rx_unicast_bytes_ok),
  91. ENIC_RX_STAT(rx_multicast_bytes_ok),
  92. ENIC_RX_STAT(rx_broadcast_bytes_ok),
  93. ENIC_RX_STAT(rx_drop),
  94. ENIC_RX_STAT(rx_no_bufs),
  95. ENIC_RX_STAT(rx_errors),
  96. ENIC_RX_STAT(rx_rss),
  97. ENIC_RX_STAT(rx_crc_errors),
  98. ENIC_RX_STAT(rx_frames_64),
  99. ENIC_RX_STAT(rx_frames_127),
  100. ENIC_RX_STAT(rx_frames_255),
  101. ENIC_RX_STAT(rx_frames_511),
  102. ENIC_RX_STAT(rx_frames_1023),
  103. ENIC_RX_STAT(rx_frames_1518),
  104. ENIC_RX_STAT(rx_frames_to_max),
  105. };
  106. static const unsigned int enic_n_tx_stats = ARRAY_SIZE(enic_tx_stats);
  107. static const unsigned int enic_n_rx_stats = ARRAY_SIZE(enic_rx_stats);
  108. static int enic_is_dynamic(struct enic *enic)
  109. {
  110. return enic->pdev->device == PCI_DEVICE_ID_CISCO_VIC_ENET_DYN;
  111. }
  112. static int enic_get_settings(struct net_device *netdev,
  113. struct ethtool_cmd *ecmd)
  114. {
  115. struct enic *enic = netdev_priv(netdev);
  116. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
  117. ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
  118. ecmd->port = PORT_FIBRE;
  119. ecmd->transceiver = XCVR_EXTERNAL;
  120. if (netif_carrier_ok(netdev)) {
  121. ecmd->speed = vnic_dev_port_speed(enic->vdev);
  122. ecmd->duplex = DUPLEX_FULL;
  123. } else {
  124. ecmd->speed = -1;
  125. ecmd->duplex = -1;
  126. }
  127. ecmd->autoneg = AUTONEG_DISABLE;
  128. return 0;
  129. }
  130. static void enic_get_drvinfo(struct net_device *netdev,
  131. struct ethtool_drvinfo *drvinfo)
  132. {
  133. struct enic *enic = netdev_priv(netdev);
  134. struct vnic_devcmd_fw_info *fw_info;
  135. spin_lock(&enic->devcmd_lock);
  136. vnic_dev_fw_info(enic->vdev, &fw_info);
  137. spin_unlock(&enic->devcmd_lock);
  138. strncpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
  139. strncpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
  140. strncpy(drvinfo->fw_version, fw_info->fw_version,
  141. sizeof(drvinfo->fw_version));
  142. strncpy(drvinfo->bus_info, pci_name(enic->pdev),
  143. sizeof(drvinfo->bus_info));
  144. }
  145. static void enic_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
  146. {
  147. unsigned int i;
  148. switch (stringset) {
  149. case ETH_SS_STATS:
  150. for (i = 0; i < enic_n_tx_stats; i++) {
  151. memcpy(data, enic_tx_stats[i].name, ETH_GSTRING_LEN);
  152. data += ETH_GSTRING_LEN;
  153. }
  154. for (i = 0; i < enic_n_rx_stats; i++) {
  155. memcpy(data, enic_rx_stats[i].name, ETH_GSTRING_LEN);
  156. data += ETH_GSTRING_LEN;
  157. }
  158. break;
  159. }
  160. }
  161. static int enic_get_sset_count(struct net_device *netdev, int sset)
  162. {
  163. switch (sset) {
  164. case ETH_SS_STATS:
  165. return enic_n_tx_stats + enic_n_rx_stats;
  166. default:
  167. return -EOPNOTSUPP;
  168. }
  169. }
  170. static void enic_get_ethtool_stats(struct net_device *netdev,
  171. struct ethtool_stats *stats, u64 *data)
  172. {
  173. struct enic *enic = netdev_priv(netdev);
  174. struct vnic_stats *vstats;
  175. unsigned int i;
  176. spin_lock(&enic->devcmd_lock);
  177. vnic_dev_stats_dump(enic->vdev, &vstats);
  178. spin_unlock(&enic->devcmd_lock);
  179. for (i = 0; i < enic_n_tx_stats; i++)
  180. *(data++) = ((u64 *)&vstats->tx)[enic_tx_stats[i].offset];
  181. for (i = 0; i < enic_n_rx_stats; i++)
  182. *(data++) = ((u64 *)&vstats->rx)[enic_rx_stats[i].offset];
  183. }
  184. static u32 enic_get_rx_csum(struct net_device *netdev)
  185. {
  186. struct enic *enic = netdev_priv(netdev);
  187. return enic->csum_rx_enabled;
  188. }
  189. static int enic_set_rx_csum(struct net_device *netdev, u32 data)
  190. {
  191. struct enic *enic = netdev_priv(netdev);
  192. if (data && !ENIC_SETTING(enic, RXCSUM))
  193. return -EINVAL;
  194. enic->csum_rx_enabled = !!data;
  195. return 0;
  196. }
  197. static int enic_set_tx_csum(struct net_device *netdev, u32 data)
  198. {
  199. struct enic *enic = netdev_priv(netdev);
  200. if (data && !ENIC_SETTING(enic, TXCSUM))
  201. return -EINVAL;
  202. if (data)
  203. netdev->features |= NETIF_F_HW_CSUM;
  204. else
  205. netdev->features &= ~NETIF_F_HW_CSUM;
  206. return 0;
  207. }
  208. static int enic_set_tso(struct net_device *netdev, u32 data)
  209. {
  210. struct enic *enic = netdev_priv(netdev);
  211. if (data && !ENIC_SETTING(enic, TSO))
  212. return -EINVAL;
  213. if (data)
  214. netdev->features |=
  215. NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN;
  216. else
  217. netdev->features &=
  218. ~(NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN);
  219. return 0;
  220. }
  221. static u32 enic_get_msglevel(struct net_device *netdev)
  222. {
  223. struct enic *enic = netdev_priv(netdev);
  224. return enic->msg_enable;
  225. }
  226. static void enic_set_msglevel(struct net_device *netdev, u32 value)
  227. {
  228. struct enic *enic = netdev_priv(netdev);
  229. enic->msg_enable = value;
  230. }
  231. static int enic_get_coalesce(struct net_device *netdev,
  232. struct ethtool_coalesce *ecmd)
  233. {
  234. struct enic *enic = netdev_priv(netdev);
  235. ecmd->tx_coalesce_usecs = enic->tx_coalesce_usecs;
  236. ecmd->rx_coalesce_usecs = enic->rx_coalesce_usecs;
  237. return 0;
  238. }
  239. static int enic_set_coalesce(struct net_device *netdev,
  240. struct ethtool_coalesce *ecmd)
  241. {
  242. struct enic *enic = netdev_priv(netdev);
  243. u32 tx_coalesce_usecs;
  244. u32 rx_coalesce_usecs;
  245. tx_coalesce_usecs = min_t(u32,
  246. INTR_COALESCE_HW_TO_USEC(VNIC_INTR_TIMER_MAX),
  247. ecmd->tx_coalesce_usecs);
  248. rx_coalesce_usecs = min_t(u32,
  249. INTR_COALESCE_HW_TO_USEC(VNIC_INTR_TIMER_MAX),
  250. ecmd->rx_coalesce_usecs);
  251. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  252. case VNIC_DEV_INTR_MODE_INTX:
  253. if (tx_coalesce_usecs != rx_coalesce_usecs)
  254. return -EINVAL;
  255. vnic_intr_coalescing_timer_set(&enic->intr[ENIC_INTX_WQ_RQ],
  256. INTR_COALESCE_USEC_TO_HW(tx_coalesce_usecs));
  257. break;
  258. case VNIC_DEV_INTR_MODE_MSI:
  259. if (tx_coalesce_usecs != rx_coalesce_usecs)
  260. return -EINVAL;
  261. vnic_intr_coalescing_timer_set(&enic->intr[0],
  262. INTR_COALESCE_USEC_TO_HW(tx_coalesce_usecs));
  263. break;
  264. case VNIC_DEV_INTR_MODE_MSIX:
  265. vnic_intr_coalescing_timer_set(&enic->intr[ENIC_MSIX_WQ],
  266. INTR_COALESCE_USEC_TO_HW(tx_coalesce_usecs));
  267. vnic_intr_coalescing_timer_set(&enic->intr[ENIC_MSIX_RQ],
  268. INTR_COALESCE_USEC_TO_HW(rx_coalesce_usecs));
  269. break;
  270. default:
  271. break;
  272. }
  273. enic->tx_coalesce_usecs = tx_coalesce_usecs;
  274. enic->rx_coalesce_usecs = rx_coalesce_usecs;
  275. return 0;
  276. }
  277. static const struct ethtool_ops enic_ethtool_ops = {
  278. .get_settings = enic_get_settings,
  279. .get_drvinfo = enic_get_drvinfo,
  280. .get_msglevel = enic_get_msglevel,
  281. .set_msglevel = enic_set_msglevel,
  282. .get_link = ethtool_op_get_link,
  283. .get_strings = enic_get_strings,
  284. .get_sset_count = enic_get_sset_count,
  285. .get_ethtool_stats = enic_get_ethtool_stats,
  286. .get_rx_csum = enic_get_rx_csum,
  287. .set_rx_csum = enic_set_rx_csum,
  288. .get_tx_csum = ethtool_op_get_tx_csum,
  289. .set_tx_csum = enic_set_tx_csum,
  290. .get_sg = ethtool_op_get_sg,
  291. .set_sg = ethtool_op_set_sg,
  292. .get_tso = ethtool_op_get_tso,
  293. .set_tso = enic_set_tso,
  294. .get_coalesce = enic_get_coalesce,
  295. .set_coalesce = enic_set_coalesce,
  296. .get_flags = ethtool_op_get_flags,
  297. .set_flags = ethtool_op_set_flags,
  298. };
  299. static void enic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf)
  300. {
  301. struct enic *enic = vnic_dev_priv(wq->vdev);
  302. if (buf->sop)
  303. pci_unmap_single(enic->pdev, buf->dma_addr,
  304. buf->len, PCI_DMA_TODEVICE);
  305. else
  306. pci_unmap_page(enic->pdev, buf->dma_addr,
  307. buf->len, PCI_DMA_TODEVICE);
  308. if (buf->os_buf)
  309. dev_kfree_skb_any(buf->os_buf);
  310. }
  311. static void enic_wq_free_buf(struct vnic_wq *wq,
  312. struct cq_desc *cq_desc, struct vnic_wq_buf *buf, void *opaque)
  313. {
  314. enic_free_wq_buf(wq, buf);
  315. }
  316. static int enic_wq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
  317. u8 type, u16 q_number, u16 completed_index, void *opaque)
  318. {
  319. struct enic *enic = vnic_dev_priv(vdev);
  320. spin_lock(&enic->wq_lock[q_number]);
  321. vnic_wq_service(&enic->wq[q_number], cq_desc,
  322. completed_index, enic_wq_free_buf,
  323. opaque);
  324. if (netif_queue_stopped(enic->netdev) &&
  325. vnic_wq_desc_avail(&enic->wq[q_number]) >=
  326. (MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS))
  327. netif_wake_queue(enic->netdev);
  328. spin_unlock(&enic->wq_lock[q_number]);
  329. return 0;
  330. }
  331. static void enic_log_q_error(struct enic *enic)
  332. {
  333. unsigned int i;
  334. u32 error_status;
  335. for (i = 0; i < enic->wq_count; i++) {
  336. error_status = vnic_wq_error_status(&enic->wq[i]);
  337. if (error_status)
  338. printk(KERN_ERR PFX "%s: WQ[%d] error_status %d\n",
  339. enic->netdev->name, i, error_status);
  340. }
  341. for (i = 0; i < enic->rq_count; i++) {
  342. error_status = vnic_rq_error_status(&enic->rq[i]);
  343. if (error_status)
  344. printk(KERN_ERR PFX "%s: RQ[%d] error_status %d\n",
  345. enic->netdev->name, i, error_status);
  346. }
  347. }
  348. static void enic_link_check(struct enic *enic)
  349. {
  350. int link_status = vnic_dev_link_status(enic->vdev);
  351. int carrier_ok = netif_carrier_ok(enic->netdev);
  352. if (link_status && !carrier_ok) {
  353. printk(KERN_INFO PFX "%s: Link UP\n", enic->netdev->name);
  354. netif_carrier_on(enic->netdev);
  355. } else if (!link_status && carrier_ok) {
  356. printk(KERN_INFO PFX "%s: Link DOWN\n", enic->netdev->name);
  357. netif_carrier_off(enic->netdev);
  358. }
  359. }
  360. static void enic_mtu_check(struct enic *enic)
  361. {
  362. u32 mtu = vnic_dev_mtu(enic->vdev);
  363. if (mtu && mtu != enic->port_mtu) {
  364. enic->port_mtu = mtu;
  365. if (mtu < enic->netdev->mtu)
  366. printk(KERN_WARNING PFX
  367. "%s: interface MTU (%d) set higher "
  368. "than switch port MTU (%d)\n",
  369. enic->netdev->name, enic->netdev->mtu, mtu);
  370. }
  371. }
  372. static void enic_msglvl_check(struct enic *enic)
  373. {
  374. u32 msg_enable = vnic_dev_msg_lvl(enic->vdev);
  375. if (msg_enable != enic->msg_enable) {
  376. printk(KERN_INFO PFX "%s: msg lvl changed from 0x%x to 0x%x\n",
  377. enic->netdev->name, enic->msg_enable, msg_enable);
  378. enic->msg_enable = msg_enable;
  379. }
  380. }
  381. static void enic_notify_check(struct enic *enic)
  382. {
  383. enic_msglvl_check(enic);
  384. enic_mtu_check(enic);
  385. enic_link_check(enic);
  386. }
  387. #define ENIC_TEST_INTR(pba, i) (pba & (1 << i))
  388. static irqreturn_t enic_isr_legacy(int irq, void *data)
  389. {
  390. struct net_device *netdev = data;
  391. struct enic *enic = netdev_priv(netdev);
  392. u32 pba;
  393. vnic_intr_mask(&enic->intr[ENIC_INTX_WQ_RQ]);
  394. pba = vnic_intr_legacy_pba(enic->legacy_pba);
  395. if (!pba) {
  396. vnic_intr_unmask(&enic->intr[ENIC_INTX_WQ_RQ]);
  397. return IRQ_NONE; /* not our interrupt */
  398. }
  399. if (ENIC_TEST_INTR(pba, ENIC_INTX_NOTIFY)) {
  400. vnic_intr_return_all_credits(&enic->intr[ENIC_INTX_NOTIFY]);
  401. enic_notify_check(enic);
  402. }
  403. if (ENIC_TEST_INTR(pba, ENIC_INTX_ERR)) {
  404. vnic_intr_return_all_credits(&enic->intr[ENIC_INTX_ERR]);
  405. enic_log_q_error(enic);
  406. /* schedule recovery from WQ/RQ error */
  407. schedule_work(&enic->reset);
  408. return IRQ_HANDLED;
  409. }
  410. if (ENIC_TEST_INTR(pba, ENIC_INTX_WQ_RQ)) {
  411. if (napi_schedule_prep(&enic->napi))
  412. __napi_schedule(&enic->napi);
  413. } else {
  414. vnic_intr_unmask(&enic->intr[ENIC_INTX_WQ_RQ]);
  415. }
  416. return IRQ_HANDLED;
  417. }
  418. static irqreturn_t enic_isr_msi(int irq, void *data)
  419. {
  420. struct enic *enic = data;
  421. /* With MSI, there is no sharing of interrupts, so this is
  422. * our interrupt and there is no need to ack it. The device
  423. * is not providing per-vector masking, so the OS will not
  424. * write to PCI config space to mask/unmask the interrupt.
  425. * We're using mask_on_assertion for MSI, so the device
  426. * automatically masks the interrupt when the interrupt is
  427. * generated. Later, when exiting polling, the interrupt
  428. * will be unmasked (see enic_poll).
  429. *
  430. * Also, the device uses the same PCIe Traffic Class (TC)
  431. * for Memory Write data and MSI, so there are no ordering
  432. * issues; the MSI will always arrive at the Root Complex
  433. * _after_ corresponding Memory Writes (i.e. descriptor
  434. * writes).
  435. */
  436. napi_schedule(&enic->napi);
  437. return IRQ_HANDLED;
  438. }
  439. static irqreturn_t enic_isr_msix_rq(int irq, void *data)
  440. {
  441. struct enic *enic = data;
  442. /* schedule NAPI polling for RQ cleanup */
  443. napi_schedule(&enic->napi);
  444. return IRQ_HANDLED;
  445. }
  446. static irqreturn_t enic_isr_msix_wq(int irq, void *data)
  447. {
  448. struct enic *enic = data;
  449. unsigned int wq_work_to_do = -1; /* no limit */
  450. unsigned int wq_work_done;
  451. wq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_WQ],
  452. wq_work_to_do, enic_wq_service, NULL);
  453. vnic_intr_return_credits(&enic->intr[ENIC_MSIX_WQ],
  454. wq_work_done,
  455. 1 /* unmask intr */,
  456. 1 /* reset intr timer */);
  457. return IRQ_HANDLED;
  458. }
  459. static irqreturn_t enic_isr_msix_err(int irq, void *data)
  460. {
  461. struct enic *enic = data;
  462. vnic_intr_return_all_credits(&enic->intr[ENIC_MSIX_ERR]);
  463. enic_log_q_error(enic);
  464. /* schedule recovery from WQ/RQ error */
  465. schedule_work(&enic->reset);
  466. return IRQ_HANDLED;
  467. }
  468. static irqreturn_t enic_isr_msix_notify(int irq, void *data)
  469. {
  470. struct enic *enic = data;
  471. vnic_intr_return_all_credits(&enic->intr[ENIC_MSIX_NOTIFY]);
  472. enic_notify_check(enic);
  473. return IRQ_HANDLED;
  474. }
  475. static inline void enic_queue_wq_skb_cont(struct enic *enic,
  476. struct vnic_wq *wq, struct sk_buff *skb,
  477. unsigned int len_left)
  478. {
  479. skb_frag_t *frag;
  480. /* Queue additional data fragments */
  481. for (frag = skb_shinfo(skb)->frags; len_left; frag++) {
  482. len_left -= frag->size;
  483. enic_queue_wq_desc_cont(wq, skb,
  484. pci_map_page(enic->pdev, frag->page,
  485. frag->page_offset, frag->size,
  486. PCI_DMA_TODEVICE),
  487. frag->size,
  488. (len_left == 0)); /* EOP? */
  489. }
  490. }
  491. static inline void enic_queue_wq_skb_vlan(struct enic *enic,
  492. struct vnic_wq *wq, struct sk_buff *skb,
  493. int vlan_tag_insert, unsigned int vlan_tag)
  494. {
  495. unsigned int head_len = skb_headlen(skb);
  496. unsigned int len_left = skb->len - head_len;
  497. int eop = (len_left == 0);
  498. /* Queue the main skb fragment. The fragments are no larger
  499. * than max MTU(9000)+ETH_HDR_LEN(14) bytes, which is less
  500. * than WQ_ENET_MAX_DESC_LEN length. So only one descriptor
  501. * per fragment is queued.
  502. */
  503. enic_queue_wq_desc(wq, skb,
  504. pci_map_single(enic->pdev, skb->data,
  505. head_len, PCI_DMA_TODEVICE),
  506. head_len,
  507. vlan_tag_insert, vlan_tag,
  508. eop);
  509. if (!eop)
  510. enic_queue_wq_skb_cont(enic, wq, skb, len_left);
  511. }
  512. static inline void enic_queue_wq_skb_csum_l4(struct enic *enic,
  513. struct vnic_wq *wq, struct sk_buff *skb,
  514. int vlan_tag_insert, unsigned int vlan_tag)
  515. {
  516. unsigned int head_len = skb_headlen(skb);
  517. unsigned int len_left = skb->len - head_len;
  518. unsigned int hdr_len = skb_transport_offset(skb);
  519. unsigned int csum_offset = hdr_len + skb->csum_offset;
  520. int eop = (len_left == 0);
  521. /* Queue the main skb fragment. The fragments are no larger
  522. * than max MTU(9000)+ETH_HDR_LEN(14) bytes, which is less
  523. * than WQ_ENET_MAX_DESC_LEN length. So only one descriptor
  524. * per fragment is queued.
  525. */
  526. enic_queue_wq_desc_csum_l4(wq, skb,
  527. pci_map_single(enic->pdev, skb->data,
  528. head_len, PCI_DMA_TODEVICE),
  529. head_len,
  530. csum_offset,
  531. hdr_len,
  532. vlan_tag_insert, vlan_tag,
  533. eop);
  534. if (!eop)
  535. enic_queue_wq_skb_cont(enic, wq, skb, len_left);
  536. }
  537. static inline void enic_queue_wq_skb_tso(struct enic *enic,
  538. struct vnic_wq *wq, struct sk_buff *skb, unsigned int mss,
  539. int vlan_tag_insert, unsigned int vlan_tag)
  540. {
  541. unsigned int frag_len_left = skb_headlen(skb);
  542. unsigned int len_left = skb->len - frag_len_left;
  543. unsigned int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  544. int eop = (len_left == 0);
  545. unsigned int len;
  546. dma_addr_t dma_addr;
  547. unsigned int offset = 0;
  548. skb_frag_t *frag;
  549. /* Preload TCP csum field with IP pseudo hdr calculated
  550. * with IP length set to zero. HW will later add in length
  551. * to each TCP segment resulting from the TSO.
  552. */
  553. if (skb->protocol == cpu_to_be16(ETH_P_IP)) {
  554. ip_hdr(skb)->check = 0;
  555. tcp_hdr(skb)->check = ~csum_tcpudp_magic(ip_hdr(skb)->saddr,
  556. ip_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
  557. } else if (skb->protocol == cpu_to_be16(ETH_P_IPV6)) {
  558. tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  559. &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
  560. }
  561. /* Queue WQ_ENET_MAX_DESC_LEN length descriptors
  562. * for the main skb fragment
  563. */
  564. while (frag_len_left) {
  565. len = min(frag_len_left, (unsigned int)WQ_ENET_MAX_DESC_LEN);
  566. dma_addr = pci_map_single(enic->pdev, skb->data + offset,
  567. len, PCI_DMA_TODEVICE);
  568. enic_queue_wq_desc_tso(wq, skb,
  569. dma_addr,
  570. len,
  571. mss, hdr_len,
  572. vlan_tag_insert, vlan_tag,
  573. eop && (len == frag_len_left));
  574. frag_len_left -= len;
  575. offset += len;
  576. }
  577. if (eop)
  578. return;
  579. /* Queue WQ_ENET_MAX_DESC_LEN length descriptors
  580. * for additional data fragments
  581. */
  582. for (frag = skb_shinfo(skb)->frags; len_left; frag++) {
  583. len_left -= frag->size;
  584. frag_len_left = frag->size;
  585. offset = frag->page_offset;
  586. while (frag_len_left) {
  587. len = min(frag_len_left,
  588. (unsigned int)WQ_ENET_MAX_DESC_LEN);
  589. dma_addr = pci_map_page(enic->pdev, frag->page,
  590. offset, len,
  591. PCI_DMA_TODEVICE);
  592. enic_queue_wq_desc_cont(wq, skb,
  593. dma_addr,
  594. len,
  595. (len_left == 0) &&
  596. (len == frag_len_left)); /* EOP? */
  597. frag_len_left -= len;
  598. offset += len;
  599. }
  600. }
  601. }
  602. static inline void enic_queue_wq_skb(struct enic *enic,
  603. struct vnic_wq *wq, struct sk_buff *skb)
  604. {
  605. unsigned int mss = skb_shinfo(skb)->gso_size;
  606. unsigned int vlan_tag = 0;
  607. int vlan_tag_insert = 0;
  608. if (enic->vlan_group && vlan_tx_tag_present(skb)) {
  609. /* VLAN tag from trunking driver */
  610. vlan_tag_insert = 1;
  611. vlan_tag = vlan_tx_tag_get(skb);
  612. }
  613. if (mss)
  614. enic_queue_wq_skb_tso(enic, wq, skb, mss,
  615. vlan_tag_insert, vlan_tag);
  616. else if (skb->ip_summed == CHECKSUM_PARTIAL)
  617. enic_queue_wq_skb_csum_l4(enic, wq, skb,
  618. vlan_tag_insert, vlan_tag);
  619. else
  620. enic_queue_wq_skb_vlan(enic, wq, skb,
  621. vlan_tag_insert, vlan_tag);
  622. }
  623. /* netif_tx_lock held, process context with BHs disabled, or BH */
  624. static netdev_tx_t enic_hard_start_xmit(struct sk_buff *skb,
  625. struct net_device *netdev)
  626. {
  627. struct enic *enic = netdev_priv(netdev);
  628. struct vnic_wq *wq = &enic->wq[0];
  629. unsigned long flags;
  630. if (skb->len <= 0) {
  631. dev_kfree_skb(skb);
  632. return NETDEV_TX_OK;
  633. }
  634. /* Non-TSO sends must fit within ENIC_NON_TSO_MAX_DESC descs,
  635. * which is very likely. In the off chance it's going to take
  636. * more than * ENIC_NON_TSO_MAX_DESC, linearize the skb.
  637. */
  638. if (skb_shinfo(skb)->gso_size == 0 &&
  639. skb_shinfo(skb)->nr_frags + 1 > ENIC_NON_TSO_MAX_DESC &&
  640. skb_linearize(skb)) {
  641. dev_kfree_skb(skb);
  642. return NETDEV_TX_OK;
  643. }
  644. spin_lock_irqsave(&enic->wq_lock[0], flags);
  645. if (vnic_wq_desc_avail(wq) <
  646. skb_shinfo(skb)->nr_frags + ENIC_DESC_MAX_SPLITS) {
  647. netif_stop_queue(netdev);
  648. /* This is a hard error, log it */
  649. printk(KERN_ERR PFX "%s: BUG! Tx ring full when "
  650. "queue awake!\n", netdev->name);
  651. spin_unlock_irqrestore(&enic->wq_lock[0], flags);
  652. return NETDEV_TX_BUSY;
  653. }
  654. enic_queue_wq_skb(enic, wq, skb);
  655. if (vnic_wq_desc_avail(wq) < MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS)
  656. netif_stop_queue(netdev);
  657. spin_unlock_irqrestore(&enic->wq_lock[0], flags);
  658. return NETDEV_TX_OK;
  659. }
  660. /* dev_base_lock rwlock held, nominally process context */
  661. static struct net_device_stats *enic_get_stats(struct net_device *netdev)
  662. {
  663. struct enic *enic = netdev_priv(netdev);
  664. struct net_device_stats *net_stats = &netdev->stats;
  665. struct vnic_stats *stats;
  666. spin_lock(&enic->devcmd_lock);
  667. vnic_dev_stats_dump(enic->vdev, &stats);
  668. spin_unlock(&enic->devcmd_lock);
  669. net_stats->tx_packets = stats->tx.tx_frames_ok;
  670. net_stats->tx_bytes = stats->tx.tx_bytes_ok;
  671. net_stats->tx_errors = stats->tx.tx_errors;
  672. net_stats->tx_dropped = stats->tx.tx_drops;
  673. net_stats->rx_packets = stats->rx.rx_frames_ok;
  674. net_stats->rx_bytes = stats->rx.rx_bytes_ok;
  675. net_stats->rx_errors = stats->rx.rx_errors;
  676. net_stats->multicast = stats->rx.rx_multicast_frames_ok;
  677. net_stats->rx_over_errors = enic->rq_truncated_pkts;
  678. net_stats->rx_crc_errors = enic->rq_bad_fcs;
  679. net_stats->rx_dropped = stats->rx.rx_no_bufs + stats->rx.rx_drop;
  680. return net_stats;
  681. }
  682. static void enic_reset_mcaddrs(struct enic *enic)
  683. {
  684. enic->mc_count = 0;
  685. }
  686. static int enic_set_mac_addr(struct net_device *netdev, char *addr)
  687. {
  688. struct enic *enic = netdev_priv(netdev);
  689. if (enic_is_dynamic(enic)) {
  690. if (!is_valid_ether_addr(addr) && !is_zero_ether_addr(addr))
  691. return -EADDRNOTAVAIL;
  692. } else {
  693. if (!is_valid_ether_addr(addr))
  694. return -EADDRNOTAVAIL;
  695. }
  696. memcpy(netdev->dev_addr, addr, netdev->addr_len);
  697. return 0;
  698. }
  699. static int enic_dev_add_station_addr(struct enic *enic)
  700. {
  701. int err = 0;
  702. if (is_valid_ether_addr(enic->netdev->dev_addr)) {
  703. spin_lock(&enic->devcmd_lock);
  704. err = vnic_dev_add_addr(enic->vdev, enic->netdev->dev_addr);
  705. spin_unlock(&enic->devcmd_lock);
  706. }
  707. return err;
  708. }
  709. static int enic_dev_del_station_addr(struct enic *enic)
  710. {
  711. int err = 0;
  712. if (is_valid_ether_addr(enic->netdev->dev_addr)) {
  713. spin_lock(&enic->devcmd_lock);
  714. err = vnic_dev_del_addr(enic->vdev, enic->netdev->dev_addr);
  715. spin_unlock(&enic->devcmd_lock);
  716. }
  717. return err;
  718. }
  719. static int enic_set_mac_address_dynamic(struct net_device *netdev, void *p)
  720. {
  721. struct enic *enic = netdev_priv(netdev);
  722. struct sockaddr *saddr = p;
  723. char *addr = saddr->sa_data;
  724. int err;
  725. if (netif_running(enic->netdev)) {
  726. err = enic_dev_del_station_addr(enic);
  727. if (err)
  728. return err;
  729. }
  730. err = enic_set_mac_addr(netdev, addr);
  731. if (err)
  732. return err;
  733. if (netif_running(enic->netdev)) {
  734. err = enic_dev_add_station_addr(enic);
  735. if (err)
  736. return err;
  737. }
  738. return err;
  739. }
  740. static int enic_set_mac_address(struct net_device *netdev, void *p)
  741. {
  742. return -EOPNOTSUPP;
  743. }
  744. /* netif_tx_lock held, BHs disabled */
  745. static void enic_set_multicast_list(struct net_device *netdev)
  746. {
  747. struct enic *enic = netdev_priv(netdev);
  748. struct netdev_hw_addr *ha;
  749. int directed = 1;
  750. int multicast = (netdev->flags & IFF_MULTICAST) ? 1 : 0;
  751. int broadcast = (netdev->flags & IFF_BROADCAST) ? 1 : 0;
  752. int promisc = (netdev->flags & IFF_PROMISC) ? 1 : 0;
  753. unsigned int mc_count = netdev_mc_count(netdev);
  754. int allmulti = (netdev->flags & IFF_ALLMULTI) ||
  755. mc_count > ENIC_MULTICAST_PERFECT_FILTERS;
  756. unsigned int flags = netdev->flags | (allmulti ? IFF_ALLMULTI : 0);
  757. u8 mc_addr[ENIC_MULTICAST_PERFECT_FILTERS][ETH_ALEN];
  758. unsigned int i, j;
  759. if (mc_count > ENIC_MULTICAST_PERFECT_FILTERS)
  760. mc_count = ENIC_MULTICAST_PERFECT_FILTERS;
  761. spin_lock(&enic->devcmd_lock);
  762. if (enic->flags != flags) {
  763. enic->flags = flags;
  764. vnic_dev_packet_filter(enic->vdev, directed,
  765. multicast, broadcast, promisc, allmulti);
  766. }
  767. /* Is there an easier way? Trying to minimize to
  768. * calls to add/del multicast addrs. We keep the
  769. * addrs from the last call in enic->mc_addr and
  770. * look for changes to add/del.
  771. */
  772. i = 0;
  773. netdev_for_each_mc_addr(ha, netdev) {
  774. if (i == mc_count)
  775. break;
  776. memcpy(mc_addr[i++], ha->addr, ETH_ALEN);
  777. }
  778. for (i = 0; i < enic->mc_count; i++) {
  779. for (j = 0; j < mc_count; j++)
  780. if (compare_ether_addr(enic->mc_addr[i],
  781. mc_addr[j]) == 0)
  782. break;
  783. if (j == mc_count)
  784. enic_del_multicast_addr(enic, enic->mc_addr[i]);
  785. }
  786. for (i = 0; i < mc_count; i++) {
  787. for (j = 0; j < enic->mc_count; j++)
  788. if (compare_ether_addr(mc_addr[i],
  789. enic->mc_addr[j]) == 0)
  790. break;
  791. if (j == enic->mc_count)
  792. enic_add_multicast_addr(enic, mc_addr[i]);
  793. }
  794. /* Save the list to compare against next time
  795. */
  796. for (i = 0; i < mc_count; i++)
  797. memcpy(enic->mc_addr[i], mc_addr[i], ETH_ALEN);
  798. enic->mc_count = mc_count;
  799. spin_unlock(&enic->devcmd_lock);
  800. }
  801. /* rtnl lock is held */
  802. static void enic_vlan_rx_register(struct net_device *netdev,
  803. struct vlan_group *vlan_group)
  804. {
  805. struct enic *enic = netdev_priv(netdev);
  806. enic->vlan_group = vlan_group;
  807. }
  808. /* rtnl lock is held */
  809. static void enic_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
  810. {
  811. struct enic *enic = netdev_priv(netdev);
  812. spin_lock(&enic->devcmd_lock);
  813. enic_add_vlan(enic, vid);
  814. spin_unlock(&enic->devcmd_lock);
  815. }
  816. /* rtnl lock is held */
  817. static void enic_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
  818. {
  819. struct enic *enic = netdev_priv(netdev);
  820. spin_lock(&enic->devcmd_lock);
  821. enic_del_vlan(enic, vid);
  822. spin_unlock(&enic->devcmd_lock);
  823. }
  824. /* netif_tx_lock held, BHs disabled */
  825. static void enic_tx_timeout(struct net_device *netdev)
  826. {
  827. struct enic *enic = netdev_priv(netdev);
  828. schedule_work(&enic->reset);
  829. }
  830. static int enic_vnic_dev_deinit(struct enic *enic)
  831. {
  832. int err;
  833. spin_lock(&enic->devcmd_lock);
  834. err = vnic_dev_deinit(enic->vdev);
  835. spin_unlock(&enic->devcmd_lock);
  836. return err;
  837. }
  838. static int enic_dev_init_prov(struct enic *enic, struct vic_provinfo *vp)
  839. {
  840. int err;
  841. spin_lock(&enic->devcmd_lock);
  842. err = vnic_dev_init_prov(enic->vdev,
  843. (u8 *)vp, vic_provinfo_size(vp));
  844. spin_unlock(&enic->devcmd_lock);
  845. return err;
  846. }
  847. static int enic_dev_init_done(struct enic *enic, int *done, int *error)
  848. {
  849. int err;
  850. spin_lock(&enic->devcmd_lock);
  851. err = vnic_dev_init_done(enic->vdev, done, error);
  852. spin_unlock(&enic->devcmd_lock);
  853. return err;
  854. }
  855. static int enic_set_port_profile(struct enic *enic, u8 *mac)
  856. {
  857. struct vic_provinfo *vp;
  858. u8 oui[3] = VIC_PROVINFO_CISCO_OUI;
  859. u8 *uuid;
  860. char uuid_str[38];
  861. static char *uuid_fmt = "%02X%02X%02X%02X-%02X%02X-%02X%02X-"
  862. "%02X%02X-%02X%02X%02X%02X%0X%02X";
  863. int err;
  864. err = enic_vnic_dev_deinit(enic);
  865. if (err)
  866. return err;
  867. switch (enic->pp.request) {
  868. case PORT_REQUEST_ASSOCIATE:
  869. if (!(enic->pp.set & ENIC_SET_NAME) || !strlen(enic->pp.name))
  870. return -EINVAL;
  871. if (!is_valid_ether_addr(mac))
  872. return -EADDRNOTAVAIL;
  873. vp = vic_provinfo_alloc(GFP_KERNEL, oui,
  874. VIC_PROVINFO_LINUX_TYPE);
  875. if (!vp)
  876. return -ENOMEM;
  877. vic_provinfo_add_tlv(vp,
  878. VIC_LINUX_PROV_TLV_PORT_PROFILE_NAME_STR,
  879. strlen(enic->pp.name) + 1, enic->pp.name);
  880. vic_provinfo_add_tlv(vp,
  881. VIC_LINUX_PROV_TLV_CLIENT_MAC_ADDR,
  882. ETH_ALEN, mac);
  883. if (enic->pp.set & ENIC_SET_INSTANCE) {
  884. uuid = enic->pp.instance_uuid;
  885. sprintf(uuid_str, uuid_fmt,
  886. uuid[0], uuid[1], uuid[2], uuid[3],
  887. uuid[4], uuid[5], uuid[6], uuid[7],
  888. uuid[8], uuid[9], uuid[10], uuid[11],
  889. uuid[12], uuid[13], uuid[14], uuid[15]);
  890. vic_provinfo_add_tlv(vp,
  891. VIC_LINUX_PROV_TLV_CLIENT_UUID_STR,
  892. sizeof(uuid_str), uuid_str);
  893. }
  894. if (enic->pp.set & ENIC_SET_HOST) {
  895. uuid = enic->pp.host_uuid;
  896. sprintf(uuid_str, uuid_fmt,
  897. uuid[0], uuid[1], uuid[2], uuid[3],
  898. uuid[4], uuid[5], uuid[6], uuid[7],
  899. uuid[8], uuid[9], uuid[10], uuid[11],
  900. uuid[12], uuid[13], uuid[14], uuid[15]);
  901. vic_provinfo_add_tlv(vp,
  902. VIC_LINUX_PROV_TLV_HOST_UUID_STR,
  903. sizeof(uuid_str), uuid_str);
  904. }
  905. err = enic_dev_init_prov(enic, vp);
  906. vic_provinfo_free(vp);
  907. if (err)
  908. return err;
  909. break;
  910. case PORT_REQUEST_DISASSOCIATE:
  911. break;
  912. default:
  913. return -EINVAL;
  914. }
  915. enic->pp.set |= ENIC_SET_APPLIED;
  916. return 0;
  917. }
  918. static int enic_set_vf_port(struct net_device *netdev, int vf,
  919. struct nlattr *port[])
  920. {
  921. struct enic *enic = netdev_priv(netdev);
  922. memset(&enic->pp, 0, sizeof(enic->pp));
  923. if (port[IFLA_PORT_REQUEST]) {
  924. enic->pp.set |= ENIC_SET_REQUEST;
  925. enic->pp.request = nla_get_u8(port[IFLA_PORT_REQUEST]);
  926. }
  927. if (port[IFLA_PORT_PROFILE]) {
  928. enic->pp.set |= ENIC_SET_NAME;
  929. memcpy(enic->pp.name, nla_data(port[IFLA_PORT_PROFILE]),
  930. PORT_PROFILE_MAX);
  931. }
  932. if (port[IFLA_PORT_INSTANCE_UUID]) {
  933. enic->pp.set |= ENIC_SET_INSTANCE;
  934. memcpy(enic->pp.instance_uuid,
  935. nla_data(port[IFLA_PORT_INSTANCE_UUID]), PORT_UUID_MAX);
  936. }
  937. if (port[IFLA_PORT_HOST_UUID]) {
  938. enic->pp.set |= ENIC_SET_HOST;
  939. memcpy(enic->pp.host_uuid,
  940. nla_data(port[IFLA_PORT_HOST_UUID]), PORT_UUID_MAX);
  941. }
  942. /* don't support VFs, yet */
  943. if (vf != PORT_SELF_VF)
  944. return -EOPNOTSUPP;
  945. if (!(enic->pp.set & ENIC_SET_REQUEST))
  946. return -EOPNOTSUPP;
  947. if (enic->pp.request == PORT_REQUEST_ASSOCIATE) {
  948. /* If the interface mac addr hasn't been assigned,
  949. * assign a random mac addr before setting port-
  950. * profile.
  951. */
  952. if (is_zero_ether_addr(netdev->dev_addr))
  953. random_ether_addr(netdev->dev_addr);
  954. }
  955. return enic_set_port_profile(enic, netdev->dev_addr);
  956. }
  957. static int enic_get_vf_port(struct net_device *netdev, int vf,
  958. struct sk_buff *skb)
  959. {
  960. struct enic *enic = netdev_priv(netdev);
  961. int err, error, done;
  962. u16 response = PORT_PROFILE_RESPONSE_SUCCESS;
  963. if (!(enic->pp.set & ENIC_SET_APPLIED))
  964. return -ENODATA;
  965. err = enic_dev_init_done(enic, &done, &error);
  966. if (err)
  967. error = err;
  968. switch (error) {
  969. case ERR_SUCCESS:
  970. if (!done)
  971. response = PORT_PROFILE_RESPONSE_INPROGRESS;
  972. break;
  973. case ERR_EINVAL:
  974. response = PORT_PROFILE_RESPONSE_INVALID;
  975. break;
  976. case ERR_EBADSTATE:
  977. response = PORT_PROFILE_RESPONSE_BADSTATE;
  978. break;
  979. case ERR_ENOMEM:
  980. response = PORT_PROFILE_RESPONSE_INSUFFICIENT_RESOURCES;
  981. break;
  982. default:
  983. response = PORT_PROFILE_RESPONSE_ERROR;
  984. break;
  985. }
  986. NLA_PUT_U16(skb, IFLA_PORT_REQUEST, enic->pp.request);
  987. NLA_PUT_U16(skb, IFLA_PORT_RESPONSE, response);
  988. if (enic->pp.set & ENIC_SET_NAME)
  989. NLA_PUT(skb, IFLA_PORT_PROFILE, PORT_PROFILE_MAX,
  990. enic->pp.name);
  991. if (enic->pp.set & ENIC_SET_INSTANCE)
  992. NLA_PUT(skb, IFLA_PORT_INSTANCE_UUID, PORT_UUID_MAX,
  993. enic->pp.instance_uuid);
  994. if (enic->pp.set & ENIC_SET_HOST)
  995. NLA_PUT(skb, IFLA_PORT_HOST_UUID, PORT_UUID_MAX,
  996. enic->pp.host_uuid);
  997. return 0;
  998. nla_put_failure:
  999. return -EMSGSIZE;
  1000. }
  1001. static void enic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf)
  1002. {
  1003. struct enic *enic = vnic_dev_priv(rq->vdev);
  1004. if (!buf->os_buf)
  1005. return;
  1006. pci_unmap_single(enic->pdev, buf->dma_addr,
  1007. buf->len, PCI_DMA_FROMDEVICE);
  1008. dev_kfree_skb_any(buf->os_buf);
  1009. }
  1010. static int enic_rq_alloc_buf(struct vnic_rq *rq)
  1011. {
  1012. struct enic *enic = vnic_dev_priv(rq->vdev);
  1013. struct net_device *netdev = enic->netdev;
  1014. struct sk_buff *skb;
  1015. unsigned int len = netdev->mtu + ETH_HLEN;
  1016. unsigned int os_buf_index = 0;
  1017. dma_addr_t dma_addr;
  1018. skb = netdev_alloc_skb_ip_align(netdev, len);
  1019. if (!skb)
  1020. return -ENOMEM;
  1021. dma_addr = pci_map_single(enic->pdev, skb->data,
  1022. len, PCI_DMA_FROMDEVICE);
  1023. enic_queue_rq_desc(rq, skb, os_buf_index,
  1024. dma_addr, len);
  1025. return 0;
  1026. }
  1027. static int enic_rq_alloc_buf_a1(struct vnic_rq *rq)
  1028. {
  1029. struct rq_enet_desc *desc = vnic_rq_next_desc(rq);
  1030. if (vnic_rq_posting_soon(rq)) {
  1031. /* SW workaround for A0 HW erratum: if we're just about
  1032. * to write posted_index, insert a dummy desc
  1033. * of type resvd
  1034. */
  1035. rq_enet_desc_enc(desc, 0, RQ_ENET_TYPE_RESV2, 0);
  1036. vnic_rq_post(rq, 0, 0, 0, 0);
  1037. } else {
  1038. return enic_rq_alloc_buf(rq);
  1039. }
  1040. return 0;
  1041. }
  1042. static int enic_set_rq_alloc_buf(struct enic *enic)
  1043. {
  1044. enum vnic_dev_hw_version hw_ver;
  1045. int err;
  1046. err = vnic_dev_hw_version(enic->vdev, &hw_ver);
  1047. if (err)
  1048. return err;
  1049. switch (hw_ver) {
  1050. case VNIC_DEV_HW_VER_A1:
  1051. enic->rq_alloc_buf = enic_rq_alloc_buf_a1;
  1052. break;
  1053. case VNIC_DEV_HW_VER_A2:
  1054. case VNIC_DEV_HW_VER_UNKNOWN:
  1055. enic->rq_alloc_buf = enic_rq_alloc_buf;
  1056. break;
  1057. default:
  1058. return -ENODEV;
  1059. }
  1060. return 0;
  1061. }
  1062. static int enic_get_skb_header(struct sk_buff *skb, void **iphdr,
  1063. void **tcph, u64 *hdr_flags, void *priv)
  1064. {
  1065. struct cq_enet_rq_desc *cq_desc = priv;
  1066. unsigned int ip_len;
  1067. struct iphdr *iph;
  1068. u8 type, color, eop, sop, ingress_port, vlan_stripped;
  1069. u8 fcoe, fcoe_sof, fcoe_fc_crc_ok, fcoe_enc_error, fcoe_eof;
  1070. u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok;
  1071. u8 ipv6, ipv4, ipv4_fragment, fcs_ok, rss_type, csum_not_calc;
  1072. u8 packet_error;
  1073. u16 q_number, completed_index, bytes_written, vlan, checksum;
  1074. u32 rss_hash;
  1075. cq_enet_rq_desc_dec(cq_desc,
  1076. &type, &color, &q_number, &completed_index,
  1077. &ingress_port, &fcoe, &eop, &sop, &rss_type,
  1078. &csum_not_calc, &rss_hash, &bytes_written,
  1079. &packet_error, &vlan_stripped, &vlan, &checksum,
  1080. &fcoe_sof, &fcoe_fc_crc_ok, &fcoe_enc_error,
  1081. &fcoe_eof, &tcp_udp_csum_ok, &udp, &tcp,
  1082. &ipv4_csum_ok, &ipv6, &ipv4, &ipv4_fragment,
  1083. &fcs_ok);
  1084. if (!(ipv4 && tcp && !ipv4_fragment))
  1085. return -1;
  1086. skb_reset_network_header(skb);
  1087. iph = ip_hdr(skb);
  1088. ip_len = ip_hdrlen(skb);
  1089. skb_set_transport_header(skb, ip_len);
  1090. /* check if ip header and tcp header are complete */
  1091. if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
  1092. return -1;
  1093. *hdr_flags = LRO_IPV4 | LRO_TCP;
  1094. *tcph = tcp_hdr(skb);
  1095. *iphdr = iph;
  1096. return 0;
  1097. }
  1098. static void enic_rq_indicate_buf(struct vnic_rq *rq,
  1099. struct cq_desc *cq_desc, struct vnic_rq_buf *buf,
  1100. int skipped, void *opaque)
  1101. {
  1102. struct enic *enic = vnic_dev_priv(rq->vdev);
  1103. struct net_device *netdev = enic->netdev;
  1104. struct sk_buff *skb;
  1105. u8 type, color, eop, sop, ingress_port, vlan_stripped;
  1106. u8 fcoe, fcoe_sof, fcoe_fc_crc_ok, fcoe_enc_error, fcoe_eof;
  1107. u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok;
  1108. u8 ipv6, ipv4, ipv4_fragment, fcs_ok, rss_type, csum_not_calc;
  1109. u8 packet_error;
  1110. u16 q_number, completed_index, bytes_written, vlan, checksum;
  1111. u32 rss_hash;
  1112. if (skipped)
  1113. return;
  1114. skb = buf->os_buf;
  1115. prefetch(skb->data - NET_IP_ALIGN);
  1116. pci_unmap_single(enic->pdev, buf->dma_addr,
  1117. buf->len, PCI_DMA_FROMDEVICE);
  1118. cq_enet_rq_desc_dec((struct cq_enet_rq_desc *)cq_desc,
  1119. &type, &color, &q_number, &completed_index,
  1120. &ingress_port, &fcoe, &eop, &sop, &rss_type,
  1121. &csum_not_calc, &rss_hash, &bytes_written,
  1122. &packet_error, &vlan_stripped, &vlan, &checksum,
  1123. &fcoe_sof, &fcoe_fc_crc_ok, &fcoe_enc_error,
  1124. &fcoe_eof, &tcp_udp_csum_ok, &udp, &tcp,
  1125. &ipv4_csum_ok, &ipv6, &ipv4, &ipv4_fragment,
  1126. &fcs_ok);
  1127. if (packet_error) {
  1128. if (!fcs_ok) {
  1129. if (bytes_written > 0)
  1130. enic->rq_bad_fcs++;
  1131. else if (bytes_written == 0)
  1132. enic->rq_truncated_pkts++;
  1133. }
  1134. dev_kfree_skb_any(skb);
  1135. return;
  1136. }
  1137. if (eop && bytes_written > 0) {
  1138. /* Good receive
  1139. */
  1140. skb_put(skb, bytes_written);
  1141. skb->protocol = eth_type_trans(skb, netdev);
  1142. if (enic->csum_rx_enabled && !csum_not_calc) {
  1143. skb->csum = htons(checksum);
  1144. skb->ip_summed = CHECKSUM_COMPLETE;
  1145. }
  1146. skb->dev = netdev;
  1147. if (enic->vlan_group && vlan_stripped) {
  1148. if ((netdev->features & NETIF_F_LRO) && ipv4)
  1149. lro_vlan_hwaccel_receive_skb(&enic->lro_mgr,
  1150. skb, enic->vlan_group,
  1151. vlan, cq_desc);
  1152. else
  1153. vlan_hwaccel_receive_skb(skb,
  1154. enic->vlan_group, vlan);
  1155. } else {
  1156. if ((netdev->features & NETIF_F_LRO) && ipv4)
  1157. lro_receive_skb(&enic->lro_mgr, skb, cq_desc);
  1158. else
  1159. netif_receive_skb(skb);
  1160. }
  1161. } else {
  1162. /* Buffer overflow
  1163. */
  1164. dev_kfree_skb_any(skb);
  1165. }
  1166. }
  1167. static int enic_rq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
  1168. u8 type, u16 q_number, u16 completed_index, void *opaque)
  1169. {
  1170. struct enic *enic = vnic_dev_priv(vdev);
  1171. vnic_rq_service(&enic->rq[q_number], cq_desc,
  1172. completed_index, VNIC_RQ_RETURN_DESC,
  1173. enic_rq_indicate_buf, opaque);
  1174. return 0;
  1175. }
  1176. static int enic_poll(struct napi_struct *napi, int budget)
  1177. {
  1178. struct enic *enic = container_of(napi, struct enic, napi);
  1179. struct net_device *netdev = enic->netdev;
  1180. unsigned int rq_work_to_do = budget;
  1181. unsigned int wq_work_to_do = -1; /* no limit */
  1182. unsigned int work_done, rq_work_done, wq_work_done;
  1183. int err;
  1184. /* Service RQ (first) and WQ
  1185. */
  1186. rq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_RQ],
  1187. rq_work_to_do, enic_rq_service, NULL);
  1188. wq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_WQ],
  1189. wq_work_to_do, enic_wq_service, NULL);
  1190. /* Accumulate intr event credits for this polling
  1191. * cycle. An intr event is the completion of a
  1192. * a WQ or RQ packet.
  1193. */
  1194. work_done = rq_work_done + wq_work_done;
  1195. if (work_done > 0)
  1196. vnic_intr_return_credits(&enic->intr[ENIC_INTX_WQ_RQ],
  1197. work_done,
  1198. 0 /* don't unmask intr */,
  1199. 0 /* don't reset intr timer */);
  1200. err = vnic_rq_fill(&enic->rq[0], enic->rq_alloc_buf);
  1201. /* Buffer allocation failed. Stay in polling
  1202. * mode so we can try to fill the ring again.
  1203. */
  1204. if (err)
  1205. rq_work_done = rq_work_to_do;
  1206. if (rq_work_done < rq_work_to_do) {
  1207. /* Some work done, but not enough to stay in polling,
  1208. * flush all LROs and exit polling
  1209. */
  1210. if (netdev->features & NETIF_F_LRO)
  1211. lro_flush_all(&enic->lro_mgr);
  1212. napi_complete(napi);
  1213. vnic_intr_unmask(&enic->intr[ENIC_INTX_WQ_RQ]);
  1214. }
  1215. return rq_work_done;
  1216. }
  1217. static int enic_poll_msix(struct napi_struct *napi, int budget)
  1218. {
  1219. struct enic *enic = container_of(napi, struct enic, napi);
  1220. struct net_device *netdev = enic->netdev;
  1221. unsigned int work_to_do = budget;
  1222. unsigned int work_done;
  1223. int err;
  1224. /* Service RQ
  1225. */
  1226. work_done = vnic_cq_service(&enic->cq[ENIC_CQ_RQ],
  1227. work_to_do, enic_rq_service, NULL);
  1228. /* Return intr event credits for this polling
  1229. * cycle. An intr event is the completion of a
  1230. * RQ packet.
  1231. */
  1232. if (work_done > 0)
  1233. vnic_intr_return_credits(&enic->intr[ENIC_MSIX_RQ],
  1234. work_done,
  1235. 0 /* don't unmask intr */,
  1236. 0 /* don't reset intr timer */);
  1237. err = vnic_rq_fill(&enic->rq[0], enic->rq_alloc_buf);
  1238. /* Buffer allocation failed. Stay in polling mode
  1239. * so we can try to fill the ring again.
  1240. */
  1241. if (err)
  1242. work_done = work_to_do;
  1243. if (work_done < work_to_do) {
  1244. /* Some work done, but not enough to stay in polling,
  1245. * flush all LROs and exit polling
  1246. */
  1247. if (netdev->features & NETIF_F_LRO)
  1248. lro_flush_all(&enic->lro_mgr);
  1249. napi_complete(napi);
  1250. vnic_intr_unmask(&enic->intr[ENIC_MSIX_RQ]);
  1251. }
  1252. return work_done;
  1253. }
  1254. static void enic_notify_timer(unsigned long data)
  1255. {
  1256. struct enic *enic = (struct enic *)data;
  1257. enic_notify_check(enic);
  1258. mod_timer(&enic->notify_timer,
  1259. round_jiffies(jiffies + ENIC_NOTIFY_TIMER_PERIOD));
  1260. }
  1261. static void enic_free_intr(struct enic *enic)
  1262. {
  1263. struct net_device *netdev = enic->netdev;
  1264. unsigned int i;
  1265. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  1266. case VNIC_DEV_INTR_MODE_INTX:
  1267. free_irq(enic->pdev->irq, netdev);
  1268. break;
  1269. case VNIC_DEV_INTR_MODE_MSI:
  1270. free_irq(enic->pdev->irq, enic);
  1271. break;
  1272. case VNIC_DEV_INTR_MODE_MSIX:
  1273. for (i = 0; i < ARRAY_SIZE(enic->msix); i++)
  1274. if (enic->msix[i].requested)
  1275. free_irq(enic->msix_entry[i].vector,
  1276. enic->msix[i].devid);
  1277. break;
  1278. default:
  1279. break;
  1280. }
  1281. }
  1282. static int enic_request_intr(struct enic *enic)
  1283. {
  1284. struct net_device *netdev = enic->netdev;
  1285. unsigned int i;
  1286. int err = 0;
  1287. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  1288. case VNIC_DEV_INTR_MODE_INTX:
  1289. err = request_irq(enic->pdev->irq, enic_isr_legacy,
  1290. IRQF_SHARED, netdev->name, netdev);
  1291. break;
  1292. case VNIC_DEV_INTR_MODE_MSI:
  1293. err = request_irq(enic->pdev->irq, enic_isr_msi,
  1294. 0, netdev->name, enic);
  1295. break;
  1296. case VNIC_DEV_INTR_MODE_MSIX:
  1297. sprintf(enic->msix[ENIC_MSIX_RQ].devname,
  1298. "%.11s-rx-0", netdev->name);
  1299. enic->msix[ENIC_MSIX_RQ].isr = enic_isr_msix_rq;
  1300. enic->msix[ENIC_MSIX_RQ].devid = enic;
  1301. sprintf(enic->msix[ENIC_MSIX_WQ].devname,
  1302. "%.11s-tx-0", netdev->name);
  1303. enic->msix[ENIC_MSIX_WQ].isr = enic_isr_msix_wq;
  1304. enic->msix[ENIC_MSIX_WQ].devid = enic;
  1305. sprintf(enic->msix[ENIC_MSIX_ERR].devname,
  1306. "%.11s-err", netdev->name);
  1307. enic->msix[ENIC_MSIX_ERR].isr = enic_isr_msix_err;
  1308. enic->msix[ENIC_MSIX_ERR].devid = enic;
  1309. sprintf(enic->msix[ENIC_MSIX_NOTIFY].devname,
  1310. "%.11s-notify", netdev->name);
  1311. enic->msix[ENIC_MSIX_NOTIFY].isr = enic_isr_msix_notify;
  1312. enic->msix[ENIC_MSIX_NOTIFY].devid = enic;
  1313. for (i = 0; i < ARRAY_SIZE(enic->msix); i++) {
  1314. err = request_irq(enic->msix_entry[i].vector,
  1315. enic->msix[i].isr, 0,
  1316. enic->msix[i].devname,
  1317. enic->msix[i].devid);
  1318. if (err) {
  1319. enic_free_intr(enic);
  1320. break;
  1321. }
  1322. enic->msix[i].requested = 1;
  1323. }
  1324. break;
  1325. default:
  1326. break;
  1327. }
  1328. return err;
  1329. }
  1330. static void enic_synchronize_irqs(struct enic *enic)
  1331. {
  1332. unsigned int i;
  1333. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  1334. case VNIC_DEV_INTR_MODE_INTX:
  1335. case VNIC_DEV_INTR_MODE_MSI:
  1336. synchronize_irq(enic->pdev->irq);
  1337. break;
  1338. case VNIC_DEV_INTR_MODE_MSIX:
  1339. for (i = 0; i < enic->intr_count; i++)
  1340. synchronize_irq(enic->msix_entry[i].vector);
  1341. break;
  1342. default:
  1343. break;
  1344. }
  1345. }
  1346. static int enic_notify_set(struct enic *enic)
  1347. {
  1348. int err;
  1349. spin_lock(&enic->devcmd_lock);
  1350. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  1351. case VNIC_DEV_INTR_MODE_INTX:
  1352. err = vnic_dev_notify_set(enic->vdev, ENIC_INTX_NOTIFY);
  1353. break;
  1354. case VNIC_DEV_INTR_MODE_MSIX:
  1355. err = vnic_dev_notify_set(enic->vdev, ENIC_MSIX_NOTIFY);
  1356. break;
  1357. default:
  1358. err = vnic_dev_notify_set(enic->vdev, -1 /* no intr */);
  1359. break;
  1360. }
  1361. spin_unlock(&enic->devcmd_lock);
  1362. return err;
  1363. }
  1364. static void enic_notify_timer_start(struct enic *enic)
  1365. {
  1366. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  1367. case VNIC_DEV_INTR_MODE_MSI:
  1368. mod_timer(&enic->notify_timer, jiffies);
  1369. break;
  1370. default:
  1371. /* Using intr for notification for INTx/MSI-X */
  1372. break;
  1373. };
  1374. }
  1375. /* rtnl lock is held, process context */
  1376. static int enic_open(struct net_device *netdev)
  1377. {
  1378. struct enic *enic = netdev_priv(netdev);
  1379. unsigned int i;
  1380. int err;
  1381. err = enic_request_intr(enic);
  1382. if (err) {
  1383. printk(KERN_ERR PFX "%s: Unable to request irq.\n",
  1384. netdev->name);
  1385. return err;
  1386. }
  1387. err = enic_notify_set(enic);
  1388. if (err) {
  1389. printk(KERN_ERR PFX
  1390. "%s: Failed to alloc notify buffer, aborting.\n",
  1391. netdev->name);
  1392. goto err_out_free_intr;
  1393. }
  1394. for (i = 0; i < enic->rq_count; i++) {
  1395. vnic_rq_fill(&enic->rq[i], enic->rq_alloc_buf);
  1396. /* Need at least one buffer on ring to get going */
  1397. if (vnic_rq_desc_used(&enic->rq[i]) == 0) {
  1398. printk(KERN_ERR PFX
  1399. "%s: Unable to alloc receive buffers.\n",
  1400. netdev->name);
  1401. err = -ENOMEM;
  1402. goto err_out_notify_unset;
  1403. }
  1404. }
  1405. for (i = 0; i < enic->wq_count; i++)
  1406. vnic_wq_enable(&enic->wq[i]);
  1407. for (i = 0; i < enic->rq_count; i++)
  1408. vnic_rq_enable(&enic->rq[i]);
  1409. enic_dev_add_station_addr(enic);
  1410. enic_set_multicast_list(netdev);
  1411. netif_wake_queue(netdev);
  1412. napi_enable(&enic->napi);
  1413. spin_lock(&enic->devcmd_lock);
  1414. vnic_dev_enable(enic->vdev);
  1415. spin_unlock(&enic->devcmd_lock);
  1416. for (i = 0; i < enic->intr_count; i++)
  1417. vnic_intr_unmask(&enic->intr[i]);
  1418. enic_notify_timer_start(enic);
  1419. return 0;
  1420. err_out_notify_unset:
  1421. spin_lock(&enic->devcmd_lock);
  1422. vnic_dev_notify_unset(enic->vdev);
  1423. spin_unlock(&enic->devcmd_lock);
  1424. err_out_free_intr:
  1425. enic_free_intr(enic);
  1426. return err;
  1427. }
  1428. /* rtnl lock is held, process context */
  1429. static int enic_stop(struct net_device *netdev)
  1430. {
  1431. struct enic *enic = netdev_priv(netdev);
  1432. unsigned int i;
  1433. int err;
  1434. for (i = 0; i < enic->intr_count; i++)
  1435. vnic_intr_mask(&enic->intr[i]);
  1436. enic_synchronize_irqs(enic);
  1437. del_timer_sync(&enic->notify_timer);
  1438. spin_lock(&enic->devcmd_lock);
  1439. vnic_dev_disable(enic->vdev);
  1440. spin_unlock(&enic->devcmd_lock);
  1441. napi_disable(&enic->napi);
  1442. netif_carrier_off(netdev);
  1443. netif_tx_disable(netdev);
  1444. enic_dev_del_station_addr(enic);
  1445. for (i = 0; i < enic->wq_count; i++) {
  1446. err = vnic_wq_disable(&enic->wq[i]);
  1447. if (err)
  1448. return err;
  1449. }
  1450. for (i = 0; i < enic->rq_count; i++) {
  1451. err = vnic_rq_disable(&enic->rq[i]);
  1452. if (err)
  1453. return err;
  1454. }
  1455. spin_lock(&enic->devcmd_lock);
  1456. vnic_dev_notify_unset(enic->vdev);
  1457. spin_unlock(&enic->devcmd_lock);
  1458. enic_free_intr(enic);
  1459. for (i = 0; i < enic->wq_count; i++)
  1460. vnic_wq_clean(&enic->wq[i], enic_free_wq_buf);
  1461. for (i = 0; i < enic->rq_count; i++)
  1462. vnic_rq_clean(&enic->rq[i], enic_free_rq_buf);
  1463. for (i = 0; i < enic->cq_count; i++)
  1464. vnic_cq_clean(&enic->cq[i]);
  1465. for (i = 0; i < enic->intr_count; i++)
  1466. vnic_intr_clean(&enic->intr[i]);
  1467. return 0;
  1468. }
  1469. static int enic_change_mtu(struct net_device *netdev, int new_mtu)
  1470. {
  1471. struct enic *enic = netdev_priv(netdev);
  1472. int running = netif_running(netdev);
  1473. if (new_mtu < ENIC_MIN_MTU || new_mtu > ENIC_MAX_MTU)
  1474. return -EINVAL;
  1475. if (running)
  1476. enic_stop(netdev);
  1477. netdev->mtu = new_mtu;
  1478. if (netdev->mtu > enic->port_mtu)
  1479. printk(KERN_WARNING PFX
  1480. "%s: interface MTU (%d) set higher "
  1481. "than port MTU (%d)\n",
  1482. netdev->name, netdev->mtu, enic->port_mtu);
  1483. if (running)
  1484. enic_open(netdev);
  1485. return 0;
  1486. }
  1487. #ifdef CONFIG_NET_POLL_CONTROLLER
  1488. static void enic_poll_controller(struct net_device *netdev)
  1489. {
  1490. struct enic *enic = netdev_priv(netdev);
  1491. struct vnic_dev *vdev = enic->vdev;
  1492. switch (vnic_dev_get_intr_mode(vdev)) {
  1493. case VNIC_DEV_INTR_MODE_MSIX:
  1494. enic_isr_msix_rq(enic->pdev->irq, enic);
  1495. enic_isr_msix_wq(enic->pdev->irq, enic);
  1496. break;
  1497. case VNIC_DEV_INTR_MODE_MSI:
  1498. enic_isr_msi(enic->pdev->irq, enic);
  1499. break;
  1500. case VNIC_DEV_INTR_MODE_INTX:
  1501. enic_isr_legacy(enic->pdev->irq, netdev);
  1502. break;
  1503. default:
  1504. break;
  1505. }
  1506. }
  1507. #endif
  1508. static int enic_dev_wait(struct vnic_dev *vdev,
  1509. int (*start)(struct vnic_dev *, int),
  1510. int (*finished)(struct vnic_dev *, int *),
  1511. int arg)
  1512. {
  1513. unsigned long time;
  1514. int done;
  1515. int err;
  1516. BUG_ON(in_interrupt());
  1517. err = start(vdev, arg);
  1518. if (err)
  1519. return err;
  1520. /* Wait for func to complete...2 seconds max
  1521. */
  1522. time = jiffies + (HZ * 2);
  1523. do {
  1524. err = finished(vdev, &done);
  1525. if (err)
  1526. return err;
  1527. if (done)
  1528. return 0;
  1529. schedule_timeout_uninterruptible(HZ / 10);
  1530. } while (time_after(time, jiffies));
  1531. return -ETIMEDOUT;
  1532. }
  1533. static int enic_dev_open(struct enic *enic)
  1534. {
  1535. int err;
  1536. err = enic_dev_wait(enic->vdev, vnic_dev_open,
  1537. vnic_dev_open_done, 0);
  1538. if (err)
  1539. printk(KERN_ERR PFX
  1540. "vNIC device open failed, err %d.\n", err);
  1541. return err;
  1542. }
  1543. static int enic_dev_soft_reset(struct enic *enic)
  1544. {
  1545. int err;
  1546. err = enic_dev_wait(enic->vdev, vnic_dev_soft_reset,
  1547. vnic_dev_soft_reset_done, 0);
  1548. if (err)
  1549. printk(KERN_ERR PFX
  1550. "vNIC soft reset failed, err %d.\n", err);
  1551. return err;
  1552. }
  1553. static int enic_set_niccfg(struct enic *enic)
  1554. {
  1555. const u8 rss_default_cpu = 0;
  1556. const u8 rss_hash_type = 0;
  1557. const u8 rss_hash_bits = 0;
  1558. const u8 rss_base_cpu = 0;
  1559. const u8 rss_enable = 0;
  1560. const u8 tso_ipid_split_en = 0;
  1561. const u8 ig_vlan_strip_en = 1;
  1562. /* Enable VLAN tag stripping. RSS not enabled (yet).
  1563. */
  1564. return enic_set_nic_cfg(enic,
  1565. rss_default_cpu, rss_hash_type,
  1566. rss_hash_bits, rss_base_cpu,
  1567. rss_enable, tso_ipid_split_en,
  1568. ig_vlan_strip_en);
  1569. }
  1570. static void enic_reset(struct work_struct *work)
  1571. {
  1572. struct enic *enic = container_of(work, struct enic, reset);
  1573. if (!netif_running(enic->netdev))
  1574. return;
  1575. rtnl_lock();
  1576. spin_lock(&enic->devcmd_lock);
  1577. vnic_dev_hang_notify(enic->vdev);
  1578. spin_unlock(&enic->devcmd_lock);
  1579. enic_stop(enic->netdev);
  1580. enic_dev_soft_reset(enic);
  1581. vnic_dev_init(enic->vdev, 0);
  1582. enic_reset_mcaddrs(enic);
  1583. enic_init_vnic_resources(enic);
  1584. enic_set_niccfg(enic);
  1585. enic_open(enic->netdev);
  1586. rtnl_unlock();
  1587. }
  1588. static int enic_set_intr_mode(struct enic *enic)
  1589. {
  1590. unsigned int n = 1;
  1591. unsigned int m = 1;
  1592. unsigned int i;
  1593. /* Set interrupt mode (INTx, MSI, MSI-X) depending
  1594. * system capabilities.
  1595. *
  1596. * Try MSI-X first
  1597. *
  1598. * We need n RQs, m WQs, n+m CQs, and n+m+2 INTRs
  1599. * (the second to last INTR is used for WQ/RQ errors)
  1600. * (the last INTR is used for notifications)
  1601. */
  1602. BUG_ON(ARRAY_SIZE(enic->msix_entry) < n + m + 2);
  1603. for (i = 0; i < n + m + 2; i++)
  1604. enic->msix_entry[i].entry = i;
  1605. if (enic->config.intr_mode < 1 &&
  1606. enic->rq_count >= n &&
  1607. enic->wq_count >= m &&
  1608. enic->cq_count >= n + m &&
  1609. enic->intr_count >= n + m + 2 &&
  1610. !pci_enable_msix(enic->pdev, enic->msix_entry, n + m + 2)) {
  1611. enic->rq_count = n;
  1612. enic->wq_count = m;
  1613. enic->cq_count = n + m;
  1614. enic->intr_count = n + m + 2;
  1615. vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_MSIX);
  1616. return 0;
  1617. }
  1618. /* Next try MSI
  1619. *
  1620. * We need 1 RQ, 1 WQ, 2 CQs, and 1 INTR
  1621. */
  1622. if (enic->config.intr_mode < 2 &&
  1623. enic->rq_count >= 1 &&
  1624. enic->wq_count >= 1 &&
  1625. enic->cq_count >= 2 &&
  1626. enic->intr_count >= 1 &&
  1627. !pci_enable_msi(enic->pdev)) {
  1628. enic->rq_count = 1;
  1629. enic->wq_count = 1;
  1630. enic->cq_count = 2;
  1631. enic->intr_count = 1;
  1632. vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_MSI);
  1633. return 0;
  1634. }
  1635. /* Next try INTx
  1636. *
  1637. * We need 1 RQ, 1 WQ, 2 CQs, and 3 INTRs
  1638. * (the first INTR is used for WQ/RQ)
  1639. * (the second INTR is used for WQ/RQ errors)
  1640. * (the last INTR is used for notifications)
  1641. */
  1642. if (enic->config.intr_mode < 3 &&
  1643. enic->rq_count >= 1 &&
  1644. enic->wq_count >= 1 &&
  1645. enic->cq_count >= 2 &&
  1646. enic->intr_count >= 3) {
  1647. enic->rq_count = 1;
  1648. enic->wq_count = 1;
  1649. enic->cq_count = 2;
  1650. enic->intr_count = 3;
  1651. vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_INTX);
  1652. return 0;
  1653. }
  1654. vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN);
  1655. return -EINVAL;
  1656. }
  1657. static void enic_clear_intr_mode(struct enic *enic)
  1658. {
  1659. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  1660. case VNIC_DEV_INTR_MODE_MSIX:
  1661. pci_disable_msix(enic->pdev);
  1662. break;
  1663. case VNIC_DEV_INTR_MODE_MSI:
  1664. pci_disable_msi(enic->pdev);
  1665. break;
  1666. default:
  1667. break;
  1668. }
  1669. vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN);
  1670. }
  1671. static const struct net_device_ops enic_netdev_dynamic_ops = {
  1672. .ndo_open = enic_open,
  1673. .ndo_stop = enic_stop,
  1674. .ndo_start_xmit = enic_hard_start_xmit,
  1675. .ndo_get_stats = enic_get_stats,
  1676. .ndo_validate_addr = eth_validate_addr,
  1677. .ndo_set_multicast_list = enic_set_multicast_list,
  1678. .ndo_set_mac_address = enic_set_mac_address_dynamic,
  1679. .ndo_change_mtu = enic_change_mtu,
  1680. .ndo_vlan_rx_register = enic_vlan_rx_register,
  1681. .ndo_vlan_rx_add_vid = enic_vlan_rx_add_vid,
  1682. .ndo_vlan_rx_kill_vid = enic_vlan_rx_kill_vid,
  1683. .ndo_tx_timeout = enic_tx_timeout,
  1684. .ndo_set_vf_port = enic_set_vf_port,
  1685. .ndo_get_vf_port = enic_get_vf_port,
  1686. #ifdef CONFIG_NET_POLL_CONTROLLER
  1687. .ndo_poll_controller = enic_poll_controller,
  1688. #endif
  1689. };
  1690. static const struct net_device_ops enic_netdev_ops = {
  1691. .ndo_open = enic_open,
  1692. .ndo_stop = enic_stop,
  1693. .ndo_start_xmit = enic_hard_start_xmit,
  1694. .ndo_get_stats = enic_get_stats,
  1695. .ndo_validate_addr = eth_validate_addr,
  1696. .ndo_set_multicast_list = enic_set_multicast_list,
  1697. .ndo_set_mac_address = enic_set_mac_address,
  1698. .ndo_change_mtu = enic_change_mtu,
  1699. .ndo_vlan_rx_register = enic_vlan_rx_register,
  1700. .ndo_vlan_rx_add_vid = enic_vlan_rx_add_vid,
  1701. .ndo_vlan_rx_kill_vid = enic_vlan_rx_kill_vid,
  1702. .ndo_tx_timeout = enic_tx_timeout,
  1703. #ifdef CONFIG_NET_POLL_CONTROLLER
  1704. .ndo_poll_controller = enic_poll_controller,
  1705. #endif
  1706. };
  1707. void enic_dev_deinit(struct enic *enic)
  1708. {
  1709. netif_napi_del(&enic->napi);
  1710. enic_free_vnic_resources(enic);
  1711. enic_clear_intr_mode(enic);
  1712. }
  1713. int enic_dev_init(struct enic *enic)
  1714. {
  1715. struct net_device *netdev = enic->netdev;
  1716. int err;
  1717. /* Get vNIC configuration
  1718. */
  1719. err = enic_get_vnic_config(enic);
  1720. if (err) {
  1721. printk(KERN_ERR PFX
  1722. "Get vNIC configuration failed, aborting.\n");
  1723. return err;
  1724. }
  1725. /* Get available resource counts
  1726. */
  1727. enic_get_res_counts(enic);
  1728. /* Set interrupt mode based on resource counts and system
  1729. * capabilities
  1730. */
  1731. err = enic_set_intr_mode(enic);
  1732. if (err) {
  1733. printk(KERN_ERR PFX
  1734. "Failed to set intr mode based on resource "
  1735. "counts and system capabilities, aborting.\n");
  1736. return err;
  1737. }
  1738. /* Allocate and configure vNIC resources
  1739. */
  1740. err = enic_alloc_vnic_resources(enic);
  1741. if (err) {
  1742. printk(KERN_ERR PFX
  1743. "Failed to alloc vNIC resources, aborting.\n");
  1744. goto err_out_free_vnic_resources;
  1745. }
  1746. enic_init_vnic_resources(enic);
  1747. err = enic_set_rq_alloc_buf(enic);
  1748. if (err) {
  1749. printk(KERN_ERR PFX
  1750. "Failed to set RQ buffer allocator, aborting.\n");
  1751. goto err_out_free_vnic_resources;
  1752. }
  1753. err = enic_set_niccfg(enic);
  1754. if (err) {
  1755. printk(KERN_ERR PFX
  1756. "Failed to config nic, aborting.\n");
  1757. goto err_out_free_vnic_resources;
  1758. }
  1759. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  1760. default:
  1761. netif_napi_add(netdev, &enic->napi, enic_poll, 64);
  1762. break;
  1763. case VNIC_DEV_INTR_MODE_MSIX:
  1764. netif_napi_add(netdev, &enic->napi, enic_poll_msix, 64);
  1765. break;
  1766. }
  1767. return 0;
  1768. err_out_free_vnic_resources:
  1769. enic_clear_intr_mode(enic);
  1770. enic_free_vnic_resources(enic);
  1771. return err;
  1772. }
  1773. static void enic_iounmap(struct enic *enic)
  1774. {
  1775. unsigned int i;
  1776. for (i = 0; i < ARRAY_SIZE(enic->bar); i++)
  1777. if (enic->bar[i].vaddr)
  1778. iounmap(enic->bar[i].vaddr);
  1779. }
  1780. static int __devinit enic_probe(struct pci_dev *pdev,
  1781. const struct pci_device_id *ent)
  1782. {
  1783. struct net_device *netdev;
  1784. struct enic *enic;
  1785. int using_dac = 0;
  1786. unsigned int i;
  1787. int err;
  1788. /* Allocate net device structure and initialize. Private
  1789. * instance data is initialized to zero.
  1790. */
  1791. netdev = alloc_etherdev(sizeof(struct enic));
  1792. if (!netdev) {
  1793. printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n");
  1794. return -ENOMEM;
  1795. }
  1796. pci_set_drvdata(pdev, netdev);
  1797. SET_NETDEV_DEV(netdev, &pdev->dev);
  1798. enic = netdev_priv(netdev);
  1799. enic->netdev = netdev;
  1800. enic->pdev = pdev;
  1801. /* Setup PCI resources
  1802. */
  1803. err = pci_enable_device(pdev);
  1804. if (err) {
  1805. printk(KERN_ERR PFX
  1806. "Cannot enable PCI device, aborting.\n");
  1807. goto err_out_free_netdev;
  1808. }
  1809. err = pci_request_regions(pdev, DRV_NAME);
  1810. if (err) {
  1811. printk(KERN_ERR PFX
  1812. "Cannot request PCI regions, aborting.\n");
  1813. goto err_out_disable_device;
  1814. }
  1815. pci_set_master(pdev);
  1816. /* Query PCI controller on system for DMA addressing
  1817. * limitation for the device. Try 40-bit first, and
  1818. * fail to 32-bit.
  1819. */
  1820. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(40));
  1821. if (err) {
  1822. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  1823. if (err) {
  1824. printk(KERN_ERR PFX
  1825. "No usable DMA configuration, aborting.\n");
  1826. goto err_out_release_regions;
  1827. }
  1828. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  1829. if (err) {
  1830. printk(KERN_ERR PFX
  1831. "Unable to obtain 32-bit DMA "
  1832. "for consistent allocations, aborting.\n");
  1833. goto err_out_release_regions;
  1834. }
  1835. } else {
  1836. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(40));
  1837. if (err) {
  1838. printk(KERN_ERR PFX
  1839. "Unable to obtain 40-bit DMA "
  1840. "for consistent allocations, aborting.\n");
  1841. goto err_out_release_regions;
  1842. }
  1843. using_dac = 1;
  1844. }
  1845. /* Map vNIC resources from BAR0-5
  1846. */
  1847. for (i = 0; i < ARRAY_SIZE(enic->bar); i++) {
  1848. if (!(pci_resource_flags(pdev, i) & IORESOURCE_MEM))
  1849. continue;
  1850. enic->bar[i].len = pci_resource_len(pdev, i);
  1851. enic->bar[i].vaddr = pci_iomap(pdev, i, enic->bar[i].len);
  1852. if (!enic->bar[i].vaddr) {
  1853. printk(KERN_ERR PFX
  1854. "Cannot memory-map BAR %d, aborting.\n", i);
  1855. err = -ENODEV;
  1856. goto err_out_iounmap;
  1857. }
  1858. enic->bar[i].bus_addr = pci_resource_start(pdev, i);
  1859. }
  1860. /* Register vNIC device
  1861. */
  1862. enic->vdev = vnic_dev_register(NULL, enic, pdev, enic->bar,
  1863. ARRAY_SIZE(enic->bar));
  1864. if (!enic->vdev) {
  1865. printk(KERN_ERR PFX
  1866. "vNIC registration failed, aborting.\n");
  1867. err = -ENODEV;
  1868. goto err_out_iounmap;
  1869. }
  1870. /* Issue device open to get device in known state
  1871. */
  1872. err = enic_dev_open(enic);
  1873. if (err) {
  1874. printk(KERN_ERR PFX
  1875. "vNIC dev open failed, aborting.\n");
  1876. goto err_out_vnic_unregister;
  1877. }
  1878. /* Issue device init to initialize the vnic-to-switch link.
  1879. * We'll start with carrier off and wait for link UP
  1880. * notification later to turn on carrier. We don't need
  1881. * to wait here for the vnic-to-switch link initialization
  1882. * to complete; link UP notification is the indication that
  1883. * the process is complete.
  1884. */
  1885. netif_carrier_off(netdev);
  1886. if (!enic_is_dynamic(enic)) {
  1887. err = vnic_dev_init(enic->vdev, 0);
  1888. if (err) {
  1889. printk(KERN_ERR PFX
  1890. "vNIC dev init failed, aborting.\n");
  1891. goto err_out_dev_close;
  1892. }
  1893. }
  1894. err = enic_dev_init(enic);
  1895. if (err) {
  1896. printk(KERN_ERR PFX
  1897. "Device initialization failed, aborting.\n");
  1898. goto err_out_dev_close;
  1899. }
  1900. /* Setup notification timer, HW reset task, and locks
  1901. */
  1902. init_timer(&enic->notify_timer);
  1903. enic->notify_timer.function = enic_notify_timer;
  1904. enic->notify_timer.data = (unsigned long)enic;
  1905. INIT_WORK(&enic->reset, enic_reset);
  1906. for (i = 0; i < enic->wq_count; i++)
  1907. spin_lock_init(&enic->wq_lock[i]);
  1908. spin_lock_init(&enic->devcmd_lock);
  1909. /* Register net device
  1910. */
  1911. enic->port_mtu = enic->config.mtu;
  1912. (void)enic_change_mtu(netdev, enic->port_mtu);
  1913. err = enic_set_mac_addr(netdev, enic->mac_addr);
  1914. if (err) {
  1915. printk(KERN_ERR PFX
  1916. "Invalid MAC address, aborting.\n");
  1917. goto err_out_dev_deinit;
  1918. }
  1919. enic->tx_coalesce_usecs = enic->config.intr_timer_usec;
  1920. enic->rx_coalesce_usecs = enic->tx_coalesce_usecs;
  1921. if (enic_is_dynamic(enic))
  1922. netdev->netdev_ops = &enic_netdev_dynamic_ops;
  1923. else
  1924. netdev->netdev_ops = &enic_netdev_ops;
  1925. netdev->watchdog_timeo = 2 * HZ;
  1926. netdev->ethtool_ops = &enic_ethtool_ops;
  1927. netdev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  1928. if (ENIC_SETTING(enic, TXCSUM))
  1929. netdev->features |= NETIF_F_SG | NETIF_F_HW_CSUM;
  1930. if (ENIC_SETTING(enic, TSO))
  1931. netdev->features |= NETIF_F_TSO |
  1932. NETIF_F_TSO6 | NETIF_F_TSO_ECN;
  1933. if (ENIC_SETTING(enic, LRO))
  1934. netdev->features |= NETIF_F_LRO;
  1935. if (using_dac)
  1936. netdev->features |= NETIF_F_HIGHDMA;
  1937. enic->csum_rx_enabled = ENIC_SETTING(enic, RXCSUM);
  1938. enic->lro_mgr.max_aggr = ENIC_LRO_MAX_AGGR;
  1939. enic->lro_mgr.max_desc = ENIC_LRO_MAX_DESC;
  1940. enic->lro_mgr.lro_arr = enic->lro_desc;
  1941. enic->lro_mgr.get_skb_header = enic_get_skb_header;
  1942. enic->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
  1943. enic->lro_mgr.dev = netdev;
  1944. enic->lro_mgr.ip_summed = CHECKSUM_COMPLETE;
  1945. enic->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
  1946. err = register_netdev(netdev);
  1947. if (err) {
  1948. printk(KERN_ERR PFX
  1949. "Cannot register net device, aborting.\n");
  1950. goto err_out_dev_deinit;
  1951. }
  1952. return 0;
  1953. err_out_dev_deinit:
  1954. enic_dev_deinit(enic);
  1955. err_out_dev_close:
  1956. vnic_dev_close(enic->vdev);
  1957. err_out_vnic_unregister:
  1958. vnic_dev_unregister(enic->vdev);
  1959. err_out_iounmap:
  1960. enic_iounmap(enic);
  1961. err_out_release_regions:
  1962. pci_release_regions(pdev);
  1963. err_out_disable_device:
  1964. pci_disable_device(pdev);
  1965. err_out_free_netdev:
  1966. pci_set_drvdata(pdev, NULL);
  1967. free_netdev(netdev);
  1968. return err;
  1969. }
  1970. static void __devexit enic_remove(struct pci_dev *pdev)
  1971. {
  1972. struct net_device *netdev = pci_get_drvdata(pdev);
  1973. if (netdev) {
  1974. struct enic *enic = netdev_priv(netdev);
  1975. flush_scheduled_work();
  1976. unregister_netdev(netdev);
  1977. enic_dev_deinit(enic);
  1978. vnic_dev_close(enic->vdev);
  1979. vnic_dev_unregister(enic->vdev);
  1980. enic_iounmap(enic);
  1981. pci_release_regions(pdev);
  1982. pci_disable_device(pdev);
  1983. pci_set_drvdata(pdev, NULL);
  1984. free_netdev(netdev);
  1985. }
  1986. }
  1987. static struct pci_driver enic_driver = {
  1988. .name = DRV_NAME,
  1989. .id_table = enic_id_table,
  1990. .probe = enic_probe,
  1991. .remove = __devexit_p(enic_remove),
  1992. };
  1993. static int __init enic_init_module(void)
  1994. {
  1995. printk(KERN_INFO PFX "%s, ver %s\n", DRV_DESCRIPTION, DRV_VERSION);
  1996. return pci_register_driver(&enic_driver);
  1997. }
  1998. static void __exit enic_cleanup_module(void)
  1999. {
  2000. pci_unregister_driver(&enic_driver);
  2001. }
  2002. module_init(enic_init_module);
  2003. module_exit(enic_cleanup_module);