main.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228
  1. /*
  2. * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
  3. * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
  4. * Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies. All rights reserved.
  5. * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
  6. *
  7. * This software is available to you under a choice of one of two
  8. * licenses. You may choose to be licensed under the terms of the GNU
  9. * General Public License (GPL) Version 2, available from the file
  10. * COPYING in the main directory of this source tree, or the
  11. * OpenIB.org BSD license below:
  12. *
  13. * Redistribution and use in source and binary forms, with or
  14. * without modification, are permitted provided that the following
  15. * conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above
  18. * copyright notice, this list of conditions and the following
  19. * disclaimer.
  20. *
  21. * - Redistributions in binary form must reproduce the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer in the documentation and/or other materials
  24. * provided with the distribution.
  25. *
  26. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  30. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  31. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  32. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  33. * SOFTWARE.
  34. */
  35. #include <linux/module.h>
  36. #include <linux/init.h>
  37. #include <linux/errno.h>
  38. #include <linux/pci.h>
  39. #include <linux/dma-mapping.h>
  40. #include <linux/slab.h>
  41. #include <linux/io-mapping.h>
  42. #include <linux/delay.h>
  43. #include <linux/mlx4/device.h>
  44. #include <linux/mlx4/doorbell.h>
  45. #include "mlx4.h"
  46. #include "fw.h"
  47. #include "icm.h"
  48. MODULE_AUTHOR("Roland Dreier");
  49. MODULE_DESCRIPTION("Mellanox ConnectX HCA low-level driver");
  50. MODULE_LICENSE("Dual BSD/GPL");
  51. MODULE_VERSION(DRV_VERSION);
  52. struct workqueue_struct *mlx4_wq;
  53. #ifdef CONFIG_MLX4_DEBUG
  54. int mlx4_debug_level = 0;
  55. module_param_named(debug_level, mlx4_debug_level, int, 0644);
  56. MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0");
  57. #endif /* CONFIG_MLX4_DEBUG */
  58. #ifdef CONFIG_PCI_MSI
  59. static int msi_x = 1;
  60. module_param(msi_x, int, 0444);
  61. MODULE_PARM_DESC(msi_x, "attempt to use MSI-X if nonzero");
  62. #else /* CONFIG_PCI_MSI */
  63. #define msi_x (0)
  64. #endif /* CONFIG_PCI_MSI */
  65. static int num_vfs;
  66. module_param(num_vfs, int, 0444);
  67. MODULE_PARM_DESC(num_vfs, "enable #num_vfs functions if num_vfs > 0");
  68. static int probe_vf;
  69. module_param(probe_vf, int, 0644);
  70. MODULE_PARM_DESC(probe_vf, "number of vfs to probe by pf driver (num_vfs > 0)");
  71. int mlx4_log_num_mgm_entry_size = 10;
  72. module_param_named(log_num_mgm_entry_size,
  73. mlx4_log_num_mgm_entry_size, int, 0444);
  74. MODULE_PARM_DESC(log_num_mgm_entry_size, "log mgm size, that defines the num"
  75. " of qp per mcg, for example:"
  76. " 10 gives 248.range: 9<="
  77. " log_num_mgm_entry_size <= 12");
  78. #define MLX4_VF (1 << 0)
  79. #define HCA_GLOBAL_CAP_MASK 0
  80. #define PF_CONTEXT_BEHAVIOUR_MASK 0
  81. static char mlx4_version[] __devinitdata =
  82. DRV_NAME ": Mellanox ConnectX core driver v"
  83. DRV_VERSION " (" DRV_RELDATE ")\n";
  84. static struct mlx4_profile default_profile = {
  85. .num_qp = 1 << 18,
  86. .num_srq = 1 << 16,
  87. .rdmarc_per_qp = 1 << 4,
  88. .num_cq = 1 << 16,
  89. .num_mcg = 1 << 13,
  90. .num_mpt = 1 << 19,
  91. .num_mtt = 1 << 20, /* It is really num mtt segements */
  92. };
  93. static int log_num_mac = 7;
  94. module_param_named(log_num_mac, log_num_mac, int, 0444);
  95. MODULE_PARM_DESC(log_num_mac, "Log2 max number of MACs per ETH port (1-7)");
  96. static int log_num_vlan;
  97. module_param_named(log_num_vlan, log_num_vlan, int, 0444);
  98. MODULE_PARM_DESC(log_num_vlan, "Log2 max number of VLANs per ETH port (0-7)");
  99. /* Log2 max number of VLANs per ETH port (0-7) */
  100. #define MLX4_LOG_NUM_VLANS 7
  101. static bool use_prio;
  102. module_param_named(use_prio, use_prio, bool, 0444);
  103. MODULE_PARM_DESC(use_prio, "Enable steering by VLAN priority on ETH ports "
  104. "(0/1, default 0)");
  105. int log_mtts_per_seg = ilog2(MLX4_MTT_ENTRY_PER_SEG);
  106. module_param_named(log_mtts_per_seg, log_mtts_per_seg, int, 0444);
  107. MODULE_PARM_DESC(log_mtts_per_seg, "Log2 number of MTT entries per segment (1-7)");
  108. static int port_type_array[2] = {MLX4_PORT_TYPE_NONE, MLX4_PORT_TYPE_NONE};
  109. static int arr_argc = 2;
  110. module_param_array(port_type_array, int, &arr_argc, 0444);
  111. MODULE_PARM_DESC(port_type_array, "Array of port types: HW_DEFAULT (0) is default "
  112. "1 for IB, 2 for Ethernet");
  113. struct mlx4_port_config {
  114. struct list_head list;
  115. enum mlx4_port_type port_type[MLX4_MAX_PORTS + 1];
  116. struct pci_dev *pdev;
  117. };
  118. static inline int mlx4_master_get_num_eqs(struct mlx4_dev *dev)
  119. {
  120. return dev->caps.reserved_eqs +
  121. MLX4_MFUNC_EQ_NUM * (dev->num_slaves + 1);
  122. }
  123. int mlx4_check_port_params(struct mlx4_dev *dev,
  124. enum mlx4_port_type *port_type)
  125. {
  126. int i;
  127. for (i = 0; i < dev->caps.num_ports - 1; i++) {
  128. if (port_type[i] != port_type[i + 1]) {
  129. if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP)) {
  130. mlx4_err(dev, "Only same port types supported "
  131. "on this HCA, aborting.\n");
  132. return -EINVAL;
  133. }
  134. if (port_type[i] == MLX4_PORT_TYPE_ETH &&
  135. port_type[i + 1] == MLX4_PORT_TYPE_IB)
  136. return -EINVAL;
  137. }
  138. }
  139. for (i = 0; i < dev->caps.num_ports; i++) {
  140. if (!(port_type[i] & dev->caps.supported_type[i+1])) {
  141. mlx4_err(dev, "Requested port type for port %d is not "
  142. "supported on this HCA\n", i + 1);
  143. return -EINVAL;
  144. }
  145. }
  146. return 0;
  147. }
  148. static void mlx4_set_port_mask(struct mlx4_dev *dev)
  149. {
  150. int i;
  151. for (i = 1; i <= dev->caps.num_ports; ++i)
  152. dev->caps.port_mask[i] = dev->caps.port_type[i];
  153. }
  154. static int mlx4_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
  155. {
  156. int err;
  157. int i;
  158. err = mlx4_QUERY_DEV_CAP(dev, dev_cap);
  159. if (err) {
  160. mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n");
  161. return err;
  162. }
  163. if (dev_cap->min_page_sz > PAGE_SIZE) {
  164. mlx4_err(dev, "HCA minimum page size of %d bigger than "
  165. "kernel PAGE_SIZE of %ld, aborting.\n",
  166. dev_cap->min_page_sz, PAGE_SIZE);
  167. return -ENODEV;
  168. }
  169. if (dev_cap->num_ports > MLX4_MAX_PORTS) {
  170. mlx4_err(dev, "HCA has %d ports, but we only support %d, "
  171. "aborting.\n",
  172. dev_cap->num_ports, MLX4_MAX_PORTS);
  173. return -ENODEV;
  174. }
  175. if (dev_cap->uar_size > pci_resource_len(dev->pdev, 2)) {
  176. mlx4_err(dev, "HCA reported UAR size of 0x%x bigger than "
  177. "PCI resource 2 size of 0x%llx, aborting.\n",
  178. dev_cap->uar_size,
  179. (unsigned long long) pci_resource_len(dev->pdev, 2));
  180. return -ENODEV;
  181. }
  182. dev->caps.num_ports = dev_cap->num_ports;
  183. for (i = 1; i <= dev->caps.num_ports; ++i) {
  184. dev->caps.vl_cap[i] = dev_cap->max_vl[i];
  185. dev->caps.ib_mtu_cap[i] = dev_cap->ib_mtu[i];
  186. dev->caps.gid_table_len[i] = dev_cap->max_gids[i];
  187. dev->caps.pkey_table_len[i] = dev_cap->max_pkeys[i];
  188. dev->caps.port_width_cap[i] = dev_cap->max_port_width[i];
  189. dev->caps.eth_mtu_cap[i] = dev_cap->eth_mtu[i];
  190. dev->caps.def_mac[i] = dev_cap->def_mac[i];
  191. dev->caps.supported_type[i] = dev_cap->supported_port_types[i];
  192. dev->caps.suggested_type[i] = dev_cap->suggested_type[i];
  193. dev->caps.default_sense[i] = dev_cap->default_sense[i];
  194. dev->caps.trans_type[i] = dev_cap->trans_type[i];
  195. dev->caps.vendor_oui[i] = dev_cap->vendor_oui[i];
  196. dev->caps.wavelength[i] = dev_cap->wavelength[i];
  197. dev->caps.trans_code[i] = dev_cap->trans_code[i];
  198. }
  199. dev->caps.uar_page_size = PAGE_SIZE;
  200. dev->caps.num_uars = dev_cap->uar_size / PAGE_SIZE;
  201. dev->caps.local_ca_ack_delay = dev_cap->local_ca_ack_delay;
  202. dev->caps.bf_reg_size = dev_cap->bf_reg_size;
  203. dev->caps.bf_regs_per_page = dev_cap->bf_regs_per_page;
  204. dev->caps.max_sq_sg = dev_cap->max_sq_sg;
  205. dev->caps.max_rq_sg = dev_cap->max_rq_sg;
  206. dev->caps.max_wqes = dev_cap->max_qp_sz;
  207. dev->caps.max_qp_init_rdma = dev_cap->max_requester_per_qp;
  208. dev->caps.max_srq_wqes = dev_cap->max_srq_sz;
  209. dev->caps.max_srq_sge = dev_cap->max_rq_sg - 1;
  210. dev->caps.reserved_srqs = dev_cap->reserved_srqs;
  211. dev->caps.max_sq_desc_sz = dev_cap->max_sq_desc_sz;
  212. dev->caps.max_rq_desc_sz = dev_cap->max_rq_desc_sz;
  213. dev->caps.num_qp_per_mgm = mlx4_get_qp_per_mgm(dev);
  214. /*
  215. * Subtract 1 from the limit because we need to allocate a
  216. * spare CQE so the HCA HW can tell the difference between an
  217. * empty CQ and a full CQ.
  218. */
  219. dev->caps.max_cqes = dev_cap->max_cq_sz - 1;
  220. dev->caps.reserved_cqs = dev_cap->reserved_cqs;
  221. dev->caps.reserved_eqs = dev_cap->reserved_eqs;
  222. dev->caps.reserved_mtts = dev_cap->reserved_mtts;
  223. dev->caps.reserved_mrws = dev_cap->reserved_mrws;
  224. /* The first 128 UARs are used for EQ doorbells */
  225. dev->caps.reserved_uars = max_t(int, 128, dev_cap->reserved_uars);
  226. dev->caps.reserved_pds = dev_cap->reserved_pds;
  227. dev->caps.reserved_xrcds = (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) ?
  228. dev_cap->reserved_xrcds : 0;
  229. dev->caps.max_xrcds = (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) ?
  230. dev_cap->max_xrcds : 0;
  231. dev->caps.mtt_entry_sz = dev_cap->mtt_entry_sz;
  232. dev->caps.max_msg_sz = dev_cap->max_msg_sz;
  233. dev->caps.page_size_cap = ~(u32) (dev_cap->min_page_sz - 1);
  234. dev->caps.flags = dev_cap->flags;
  235. dev->caps.flags2 = dev_cap->flags2;
  236. dev->caps.bmme_flags = dev_cap->bmme_flags;
  237. dev->caps.reserved_lkey = dev_cap->reserved_lkey;
  238. dev->caps.stat_rate_support = dev_cap->stat_rate_support;
  239. dev->caps.max_gso_sz = dev_cap->max_gso_sz;
  240. dev->caps.max_rss_tbl_sz = dev_cap->max_rss_tbl_sz;
  241. /* Sense port always allowed on supported devices for ConnectX1 and 2 */
  242. if (dev->pdev->device != 0x1003)
  243. dev->caps.flags |= MLX4_DEV_CAP_FLAG_SENSE_SUPPORT;
  244. dev->caps.log_num_macs = log_num_mac;
  245. dev->caps.log_num_vlans = MLX4_LOG_NUM_VLANS;
  246. dev->caps.log_num_prios = use_prio ? 3 : 0;
  247. for (i = 1; i <= dev->caps.num_ports; ++i) {
  248. dev->caps.port_type[i] = MLX4_PORT_TYPE_NONE;
  249. if (dev->caps.supported_type[i]) {
  250. /* if only ETH is supported - assign ETH */
  251. if (dev->caps.supported_type[i] == MLX4_PORT_TYPE_ETH)
  252. dev->caps.port_type[i] = MLX4_PORT_TYPE_ETH;
  253. /* if only IB is supported,
  254. * assign IB only if SRIOV is off*/
  255. else if (dev->caps.supported_type[i] ==
  256. MLX4_PORT_TYPE_IB) {
  257. if (dev->flags & MLX4_FLAG_SRIOV)
  258. dev->caps.port_type[i] =
  259. MLX4_PORT_TYPE_NONE;
  260. else
  261. dev->caps.port_type[i] =
  262. MLX4_PORT_TYPE_IB;
  263. /* if IB and ETH are supported,
  264. * first of all check if SRIOV is on */
  265. } else if (dev->flags & MLX4_FLAG_SRIOV)
  266. dev->caps.port_type[i] = MLX4_PORT_TYPE_ETH;
  267. else {
  268. /* In non-SRIOV mode, we set the port type
  269. * according to user selection of port type,
  270. * if usere selected none, take the FW hint */
  271. if (port_type_array[i-1] == MLX4_PORT_TYPE_NONE)
  272. dev->caps.port_type[i] = dev->caps.suggested_type[i] ?
  273. MLX4_PORT_TYPE_ETH : MLX4_PORT_TYPE_IB;
  274. else
  275. dev->caps.port_type[i] = port_type_array[i-1];
  276. }
  277. }
  278. /*
  279. * Link sensing is allowed on the port if 3 conditions are true:
  280. * 1. Both protocols are supported on the port.
  281. * 2. Different types are supported on the port
  282. * 3. FW declared that it supports link sensing
  283. */
  284. mlx4_priv(dev)->sense.sense_allowed[i] =
  285. ((dev->caps.supported_type[i] == MLX4_PORT_TYPE_AUTO) &&
  286. (dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP) &&
  287. (dev->caps.flags & MLX4_DEV_CAP_FLAG_SENSE_SUPPORT));
  288. /*
  289. * If "default_sense" bit is set, we move the port to "AUTO" mode
  290. * and perform sense_port FW command to try and set the correct
  291. * port type from beginning
  292. */
  293. if (mlx4_priv(dev)->sense.sense_allowed[i] && dev->caps.default_sense[i]) {
  294. enum mlx4_port_type sensed_port = MLX4_PORT_TYPE_NONE;
  295. dev->caps.possible_type[i] = MLX4_PORT_TYPE_AUTO;
  296. mlx4_SENSE_PORT(dev, i, &sensed_port);
  297. if (sensed_port != MLX4_PORT_TYPE_NONE)
  298. dev->caps.port_type[i] = sensed_port;
  299. } else {
  300. dev->caps.possible_type[i] = dev->caps.port_type[i];
  301. }
  302. if (dev->caps.log_num_macs > dev_cap->log_max_macs[i]) {
  303. dev->caps.log_num_macs = dev_cap->log_max_macs[i];
  304. mlx4_warn(dev, "Requested number of MACs is too much "
  305. "for port %d, reducing to %d.\n",
  306. i, 1 << dev->caps.log_num_macs);
  307. }
  308. if (dev->caps.log_num_vlans > dev_cap->log_max_vlans[i]) {
  309. dev->caps.log_num_vlans = dev_cap->log_max_vlans[i];
  310. mlx4_warn(dev, "Requested number of VLANs is too much "
  311. "for port %d, reducing to %d.\n",
  312. i, 1 << dev->caps.log_num_vlans);
  313. }
  314. }
  315. dev->caps.max_counters = 1 << ilog2(dev_cap->max_counters);
  316. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW] = dev_cap->reserved_qps;
  317. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_ETH_ADDR] =
  318. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_ADDR] =
  319. (1 << dev->caps.log_num_macs) *
  320. (1 << dev->caps.log_num_vlans) *
  321. (1 << dev->caps.log_num_prios) *
  322. dev->caps.num_ports;
  323. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_EXCH] = MLX4_NUM_FEXCH;
  324. dev->caps.reserved_qps = dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW] +
  325. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_ETH_ADDR] +
  326. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_ADDR] +
  327. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_EXCH];
  328. return 0;
  329. }
  330. /*The function checks if there are live vf, return the num of them*/
  331. static int mlx4_how_many_lives_vf(struct mlx4_dev *dev)
  332. {
  333. struct mlx4_priv *priv = mlx4_priv(dev);
  334. struct mlx4_slave_state *s_state;
  335. int i;
  336. int ret = 0;
  337. for (i = 1/*the ppf is 0*/; i < dev->num_slaves; ++i) {
  338. s_state = &priv->mfunc.master.slave_state[i];
  339. if (s_state->active && s_state->last_cmd !=
  340. MLX4_COMM_CMD_RESET) {
  341. mlx4_warn(dev, "%s: slave: %d is still active\n",
  342. __func__, i);
  343. ret++;
  344. }
  345. }
  346. return ret;
  347. }
  348. int mlx4_is_slave_active(struct mlx4_dev *dev, int slave)
  349. {
  350. struct mlx4_priv *priv = mlx4_priv(dev);
  351. struct mlx4_slave_state *s_slave;
  352. if (!mlx4_is_master(dev))
  353. return 0;
  354. s_slave = &priv->mfunc.master.slave_state[slave];
  355. return !!s_slave->active;
  356. }
  357. EXPORT_SYMBOL(mlx4_is_slave_active);
  358. static int mlx4_slave_cap(struct mlx4_dev *dev)
  359. {
  360. int err;
  361. u32 page_size;
  362. struct mlx4_dev_cap dev_cap;
  363. struct mlx4_func_cap func_cap;
  364. struct mlx4_init_hca_param hca_param;
  365. int i;
  366. memset(&hca_param, 0, sizeof(hca_param));
  367. err = mlx4_QUERY_HCA(dev, &hca_param);
  368. if (err) {
  369. mlx4_err(dev, "QUERY_HCA command failed, aborting.\n");
  370. return err;
  371. }
  372. /*fail if the hca has an unknown capability */
  373. if ((hca_param.global_caps | HCA_GLOBAL_CAP_MASK) !=
  374. HCA_GLOBAL_CAP_MASK) {
  375. mlx4_err(dev, "Unknown hca global capabilities\n");
  376. return -ENOSYS;
  377. }
  378. mlx4_log_num_mgm_entry_size = hca_param.log_mc_entry_sz;
  379. memset(&dev_cap, 0, sizeof(dev_cap));
  380. err = mlx4_dev_cap(dev, &dev_cap);
  381. if (err) {
  382. mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n");
  383. return err;
  384. }
  385. page_size = ~dev->caps.page_size_cap + 1;
  386. mlx4_warn(dev, "HCA minimum page size:%d\n", page_size);
  387. if (page_size > PAGE_SIZE) {
  388. mlx4_err(dev, "HCA minimum page size of %d bigger than "
  389. "kernel PAGE_SIZE of %ld, aborting.\n",
  390. page_size, PAGE_SIZE);
  391. return -ENODEV;
  392. }
  393. /* slave gets uar page size from QUERY_HCA fw command */
  394. dev->caps.uar_page_size = 1 << (hca_param.uar_page_sz + 12);
  395. /* TODO: relax this assumption */
  396. if (dev->caps.uar_page_size != PAGE_SIZE) {
  397. mlx4_err(dev, "UAR size:%d != kernel PAGE_SIZE of %ld\n",
  398. dev->caps.uar_page_size, PAGE_SIZE);
  399. return -ENODEV;
  400. }
  401. memset(&func_cap, 0, sizeof(func_cap));
  402. err = mlx4_QUERY_FUNC_CAP(dev, &func_cap);
  403. if (err) {
  404. mlx4_err(dev, "QUERY_FUNC_CAP command failed, aborting.\n");
  405. return err;
  406. }
  407. if ((func_cap.pf_context_behaviour | PF_CONTEXT_BEHAVIOUR_MASK) !=
  408. PF_CONTEXT_BEHAVIOUR_MASK) {
  409. mlx4_err(dev, "Unknown pf context behaviour\n");
  410. return -ENOSYS;
  411. }
  412. dev->caps.num_ports = func_cap.num_ports;
  413. dev->caps.num_qps = func_cap.qp_quota;
  414. dev->caps.num_srqs = func_cap.srq_quota;
  415. dev->caps.num_cqs = func_cap.cq_quota;
  416. dev->caps.num_eqs = func_cap.max_eq;
  417. dev->caps.reserved_eqs = func_cap.reserved_eq;
  418. dev->caps.num_mpts = func_cap.mpt_quota;
  419. dev->caps.num_mtts = func_cap.mtt_quota;
  420. dev->caps.num_pds = MLX4_NUM_PDS;
  421. dev->caps.num_mgms = 0;
  422. dev->caps.num_amgms = 0;
  423. for (i = 1; i <= dev->caps.num_ports; ++i)
  424. dev->caps.port_mask[i] = dev->caps.port_type[i];
  425. if (dev->caps.num_ports > MLX4_MAX_PORTS) {
  426. mlx4_err(dev, "HCA has %d ports, but we only support %d, "
  427. "aborting.\n", dev->caps.num_ports, MLX4_MAX_PORTS);
  428. return -ENODEV;
  429. }
  430. if (dev->caps.uar_page_size * (dev->caps.num_uars -
  431. dev->caps.reserved_uars) >
  432. pci_resource_len(dev->pdev, 2)) {
  433. mlx4_err(dev, "HCA reported UAR region size of 0x%x bigger than "
  434. "PCI resource 2 size of 0x%llx, aborting.\n",
  435. dev->caps.uar_page_size * dev->caps.num_uars,
  436. (unsigned long long) pci_resource_len(dev->pdev, 2));
  437. return -ENODEV;
  438. }
  439. #if 0
  440. mlx4_warn(dev, "sqp_demux:%d\n", dev->caps.sqp_demux);
  441. mlx4_warn(dev, "num_uars:%d reserved_uars:%d uar region:0x%x bar2:0x%llx\n",
  442. dev->caps.num_uars, dev->caps.reserved_uars,
  443. dev->caps.uar_page_size * dev->caps.num_uars,
  444. pci_resource_len(dev->pdev, 2));
  445. mlx4_warn(dev, "num_eqs:%d reserved_eqs:%d\n", dev->caps.num_eqs,
  446. dev->caps.reserved_eqs);
  447. mlx4_warn(dev, "num_pds:%d reserved_pds:%d slave_pd_shift:%d pd_base:%d\n",
  448. dev->caps.num_pds, dev->caps.reserved_pds,
  449. dev->caps.slave_pd_shift, dev->caps.pd_base);
  450. #endif
  451. return 0;
  452. }
  453. /*
  454. * Change the port configuration of the device.
  455. * Every user of this function must hold the port mutex.
  456. */
  457. int mlx4_change_port_types(struct mlx4_dev *dev,
  458. enum mlx4_port_type *port_types)
  459. {
  460. int err = 0;
  461. int change = 0;
  462. int port;
  463. for (port = 0; port < dev->caps.num_ports; port++) {
  464. /* Change the port type only if the new type is different
  465. * from the current, and not set to Auto */
  466. if (port_types[port] != dev->caps.port_type[port + 1])
  467. change = 1;
  468. }
  469. if (change) {
  470. mlx4_unregister_device(dev);
  471. for (port = 1; port <= dev->caps.num_ports; port++) {
  472. mlx4_CLOSE_PORT(dev, port);
  473. dev->caps.port_type[port] = port_types[port - 1];
  474. err = mlx4_SET_PORT(dev, port);
  475. if (err) {
  476. mlx4_err(dev, "Failed to set port %d, "
  477. "aborting\n", port);
  478. goto out;
  479. }
  480. }
  481. mlx4_set_port_mask(dev);
  482. err = mlx4_register_device(dev);
  483. }
  484. out:
  485. return err;
  486. }
  487. static ssize_t show_port_type(struct device *dev,
  488. struct device_attribute *attr,
  489. char *buf)
  490. {
  491. struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info,
  492. port_attr);
  493. struct mlx4_dev *mdev = info->dev;
  494. char type[8];
  495. sprintf(type, "%s",
  496. (mdev->caps.port_type[info->port] == MLX4_PORT_TYPE_IB) ?
  497. "ib" : "eth");
  498. if (mdev->caps.possible_type[info->port] == MLX4_PORT_TYPE_AUTO)
  499. sprintf(buf, "auto (%s)\n", type);
  500. else
  501. sprintf(buf, "%s\n", type);
  502. return strlen(buf);
  503. }
  504. static ssize_t set_port_type(struct device *dev,
  505. struct device_attribute *attr,
  506. const char *buf, size_t count)
  507. {
  508. struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info,
  509. port_attr);
  510. struct mlx4_dev *mdev = info->dev;
  511. struct mlx4_priv *priv = mlx4_priv(mdev);
  512. enum mlx4_port_type types[MLX4_MAX_PORTS];
  513. enum mlx4_port_type new_types[MLX4_MAX_PORTS];
  514. int i;
  515. int err = 0;
  516. if (!strcmp(buf, "ib\n"))
  517. info->tmp_type = MLX4_PORT_TYPE_IB;
  518. else if (!strcmp(buf, "eth\n"))
  519. info->tmp_type = MLX4_PORT_TYPE_ETH;
  520. else if (!strcmp(buf, "auto\n"))
  521. info->tmp_type = MLX4_PORT_TYPE_AUTO;
  522. else {
  523. mlx4_err(mdev, "%s is not supported port type\n", buf);
  524. return -EINVAL;
  525. }
  526. mlx4_stop_sense(mdev);
  527. mutex_lock(&priv->port_mutex);
  528. /* Possible type is always the one that was delivered */
  529. mdev->caps.possible_type[info->port] = info->tmp_type;
  530. for (i = 0; i < mdev->caps.num_ports; i++) {
  531. types[i] = priv->port[i+1].tmp_type ? priv->port[i+1].tmp_type :
  532. mdev->caps.possible_type[i+1];
  533. if (types[i] == MLX4_PORT_TYPE_AUTO)
  534. types[i] = mdev->caps.port_type[i+1];
  535. }
  536. if (!(mdev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP) &&
  537. !(mdev->caps.flags & MLX4_DEV_CAP_FLAG_SENSE_SUPPORT)) {
  538. for (i = 1; i <= mdev->caps.num_ports; i++) {
  539. if (mdev->caps.possible_type[i] == MLX4_PORT_TYPE_AUTO) {
  540. mdev->caps.possible_type[i] = mdev->caps.port_type[i];
  541. err = -EINVAL;
  542. }
  543. }
  544. }
  545. if (err) {
  546. mlx4_err(mdev, "Auto sensing is not supported on this HCA. "
  547. "Set only 'eth' or 'ib' for both ports "
  548. "(should be the same)\n");
  549. goto out;
  550. }
  551. mlx4_do_sense_ports(mdev, new_types, types);
  552. err = mlx4_check_port_params(mdev, new_types);
  553. if (err)
  554. goto out;
  555. /* We are about to apply the changes after the configuration
  556. * was verified, no need to remember the temporary types
  557. * any more */
  558. for (i = 0; i < mdev->caps.num_ports; i++)
  559. priv->port[i + 1].tmp_type = 0;
  560. err = mlx4_change_port_types(mdev, new_types);
  561. out:
  562. mlx4_start_sense(mdev);
  563. mutex_unlock(&priv->port_mutex);
  564. return err ? err : count;
  565. }
  566. enum ibta_mtu {
  567. IB_MTU_256 = 1,
  568. IB_MTU_512 = 2,
  569. IB_MTU_1024 = 3,
  570. IB_MTU_2048 = 4,
  571. IB_MTU_4096 = 5
  572. };
  573. static inline int int_to_ibta_mtu(int mtu)
  574. {
  575. switch (mtu) {
  576. case 256: return IB_MTU_256;
  577. case 512: return IB_MTU_512;
  578. case 1024: return IB_MTU_1024;
  579. case 2048: return IB_MTU_2048;
  580. case 4096: return IB_MTU_4096;
  581. default: return -1;
  582. }
  583. }
  584. static inline int ibta_mtu_to_int(enum ibta_mtu mtu)
  585. {
  586. switch (mtu) {
  587. case IB_MTU_256: return 256;
  588. case IB_MTU_512: return 512;
  589. case IB_MTU_1024: return 1024;
  590. case IB_MTU_2048: return 2048;
  591. case IB_MTU_4096: return 4096;
  592. default: return -1;
  593. }
  594. }
  595. static ssize_t show_port_ib_mtu(struct device *dev,
  596. struct device_attribute *attr,
  597. char *buf)
  598. {
  599. struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info,
  600. port_mtu_attr);
  601. struct mlx4_dev *mdev = info->dev;
  602. if (mdev->caps.port_type[info->port] == MLX4_PORT_TYPE_ETH)
  603. mlx4_warn(mdev, "port level mtu is only used for IB ports\n");
  604. sprintf(buf, "%d\n",
  605. ibta_mtu_to_int(mdev->caps.port_ib_mtu[info->port]));
  606. return strlen(buf);
  607. }
  608. static ssize_t set_port_ib_mtu(struct device *dev,
  609. struct device_attribute *attr,
  610. const char *buf, size_t count)
  611. {
  612. struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info,
  613. port_mtu_attr);
  614. struct mlx4_dev *mdev = info->dev;
  615. struct mlx4_priv *priv = mlx4_priv(mdev);
  616. int err, port, mtu, ibta_mtu = -1;
  617. if (mdev->caps.port_type[info->port] == MLX4_PORT_TYPE_ETH) {
  618. mlx4_warn(mdev, "port level mtu is only used for IB ports\n");
  619. return -EINVAL;
  620. }
  621. err = sscanf(buf, "%d", &mtu);
  622. if (err > 0)
  623. ibta_mtu = int_to_ibta_mtu(mtu);
  624. if (err <= 0 || ibta_mtu < 0) {
  625. mlx4_err(mdev, "%s is invalid IBTA mtu\n", buf);
  626. return -EINVAL;
  627. }
  628. mdev->caps.port_ib_mtu[info->port] = ibta_mtu;
  629. mlx4_stop_sense(mdev);
  630. mutex_lock(&priv->port_mutex);
  631. mlx4_unregister_device(mdev);
  632. for (port = 1; port <= mdev->caps.num_ports; port++) {
  633. mlx4_CLOSE_PORT(mdev, port);
  634. err = mlx4_SET_PORT(mdev, port);
  635. if (err) {
  636. mlx4_err(mdev, "Failed to set port %d, "
  637. "aborting\n", port);
  638. goto err_set_port;
  639. }
  640. }
  641. err = mlx4_register_device(mdev);
  642. err_set_port:
  643. mutex_unlock(&priv->port_mutex);
  644. mlx4_start_sense(mdev);
  645. return err ? err : count;
  646. }
  647. static int mlx4_load_fw(struct mlx4_dev *dev)
  648. {
  649. struct mlx4_priv *priv = mlx4_priv(dev);
  650. int err;
  651. priv->fw.fw_icm = mlx4_alloc_icm(dev, priv->fw.fw_pages,
  652. GFP_HIGHUSER | __GFP_NOWARN, 0);
  653. if (!priv->fw.fw_icm) {
  654. mlx4_err(dev, "Couldn't allocate FW area, aborting.\n");
  655. return -ENOMEM;
  656. }
  657. err = mlx4_MAP_FA(dev, priv->fw.fw_icm);
  658. if (err) {
  659. mlx4_err(dev, "MAP_FA command failed, aborting.\n");
  660. goto err_free;
  661. }
  662. err = mlx4_RUN_FW(dev);
  663. if (err) {
  664. mlx4_err(dev, "RUN_FW command failed, aborting.\n");
  665. goto err_unmap_fa;
  666. }
  667. return 0;
  668. err_unmap_fa:
  669. mlx4_UNMAP_FA(dev);
  670. err_free:
  671. mlx4_free_icm(dev, priv->fw.fw_icm, 0);
  672. return err;
  673. }
  674. static int mlx4_init_cmpt_table(struct mlx4_dev *dev, u64 cmpt_base,
  675. int cmpt_entry_sz)
  676. {
  677. struct mlx4_priv *priv = mlx4_priv(dev);
  678. int err;
  679. int num_eqs;
  680. err = mlx4_init_icm_table(dev, &priv->qp_table.cmpt_table,
  681. cmpt_base +
  682. ((u64) (MLX4_CMPT_TYPE_QP *
  683. cmpt_entry_sz) << MLX4_CMPT_SHIFT),
  684. cmpt_entry_sz, dev->caps.num_qps,
  685. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  686. 0, 0);
  687. if (err)
  688. goto err;
  689. err = mlx4_init_icm_table(dev, &priv->srq_table.cmpt_table,
  690. cmpt_base +
  691. ((u64) (MLX4_CMPT_TYPE_SRQ *
  692. cmpt_entry_sz) << MLX4_CMPT_SHIFT),
  693. cmpt_entry_sz, dev->caps.num_srqs,
  694. dev->caps.reserved_srqs, 0, 0);
  695. if (err)
  696. goto err_qp;
  697. err = mlx4_init_icm_table(dev, &priv->cq_table.cmpt_table,
  698. cmpt_base +
  699. ((u64) (MLX4_CMPT_TYPE_CQ *
  700. cmpt_entry_sz) << MLX4_CMPT_SHIFT),
  701. cmpt_entry_sz, dev->caps.num_cqs,
  702. dev->caps.reserved_cqs, 0, 0);
  703. if (err)
  704. goto err_srq;
  705. num_eqs = (mlx4_is_master(dev)) ?
  706. roundup_pow_of_two(mlx4_master_get_num_eqs(dev)) :
  707. dev->caps.num_eqs;
  708. err = mlx4_init_icm_table(dev, &priv->eq_table.cmpt_table,
  709. cmpt_base +
  710. ((u64) (MLX4_CMPT_TYPE_EQ *
  711. cmpt_entry_sz) << MLX4_CMPT_SHIFT),
  712. cmpt_entry_sz, num_eqs, num_eqs, 0, 0);
  713. if (err)
  714. goto err_cq;
  715. return 0;
  716. err_cq:
  717. mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
  718. err_srq:
  719. mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
  720. err_qp:
  721. mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
  722. err:
  723. return err;
  724. }
  725. static int mlx4_init_icm(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap,
  726. struct mlx4_init_hca_param *init_hca, u64 icm_size)
  727. {
  728. struct mlx4_priv *priv = mlx4_priv(dev);
  729. u64 aux_pages;
  730. int num_eqs;
  731. int err;
  732. err = mlx4_SET_ICM_SIZE(dev, icm_size, &aux_pages);
  733. if (err) {
  734. mlx4_err(dev, "SET_ICM_SIZE command failed, aborting.\n");
  735. return err;
  736. }
  737. mlx4_dbg(dev, "%lld KB of HCA context requires %lld KB aux memory.\n",
  738. (unsigned long long) icm_size >> 10,
  739. (unsigned long long) aux_pages << 2);
  740. priv->fw.aux_icm = mlx4_alloc_icm(dev, aux_pages,
  741. GFP_HIGHUSER | __GFP_NOWARN, 0);
  742. if (!priv->fw.aux_icm) {
  743. mlx4_err(dev, "Couldn't allocate aux memory, aborting.\n");
  744. return -ENOMEM;
  745. }
  746. err = mlx4_MAP_ICM_AUX(dev, priv->fw.aux_icm);
  747. if (err) {
  748. mlx4_err(dev, "MAP_ICM_AUX command failed, aborting.\n");
  749. goto err_free_aux;
  750. }
  751. err = mlx4_init_cmpt_table(dev, init_hca->cmpt_base, dev_cap->cmpt_entry_sz);
  752. if (err) {
  753. mlx4_err(dev, "Failed to map cMPT context memory, aborting.\n");
  754. goto err_unmap_aux;
  755. }
  756. num_eqs = (mlx4_is_master(dev)) ?
  757. roundup_pow_of_two(mlx4_master_get_num_eqs(dev)) :
  758. dev->caps.num_eqs;
  759. err = mlx4_init_icm_table(dev, &priv->eq_table.table,
  760. init_hca->eqc_base, dev_cap->eqc_entry_sz,
  761. num_eqs, num_eqs, 0, 0);
  762. if (err) {
  763. mlx4_err(dev, "Failed to map EQ context memory, aborting.\n");
  764. goto err_unmap_cmpt;
  765. }
  766. /*
  767. * Reserved MTT entries must be aligned up to a cacheline
  768. * boundary, since the FW will write to them, while the driver
  769. * writes to all other MTT entries. (The variable
  770. * dev->caps.mtt_entry_sz below is really the MTT segment
  771. * size, not the raw entry size)
  772. */
  773. dev->caps.reserved_mtts =
  774. ALIGN(dev->caps.reserved_mtts * dev->caps.mtt_entry_sz,
  775. dma_get_cache_alignment()) / dev->caps.mtt_entry_sz;
  776. err = mlx4_init_icm_table(dev, &priv->mr_table.mtt_table,
  777. init_hca->mtt_base,
  778. dev->caps.mtt_entry_sz,
  779. dev->caps.num_mtts,
  780. dev->caps.reserved_mtts, 1, 0);
  781. if (err) {
  782. mlx4_err(dev, "Failed to map MTT context memory, aborting.\n");
  783. goto err_unmap_eq;
  784. }
  785. err = mlx4_init_icm_table(dev, &priv->mr_table.dmpt_table,
  786. init_hca->dmpt_base,
  787. dev_cap->dmpt_entry_sz,
  788. dev->caps.num_mpts,
  789. dev->caps.reserved_mrws, 1, 1);
  790. if (err) {
  791. mlx4_err(dev, "Failed to map dMPT context memory, aborting.\n");
  792. goto err_unmap_mtt;
  793. }
  794. err = mlx4_init_icm_table(dev, &priv->qp_table.qp_table,
  795. init_hca->qpc_base,
  796. dev_cap->qpc_entry_sz,
  797. dev->caps.num_qps,
  798. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  799. 0, 0);
  800. if (err) {
  801. mlx4_err(dev, "Failed to map QP context memory, aborting.\n");
  802. goto err_unmap_dmpt;
  803. }
  804. err = mlx4_init_icm_table(dev, &priv->qp_table.auxc_table,
  805. init_hca->auxc_base,
  806. dev_cap->aux_entry_sz,
  807. dev->caps.num_qps,
  808. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  809. 0, 0);
  810. if (err) {
  811. mlx4_err(dev, "Failed to map AUXC context memory, aborting.\n");
  812. goto err_unmap_qp;
  813. }
  814. err = mlx4_init_icm_table(dev, &priv->qp_table.altc_table,
  815. init_hca->altc_base,
  816. dev_cap->altc_entry_sz,
  817. dev->caps.num_qps,
  818. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  819. 0, 0);
  820. if (err) {
  821. mlx4_err(dev, "Failed to map ALTC context memory, aborting.\n");
  822. goto err_unmap_auxc;
  823. }
  824. err = mlx4_init_icm_table(dev, &priv->qp_table.rdmarc_table,
  825. init_hca->rdmarc_base,
  826. dev_cap->rdmarc_entry_sz << priv->qp_table.rdmarc_shift,
  827. dev->caps.num_qps,
  828. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  829. 0, 0);
  830. if (err) {
  831. mlx4_err(dev, "Failed to map RDMARC context memory, aborting\n");
  832. goto err_unmap_altc;
  833. }
  834. err = mlx4_init_icm_table(dev, &priv->cq_table.table,
  835. init_hca->cqc_base,
  836. dev_cap->cqc_entry_sz,
  837. dev->caps.num_cqs,
  838. dev->caps.reserved_cqs, 0, 0);
  839. if (err) {
  840. mlx4_err(dev, "Failed to map CQ context memory, aborting.\n");
  841. goto err_unmap_rdmarc;
  842. }
  843. err = mlx4_init_icm_table(dev, &priv->srq_table.table,
  844. init_hca->srqc_base,
  845. dev_cap->srq_entry_sz,
  846. dev->caps.num_srqs,
  847. dev->caps.reserved_srqs, 0, 0);
  848. if (err) {
  849. mlx4_err(dev, "Failed to map SRQ context memory, aborting.\n");
  850. goto err_unmap_cq;
  851. }
  852. /*
  853. * It's not strictly required, but for simplicity just map the
  854. * whole multicast group table now. The table isn't very big
  855. * and it's a lot easier than trying to track ref counts.
  856. */
  857. err = mlx4_init_icm_table(dev, &priv->mcg_table.table,
  858. init_hca->mc_base,
  859. mlx4_get_mgm_entry_size(dev),
  860. dev->caps.num_mgms + dev->caps.num_amgms,
  861. dev->caps.num_mgms + dev->caps.num_amgms,
  862. 0, 0);
  863. if (err) {
  864. mlx4_err(dev, "Failed to map MCG context memory, aborting.\n");
  865. goto err_unmap_srq;
  866. }
  867. return 0;
  868. err_unmap_srq:
  869. mlx4_cleanup_icm_table(dev, &priv->srq_table.table);
  870. err_unmap_cq:
  871. mlx4_cleanup_icm_table(dev, &priv->cq_table.table);
  872. err_unmap_rdmarc:
  873. mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table);
  874. err_unmap_altc:
  875. mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table);
  876. err_unmap_auxc:
  877. mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table);
  878. err_unmap_qp:
  879. mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table);
  880. err_unmap_dmpt:
  881. mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table);
  882. err_unmap_mtt:
  883. mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table);
  884. err_unmap_eq:
  885. mlx4_cleanup_icm_table(dev, &priv->eq_table.table);
  886. err_unmap_cmpt:
  887. mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table);
  888. mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
  889. mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
  890. mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
  891. err_unmap_aux:
  892. mlx4_UNMAP_ICM_AUX(dev);
  893. err_free_aux:
  894. mlx4_free_icm(dev, priv->fw.aux_icm, 0);
  895. return err;
  896. }
  897. static void mlx4_free_icms(struct mlx4_dev *dev)
  898. {
  899. struct mlx4_priv *priv = mlx4_priv(dev);
  900. mlx4_cleanup_icm_table(dev, &priv->mcg_table.table);
  901. mlx4_cleanup_icm_table(dev, &priv->srq_table.table);
  902. mlx4_cleanup_icm_table(dev, &priv->cq_table.table);
  903. mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table);
  904. mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table);
  905. mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table);
  906. mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table);
  907. mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table);
  908. mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table);
  909. mlx4_cleanup_icm_table(dev, &priv->eq_table.table);
  910. mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table);
  911. mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
  912. mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
  913. mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
  914. mlx4_UNMAP_ICM_AUX(dev);
  915. mlx4_free_icm(dev, priv->fw.aux_icm, 0);
  916. }
  917. static void mlx4_slave_exit(struct mlx4_dev *dev)
  918. {
  919. struct mlx4_priv *priv = mlx4_priv(dev);
  920. down(&priv->cmd.slave_sem);
  921. if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, MLX4_COMM_TIME))
  922. mlx4_warn(dev, "Failed to close slave function.\n");
  923. up(&priv->cmd.slave_sem);
  924. }
  925. static int map_bf_area(struct mlx4_dev *dev)
  926. {
  927. struct mlx4_priv *priv = mlx4_priv(dev);
  928. resource_size_t bf_start;
  929. resource_size_t bf_len;
  930. int err = 0;
  931. if (!dev->caps.bf_reg_size)
  932. return -ENXIO;
  933. bf_start = pci_resource_start(dev->pdev, 2) +
  934. (dev->caps.num_uars << PAGE_SHIFT);
  935. bf_len = pci_resource_len(dev->pdev, 2) -
  936. (dev->caps.num_uars << PAGE_SHIFT);
  937. priv->bf_mapping = io_mapping_create_wc(bf_start, bf_len);
  938. if (!priv->bf_mapping)
  939. err = -ENOMEM;
  940. return err;
  941. }
  942. static void unmap_bf_area(struct mlx4_dev *dev)
  943. {
  944. if (mlx4_priv(dev)->bf_mapping)
  945. io_mapping_free(mlx4_priv(dev)->bf_mapping);
  946. }
  947. static void mlx4_close_hca(struct mlx4_dev *dev)
  948. {
  949. unmap_bf_area(dev);
  950. if (mlx4_is_slave(dev))
  951. mlx4_slave_exit(dev);
  952. else {
  953. mlx4_CLOSE_HCA(dev, 0);
  954. mlx4_free_icms(dev);
  955. mlx4_UNMAP_FA(dev);
  956. mlx4_free_icm(dev, mlx4_priv(dev)->fw.fw_icm, 0);
  957. }
  958. }
  959. static int mlx4_init_slave(struct mlx4_dev *dev)
  960. {
  961. struct mlx4_priv *priv = mlx4_priv(dev);
  962. u64 dma = (u64) priv->mfunc.vhcr_dma;
  963. int num_of_reset_retries = NUM_OF_RESET_RETRIES;
  964. int ret_from_reset = 0;
  965. u32 slave_read;
  966. u32 cmd_channel_ver;
  967. down(&priv->cmd.slave_sem);
  968. priv->cmd.max_cmds = 1;
  969. mlx4_warn(dev, "Sending reset\n");
  970. ret_from_reset = mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0,
  971. MLX4_COMM_TIME);
  972. /* if we are in the middle of flr the slave will try
  973. * NUM_OF_RESET_RETRIES times before leaving.*/
  974. if (ret_from_reset) {
  975. if (MLX4_DELAY_RESET_SLAVE == ret_from_reset) {
  976. msleep(SLEEP_TIME_IN_RESET);
  977. while (ret_from_reset && num_of_reset_retries) {
  978. mlx4_warn(dev, "slave is currently in the"
  979. "middle of FLR. retrying..."
  980. "(try num:%d)\n",
  981. (NUM_OF_RESET_RETRIES -
  982. num_of_reset_retries + 1));
  983. ret_from_reset =
  984. mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET,
  985. 0, MLX4_COMM_TIME);
  986. num_of_reset_retries = num_of_reset_retries - 1;
  987. }
  988. } else
  989. goto err;
  990. }
  991. /* check the driver version - the slave I/F revision
  992. * must match the master's */
  993. slave_read = swab32(readl(&priv->mfunc.comm->slave_read));
  994. cmd_channel_ver = mlx4_comm_get_version();
  995. if (MLX4_COMM_GET_IF_REV(cmd_channel_ver) !=
  996. MLX4_COMM_GET_IF_REV(slave_read)) {
  997. mlx4_err(dev, "slave driver version is not supported"
  998. " by the master\n");
  999. goto err;
  1000. }
  1001. mlx4_warn(dev, "Sending vhcr0\n");
  1002. if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR0, dma >> 48,
  1003. MLX4_COMM_TIME))
  1004. goto err;
  1005. if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR1, dma >> 32,
  1006. MLX4_COMM_TIME))
  1007. goto err;
  1008. if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR2, dma >> 16,
  1009. MLX4_COMM_TIME))
  1010. goto err;
  1011. if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR_EN, dma, MLX4_COMM_TIME))
  1012. goto err;
  1013. up(&priv->cmd.slave_sem);
  1014. return 0;
  1015. err:
  1016. mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, 0);
  1017. up(&priv->cmd.slave_sem);
  1018. return -EIO;
  1019. }
  1020. static int mlx4_init_hca(struct mlx4_dev *dev)
  1021. {
  1022. struct mlx4_priv *priv = mlx4_priv(dev);
  1023. struct mlx4_adapter adapter;
  1024. struct mlx4_dev_cap dev_cap;
  1025. struct mlx4_mod_stat_cfg mlx4_cfg;
  1026. struct mlx4_profile profile;
  1027. struct mlx4_init_hca_param init_hca;
  1028. u64 icm_size;
  1029. int err;
  1030. if (!mlx4_is_slave(dev)) {
  1031. err = mlx4_QUERY_FW(dev);
  1032. if (err) {
  1033. if (err == -EACCES)
  1034. mlx4_info(dev, "non-primary physical function, skipping.\n");
  1035. else
  1036. mlx4_err(dev, "QUERY_FW command failed, aborting.\n");
  1037. goto unmap_bf;
  1038. }
  1039. err = mlx4_load_fw(dev);
  1040. if (err) {
  1041. mlx4_err(dev, "Failed to start FW, aborting.\n");
  1042. goto unmap_bf;
  1043. }
  1044. mlx4_cfg.log_pg_sz_m = 1;
  1045. mlx4_cfg.log_pg_sz = 0;
  1046. err = mlx4_MOD_STAT_CFG(dev, &mlx4_cfg);
  1047. if (err)
  1048. mlx4_warn(dev, "Failed to override log_pg_sz parameter\n");
  1049. err = mlx4_dev_cap(dev, &dev_cap);
  1050. if (err) {
  1051. mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n");
  1052. goto err_stop_fw;
  1053. }
  1054. profile = default_profile;
  1055. icm_size = mlx4_make_profile(dev, &profile, &dev_cap,
  1056. &init_hca);
  1057. if ((long long) icm_size < 0) {
  1058. err = icm_size;
  1059. goto err_stop_fw;
  1060. }
  1061. dev->caps.max_fmr_maps = (1 << (32 - ilog2(dev->caps.num_mpts))) - 1;
  1062. init_hca.log_uar_sz = ilog2(dev->caps.num_uars);
  1063. init_hca.uar_page_sz = PAGE_SHIFT - 12;
  1064. err = mlx4_init_icm(dev, &dev_cap, &init_hca, icm_size);
  1065. if (err)
  1066. goto err_stop_fw;
  1067. err = mlx4_INIT_HCA(dev, &init_hca);
  1068. if (err) {
  1069. mlx4_err(dev, "INIT_HCA command failed, aborting.\n");
  1070. goto err_free_icm;
  1071. }
  1072. } else {
  1073. err = mlx4_init_slave(dev);
  1074. if (err) {
  1075. mlx4_err(dev, "Failed to initialize slave\n");
  1076. goto unmap_bf;
  1077. }
  1078. err = mlx4_slave_cap(dev);
  1079. if (err) {
  1080. mlx4_err(dev, "Failed to obtain slave caps\n");
  1081. goto err_close;
  1082. }
  1083. }
  1084. if (map_bf_area(dev))
  1085. mlx4_dbg(dev, "Failed to map blue flame area\n");
  1086. /*Only the master set the ports, all the rest got it from it.*/
  1087. if (!mlx4_is_slave(dev))
  1088. mlx4_set_port_mask(dev);
  1089. err = mlx4_QUERY_ADAPTER(dev, &adapter);
  1090. if (err) {
  1091. mlx4_err(dev, "QUERY_ADAPTER command failed, aborting.\n");
  1092. goto err_close;
  1093. }
  1094. priv->eq_table.inta_pin = adapter.inta_pin;
  1095. memcpy(dev->board_id, adapter.board_id, sizeof dev->board_id);
  1096. return 0;
  1097. err_close:
  1098. mlx4_close_hca(dev);
  1099. err_free_icm:
  1100. if (!mlx4_is_slave(dev))
  1101. mlx4_free_icms(dev);
  1102. err_stop_fw:
  1103. if (!mlx4_is_slave(dev)) {
  1104. mlx4_UNMAP_FA(dev);
  1105. mlx4_free_icm(dev, priv->fw.fw_icm, 0);
  1106. }
  1107. unmap_bf:
  1108. unmap_bf_area(dev);
  1109. return err;
  1110. }
  1111. static int mlx4_init_counters_table(struct mlx4_dev *dev)
  1112. {
  1113. struct mlx4_priv *priv = mlx4_priv(dev);
  1114. int nent;
  1115. if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS))
  1116. return -ENOENT;
  1117. nent = dev->caps.max_counters;
  1118. return mlx4_bitmap_init(&priv->counters_bitmap, nent, nent - 1, 0, 0);
  1119. }
  1120. static void mlx4_cleanup_counters_table(struct mlx4_dev *dev)
  1121. {
  1122. mlx4_bitmap_cleanup(&mlx4_priv(dev)->counters_bitmap);
  1123. }
  1124. int mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx)
  1125. {
  1126. struct mlx4_priv *priv = mlx4_priv(dev);
  1127. if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS))
  1128. return -ENOENT;
  1129. *idx = mlx4_bitmap_alloc(&priv->counters_bitmap);
  1130. if (*idx == -1)
  1131. return -ENOMEM;
  1132. return 0;
  1133. }
  1134. EXPORT_SYMBOL_GPL(mlx4_counter_alloc);
  1135. void mlx4_counter_free(struct mlx4_dev *dev, u32 idx)
  1136. {
  1137. mlx4_bitmap_free(&mlx4_priv(dev)->counters_bitmap, idx);
  1138. return;
  1139. }
  1140. EXPORT_SYMBOL_GPL(mlx4_counter_free);
  1141. static int mlx4_setup_hca(struct mlx4_dev *dev)
  1142. {
  1143. struct mlx4_priv *priv = mlx4_priv(dev);
  1144. int err;
  1145. int port;
  1146. __be32 ib_port_default_caps;
  1147. err = mlx4_init_uar_table(dev);
  1148. if (err) {
  1149. mlx4_err(dev, "Failed to initialize "
  1150. "user access region table, aborting.\n");
  1151. return err;
  1152. }
  1153. err = mlx4_uar_alloc(dev, &priv->driver_uar);
  1154. if (err) {
  1155. mlx4_err(dev, "Failed to allocate driver access region, "
  1156. "aborting.\n");
  1157. goto err_uar_table_free;
  1158. }
  1159. priv->kar = ioremap((phys_addr_t) priv->driver_uar.pfn << PAGE_SHIFT, PAGE_SIZE);
  1160. if (!priv->kar) {
  1161. mlx4_err(dev, "Couldn't map kernel access region, "
  1162. "aborting.\n");
  1163. err = -ENOMEM;
  1164. goto err_uar_free;
  1165. }
  1166. err = mlx4_init_pd_table(dev);
  1167. if (err) {
  1168. mlx4_err(dev, "Failed to initialize "
  1169. "protection domain table, aborting.\n");
  1170. goto err_kar_unmap;
  1171. }
  1172. err = mlx4_init_xrcd_table(dev);
  1173. if (err) {
  1174. mlx4_err(dev, "Failed to initialize "
  1175. "reliable connection domain table, aborting.\n");
  1176. goto err_pd_table_free;
  1177. }
  1178. err = mlx4_init_mr_table(dev);
  1179. if (err) {
  1180. mlx4_err(dev, "Failed to initialize "
  1181. "memory region table, aborting.\n");
  1182. goto err_xrcd_table_free;
  1183. }
  1184. err = mlx4_init_eq_table(dev);
  1185. if (err) {
  1186. mlx4_err(dev, "Failed to initialize "
  1187. "event queue table, aborting.\n");
  1188. goto err_mr_table_free;
  1189. }
  1190. err = mlx4_cmd_use_events(dev);
  1191. if (err) {
  1192. mlx4_err(dev, "Failed to switch to event-driven "
  1193. "firmware commands, aborting.\n");
  1194. goto err_eq_table_free;
  1195. }
  1196. err = mlx4_NOP(dev);
  1197. if (err) {
  1198. if (dev->flags & MLX4_FLAG_MSI_X) {
  1199. mlx4_warn(dev, "NOP command failed to generate MSI-X "
  1200. "interrupt IRQ %d).\n",
  1201. priv->eq_table.eq[dev->caps.num_comp_vectors].irq);
  1202. mlx4_warn(dev, "Trying again without MSI-X.\n");
  1203. } else {
  1204. mlx4_err(dev, "NOP command failed to generate interrupt "
  1205. "(IRQ %d), aborting.\n",
  1206. priv->eq_table.eq[dev->caps.num_comp_vectors].irq);
  1207. mlx4_err(dev, "BIOS or ACPI interrupt routing problem?\n");
  1208. }
  1209. goto err_cmd_poll;
  1210. }
  1211. mlx4_dbg(dev, "NOP command IRQ test passed\n");
  1212. err = mlx4_init_cq_table(dev);
  1213. if (err) {
  1214. mlx4_err(dev, "Failed to initialize "
  1215. "completion queue table, aborting.\n");
  1216. goto err_cmd_poll;
  1217. }
  1218. err = mlx4_init_srq_table(dev);
  1219. if (err) {
  1220. mlx4_err(dev, "Failed to initialize "
  1221. "shared receive queue table, aborting.\n");
  1222. goto err_cq_table_free;
  1223. }
  1224. err = mlx4_init_qp_table(dev);
  1225. if (err) {
  1226. mlx4_err(dev, "Failed to initialize "
  1227. "queue pair table, aborting.\n");
  1228. goto err_srq_table_free;
  1229. }
  1230. if (!mlx4_is_slave(dev)) {
  1231. err = mlx4_init_mcg_table(dev);
  1232. if (err) {
  1233. mlx4_err(dev, "Failed to initialize "
  1234. "multicast group table, aborting.\n");
  1235. goto err_qp_table_free;
  1236. }
  1237. }
  1238. err = mlx4_init_counters_table(dev);
  1239. if (err && err != -ENOENT) {
  1240. mlx4_err(dev, "Failed to initialize counters table, aborting.\n");
  1241. goto err_mcg_table_free;
  1242. }
  1243. if (!mlx4_is_slave(dev)) {
  1244. for (port = 1; port <= dev->caps.num_ports; port++) {
  1245. ib_port_default_caps = 0;
  1246. err = mlx4_get_port_ib_caps(dev, port,
  1247. &ib_port_default_caps);
  1248. if (err)
  1249. mlx4_warn(dev, "failed to get port %d default "
  1250. "ib capabilities (%d). Continuing "
  1251. "with caps = 0\n", port, err);
  1252. dev->caps.ib_port_def_cap[port] = ib_port_default_caps;
  1253. if (mlx4_is_mfunc(dev))
  1254. dev->caps.port_ib_mtu[port] = IB_MTU_2048;
  1255. else
  1256. dev->caps.port_ib_mtu[port] = IB_MTU_4096;
  1257. err = mlx4_SET_PORT(dev, port);
  1258. if (err) {
  1259. mlx4_err(dev, "Failed to set port %d, aborting\n",
  1260. port);
  1261. goto err_counters_table_free;
  1262. }
  1263. }
  1264. }
  1265. return 0;
  1266. err_counters_table_free:
  1267. mlx4_cleanup_counters_table(dev);
  1268. err_mcg_table_free:
  1269. mlx4_cleanup_mcg_table(dev);
  1270. err_qp_table_free:
  1271. mlx4_cleanup_qp_table(dev);
  1272. err_srq_table_free:
  1273. mlx4_cleanup_srq_table(dev);
  1274. err_cq_table_free:
  1275. mlx4_cleanup_cq_table(dev);
  1276. err_cmd_poll:
  1277. mlx4_cmd_use_polling(dev);
  1278. err_eq_table_free:
  1279. mlx4_cleanup_eq_table(dev);
  1280. err_mr_table_free:
  1281. mlx4_cleanup_mr_table(dev);
  1282. err_xrcd_table_free:
  1283. mlx4_cleanup_xrcd_table(dev);
  1284. err_pd_table_free:
  1285. mlx4_cleanup_pd_table(dev);
  1286. err_kar_unmap:
  1287. iounmap(priv->kar);
  1288. err_uar_free:
  1289. mlx4_uar_free(dev, &priv->driver_uar);
  1290. err_uar_table_free:
  1291. mlx4_cleanup_uar_table(dev);
  1292. return err;
  1293. }
  1294. static void mlx4_enable_msi_x(struct mlx4_dev *dev)
  1295. {
  1296. struct mlx4_priv *priv = mlx4_priv(dev);
  1297. struct msix_entry *entries;
  1298. int nreq = min_t(int, dev->caps.num_ports *
  1299. min_t(int, num_online_cpus() + 1, MAX_MSIX_P_PORT)
  1300. + MSIX_LEGACY_SZ, MAX_MSIX);
  1301. int err;
  1302. int i;
  1303. if (msi_x) {
  1304. /* In multifunction mode each function gets 2 msi-X vectors
  1305. * one for data path completions anf the other for asynch events
  1306. * or command completions */
  1307. if (mlx4_is_mfunc(dev)) {
  1308. nreq = 2;
  1309. } else {
  1310. nreq = min_t(int, dev->caps.num_eqs -
  1311. dev->caps.reserved_eqs, nreq);
  1312. }
  1313. entries = kcalloc(nreq, sizeof *entries, GFP_KERNEL);
  1314. if (!entries)
  1315. goto no_msi;
  1316. for (i = 0; i < nreq; ++i)
  1317. entries[i].entry = i;
  1318. retry:
  1319. err = pci_enable_msix(dev->pdev, entries, nreq);
  1320. if (err) {
  1321. /* Try again if at least 2 vectors are available */
  1322. if (err > 1) {
  1323. mlx4_info(dev, "Requested %d vectors, "
  1324. "but only %d MSI-X vectors available, "
  1325. "trying again\n", nreq, err);
  1326. nreq = err;
  1327. goto retry;
  1328. }
  1329. kfree(entries);
  1330. goto no_msi;
  1331. }
  1332. if (nreq <
  1333. MSIX_LEGACY_SZ + dev->caps.num_ports * MIN_MSIX_P_PORT) {
  1334. /*Working in legacy mode , all EQ's shared*/
  1335. dev->caps.comp_pool = 0;
  1336. dev->caps.num_comp_vectors = nreq - 1;
  1337. } else {
  1338. dev->caps.comp_pool = nreq - MSIX_LEGACY_SZ;
  1339. dev->caps.num_comp_vectors = MSIX_LEGACY_SZ - 1;
  1340. }
  1341. for (i = 0; i < nreq; ++i)
  1342. priv->eq_table.eq[i].irq = entries[i].vector;
  1343. dev->flags |= MLX4_FLAG_MSI_X;
  1344. kfree(entries);
  1345. return;
  1346. }
  1347. no_msi:
  1348. dev->caps.num_comp_vectors = 1;
  1349. dev->caps.comp_pool = 0;
  1350. for (i = 0; i < 2; ++i)
  1351. priv->eq_table.eq[i].irq = dev->pdev->irq;
  1352. }
  1353. static int mlx4_init_port_info(struct mlx4_dev *dev, int port)
  1354. {
  1355. struct mlx4_port_info *info = &mlx4_priv(dev)->port[port];
  1356. int err = 0;
  1357. info->dev = dev;
  1358. info->port = port;
  1359. if (!mlx4_is_slave(dev)) {
  1360. INIT_RADIX_TREE(&info->mac_tree, GFP_KERNEL);
  1361. mlx4_init_mac_table(dev, &info->mac_table);
  1362. mlx4_init_vlan_table(dev, &info->vlan_table);
  1363. info->base_qpn =
  1364. dev->caps.reserved_qps_base[MLX4_QP_REGION_ETH_ADDR] +
  1365. (port - 1) * (1 << log_num_mac);
  1366. }
  1367. sprintf(info->dev_name, "mlx4_port%d", port);
  1368. info->port_attr.attr.name = info->dev_name;
  1369. if (mlx4_is_mfunc(dev))
  1370. info->port_attr.attr.mode = S_IRUGO;
  1371. else {
  1372. info->port_attr.attr.mode = S_IRUGO | S_IWUSR;
  1373. info->port_attr.store = set_port_type;
  1374. }
  1375. info->port_attr.show = show_port_type;
  1376. sysfs_attr_init(&info->port_attr.attr);
  1377. err = device_create_file(&dev->pdev->dev, &info->port_attr);
  1378. if (err) {
  1379. mlx4_err(dev, "Failed to create file for port %d\n", port);
  1380. info->port = -1;
  1381. }
  1382. sprintf(info->dev_mtu_name, "mlx4_port%d_mtu", port);
  1383. info->port_mtu_attr.attr.name = info->dev_mtu_name;
  1384. if (mlx4_is_mfunc(dev))
  1385. info->port_mtu_attr.attr.mode = S_IRUGO;
  1386. else {
  1387. info->port_mtu_attr.attr.mode = S_IRUGO | S_IWUSR;
  1388. info->port_mtu_attr.store = set_port_ib_mtu;
  1389. }
  1390. info->port_mtu_attr.show = show_port_ib_mtu;
  1391. sysfs_attr_init(&info->port_mtu_attr.attr);
  1392. err = device_create_file(&dev->pdev->dev, &info->port_mtu_attr);
  1393. if (err) {
  1394. mlx4_err(dev, "Failed to create mtu file for port %d\n", port);
  1395. device_remove_file(&info->dev->pdev->dev, &info->port_attr);
  1396. info->port = -1;
  1397. }
  1398. return err;
  1399. }
  1400. static void mlx4_cleanup_port_info(struct mlx4_port_info *info)
  1401. {
  1402. if (info->port < 0)
  1403. return;
  1404. device_remove_file(&info->dev->pdev->dev, &info->port_attr);
  1405. device_remove_file(&info->dev->pdev->dev, &info->port_mtu_attr);
  1406. }
  1407. static int mlx4_init_steering(struct mlx4_dev *dev)
  1408. {
  1409. struct mlx4_priv *priv = mlx4_priv(dev);
  1410. int num_entries = dev->caps.num_ports;
  1411. int i, j;
  1412. priv->steer = kzalloc(sizeof(struct mlx4_steer) * num_entries, GFP_KERNEL);
  1413. if (!priv->steer)
  1414. return -ENOMEM;
  1415. for (i = 0; i < num_entries; i++)
  1416. for (j = 0; j < MLX4_NUM_STEERS; j++) {
  1417. INIT_LIST_HEAD(&priv->steer[i].promisc_qps[j]);
  1418. INIT_LIST_HEAD(&priv->steer[i].steer_entries[j]);
  1419. }
  1420. return 0;
  1421. }
  1422. static void mlx4_clear_steering(struct mlx4_dev *dev)
  1423. {
  1424. struct mlx4_priv *priv = mlx4_priv(dev);
  1425. struct mlx4_steer_index *entry, *tmp_entry;
  1426. struct mlx4_promisc_qp *pqp, *tmp_pqp;
  1427. int num_entries = dev->caps.num_ports;
  1428. int i, j;
  1429. for (i = 0; i < num_entries; i++) {
  1430. for (j = 0; j < MLX4_NUM_STEERS; j++) {
  1431. list_for_each_entry_safe(pqp, tmp_pqp,
  1432. &priv->steer[i].promisc_qps[j],
  1433. list) {
  1434. list_del(&pqp->list);
  1435. kfree(pqp);
  1436. }
  1437. list_for_each_entry_safe(entry, tmp_entry,
  1438. &priv->steer[i].steer_entries[j],
  1439. list) {
  1440. list_del(&entry->list);
  1441. list_for_each_entry_safe(pqp, tmp_pqp,
  1442. &entry->duplicates,
  1443. list) {
  1444. list_del(&pqp->list);
  1445. kfree(pqp);
  1446. }
  1447. kfree(entry);
  1448. }
  1449. }
  1450. }
  1451. kfree(priv->steer);
  1452. }
  1453. static int extended_func_num(struct pci_dev *pdev)
  1454. {
  1455. return PCI_SLOT(pdev->devfn) * 8 + PCI_FUNC(pdev->devfn);
  1456. }
  1457. #define MLX4_OWNER_BASE 0x8069c
  1458. #define MLX4_OWNER_SIZE 4
  1459. static int mlx4_get_ownership(struct mlx4_dev *dev)
  1460. {
  1461. void __iomem *owner;
  1462. u32 ret;
  1463. owner = ioremap(pci_resource_start(dev->pdev, 0) + MLX4_OWNER_BASE,
  1464. MLX4_OWNER_SIZE);
  1465. if (!owner) {
  1466. mlx4_err(dev, "Failed to obtain ownership bit\n");
  1467. return -ENOMEM;
  1468. }
  1469. ret = readl(owner);
  1470. iounmap(owner);
  1471. return (int) !!ret;
  1472. }
  1473. static void mlx4_free_ownership(struct mlx4_dev *dev)
  1474. {
  1475. void __iomem *owner;
  1476. owner = ioremap(pci_resource_start(dev->pdev, 0) + MLX4_OWNER_BASE,
  1477. MLX4_OWNER_SIZE);
  1478. if (!owner) {
  1479. mlx4_err(dev, "Failed to obtain ownership bit\n");
  1480. return;
  1481. }
  1482. writel(0, owner);
  1483. msleep(1000);
  1484. iounmap(owner);
  1485. }
  1486. static int __mlx4_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  1487. {
  1488. struct mlx4_priv *priv;
  1489. struct mlx4_dev *dev;
  1490. int err;
  1491. int port;
  1492. pr_info(DRV_NAME ": Initializing %s\n", pci_name(pdev));
  1493. err = pci_enable_device(pdev);
  1494. if (err) {
  1495. dev_err(&pdev->dev, "Cannot enable PCI device, "
  1496. "aborting.\n");
  1497. return err;
  1498. }
  1499. if (num_vfs > MLX4_MAX_NUM_VF) {
  1500. printk(KERN_ERR "There are more VF's (%d) than allowed(%d)\n",
  1501. num_vfs, MLX4_MAX_NUM_VF);
  1502. return -EINVAL;
  1503. }
  1504. /*
  1505. * Check for BARs.
  1506. */
  1507. if (((id == NULL) || !(id->driver_data & MLX4_VF)) &&
  1508. !(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  1509. dev_err(&pdev->dev, "Missing DCS, aborting."
  1510. "(id == 0X%p, id->driver_data: 0x%lx,"
  1511. " pci_resource_flags(pdev, 0):0x%lx)\n", id,
  1512. id ? id->driver_data : 0, pci_resource_flags(pdev, 0));
  1513. err = -ENODEV;
  1514. goto err_disable_pdev;
  1515. }
  1516. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  1517. dev_err(&pdev->dev, "Missing UAR, aborting.\n");
  1518. err = -ENODEV;
  1519. goto err_disable_pdev;
  1520. }
  1521. err = pci_request_regions(pdev, DRV_NAME);
  1522. if (err) {
  1523. dev_err(&pdev->dev, "Couldn't get PCI resources, aborting\n");
  1524. goto err_disable_pdev;
  1525. }
  1526. pci_set_master(pdev);
  1527. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  1528. if (err) {
  1529. dev_warn(&pdev->dev, "Warning: couldn't set 64-bit PCI DMA mask.\n");
  1530. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  1531. if (err) {
  1532. dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting.\n");
  1533. goto err_release_regions;
  1534. }
  1535. }
  1536. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  1537. if (err) {
  1538. dev_warn(&pdev->dev, "Warning: couldn't set 64-bit "
  1539. "consistent PCI DMA mask.\n");
  1540. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  1541. if (err) {
  1542. dev_err(&pdev->dev, "Can't set consistent PCI DMA mask, "
  1543. "aborting.\n");
  1544. goto err_release_regions;
  1545. }
  1546. }
  1547. /* Allow large DMA segments, up to the firmware limit of 1 GB */
  1548. dma_set_max_seg_size(&pdev->dev, 1024 * 1024 * 1024);
  1549. priv = kzalloc(sizeof *priv, GFP_KERNEL);
  1550. if (!priv) {
  1551. dev_err(&pdev->dev, "Device struct alloc failed, "
  1552. "aborting.\n");
  1553. err = -ENOMEM;
  1554. goto err_release_regions;
  1555. }
  1556. dev = &priv->dev;
  1557. dev->pdev = pdev;
  1558. INIT_LIST_HEAD(&priv->ctx_list);
  1559. spin_lock_init(&priv->ctx_lock);
  1560. mutex_init(&priv->port_mutex);
  1561. INIT_LIST_HEAD(&priv->pgdir_list);
  1562. mutex_init(&priv->pgdir_mutex);
  1563. INIT_LIST_HEAD(&priv->bf_list);
  1564. mutex_init(&priv->bf_mutex);
  1565. dev->rev_id = pdev->revision;
  1566. /* Detect if this device is a virtual function */
  1567. if (id && id->driver_data & MLX4_VF) {
  1568. /* When acting as pf, we normally skip vfs unless explicitly
  1569. * requested to probe them. */
  1570. if (num_vfs && extended_func_num(pdev) > probe_vf) {
  1571. mlx4_warn(dev, "Skipping virtual function:%d\n",
  1572. extended_func_num(pdev));
  1573. err = -ENODEV;
  1574. goto err_free_dev;
  1575. }
  1576. mlx4_warn(dev, "Detected virtual function - running in slave mode\n");
  1577. dev->flags |= MLX4_FLAG_SLAVE;
  1578. } else {
  1579. /* We reset the device and enable SRIOV only for physical
  1580. * devices. Try to claim ownership on the device;
  1581. * if already taken, skip -- do not allow multiple PFs */
  1582. err = mlx4_get_ownership(dev);
  1583. if (err) {
  1584. if (err < 0)
  1585. goto err_free_dev;
  1586. else {
  1587. mlx4_warn(dev, "Multiple PFs not yet supported."
  1588. " Skipping PF.\n");
  1589. err = -EINVAL;
  1590. goto err_free_dev;
  1591. }
  1592. }
  1593. if (num_vfs) {
  1594. mlx4_warn(dev, "Enabling sriov with:%d vfs\n", num_vfs);
  1595. err = pci_enable_sriov(pdev, num_vfs);
  1596. if (err) {
  1597. mlx4_err(dev, "Failed to enable sriov,"
  1598. "continuing without sriov enabled"
  1599. " (err = %d).\n", err);
  1600. num_vfs = 0;
  1601. err = 0;
  1602. } else {
  1603. mlx4_warn(dev, "Running in master mode\n");
  1604. dev->flags |= MLX4_FLAG_SRIOV |
  1605. MLX4_FLAG_MASTER;
  1606. dev->num_vfs = num_vfs;
  1607. }
  1608. }
  1609. /*
  1610. * Now reset the HCA before we touch the PCI capabilities or
  1611. * attempt a firmware command, since a boot ROM may have left
  1612. * the HCA in an undefined state.
  1613. */
  1614. err = mlx4_reset(dev);
  1615. if (err) {
  1616. mlx4_err(dev, "Failed to reset HCA, aborting.\n");
  1617. goto err_rel_own;
  1618. }
  1619. }
  1620. slave_start:
  1621. if (mlx4_cmd_init(dev)) {
  1622. mlx4_err(dev, "Failed to init command interface, aborting.\n");
  1623. goto err_sriov;
  1624. }
  1625. /* In slave functions, the communication channel must be initialized
  1626. * before posting commands. Also, init num_slaves before calling
  1627. * mlx4_init_hca */
  1628. if (mlx4_is_mfunc(dev)) {
  1629. if (mlx4_is_master(dev))
  1630. dev->num_slaves = MLX4_MAX_NUM_SLAVES;
  1631. else {
  1632. dev->num_slaves = 0;
  1633. if (mlx4_multi_func_init(dev)) {
  1634. mlx4_err(dev, "Failed to init slave mfunc"
  1635. " interface, aborting.\n");
  1636. goto err_cmd;
  1637. }
  1638. }
  1639. }
  1640. err = mlx4_init_hca(dev);
  1641. if (err) {
  1642. if (err == -EACCES) {
  1643. /* Not primary Physical function
  1644. * Running in slave mode */
  1645. mlx4_cmd_cleanup(dev);
  1646. dev->flags |= MLX4_FLAG_SLAVE;
  1647. dev->flags &= ~MLX4_FLAG_MASTER;
  1648. goto slave_start;
  1649. } else
  1650. goto err_mfunc;
  1651. }
  1652. /* In master functions, the communication channel must be initialized
  1653. * after obtaining its address from fw */
  1654. if (mlx4_is_master(dev)) {
  1655. if (mlx4_multi_func_init(dev)) {
  1656. mlx4_err(dev, "Failed to init master mfunc"
  1657. "interface, aborting.\n");
  1658. goto err_close;
  1659. }
  1660. }
  1661. err = mlx4_alloc_eq_table(dev);
  1662. if (err)
  1663. goto err_master_mfunc;
  1664. priv->msix_ctl.pool_bm = 0;
  1665. mutex_init(&priv->msix_ctl.pool_lock);
  1666. mlx4_enable_msi_x(dev);
  1667. if ((mlx4_is_mfunc(dev)) &&
  1668. !(dev->flags & MLX4_FLAG_MSI_X)) {
  1669. mlx4_err(dev, "INTx is not supported in multi-function mode."
  1670. " aborting.\n");
  1671. goto err_free_eq;
  1672. }
  1673. if (!mlx4_is_slave(dev)) {
  1674. err = mlx4_init_steering(dev);
  1675. if (err)
  1676. goto err_free_eq;
  1677. }
  1678. err = mlx4_setup_hca(dev);
  1679. if (err == -EBUSY && (dev->flags & MLX4_FLAG_MSI_X) &&
  1680. !mlx4_is_mfunc(dev)) {
  1681. dev->flags &= ~MLX4_FLAG_MSI_X;
  1682. pci_disable_msix(pdev);
  1683. err = mlx4_setup_hca(dev);
  1684. }
  1685. if (err)
  1686. goto err_steer;
  1687. for (port = 1; port <= dev->caps.num_ports; port++) {
  1688. err = mlx4_init_port_info(dev, port);
  1689. if (err)
  1690. goto err_port;
  1691. }
  1692. err = mlx4_register_device(dev);
  1693. if (err)
  1694. goto err_port;
  1695. mlx4_sense_init(dev);
  1696. mlx4_start_sense(dev);
  1697. pci_set_drvdata(pdev, dev);
  1698. return 0;
  1699. err_port:
  1700. for (--port; port >= 1; --port)
  1701. mlx4_cleanup_port_info(&priv->port[port]);
  1702. mlx4_cleanup_counters_table(dev);
  1703. mlx4_cleanup_mcg_table(dev);
  1704. mlx4_cleanup_qp_table(dev);
  1705. mlx4_cleanup_srq_table(dev);
  1706. mlx4_cleanup_cq_table(dev);
  1707. mlx4_cmd_use_polling(dev);
  1708. mlx4_cleanup_eq_table(dev);
  1709. mlx4_cleanup_mr_table(dev);
  1710. mlx4_cleanup_xrcd_table(dev);
  1711. mlx4_cleanup_pd_table(dev);
  1712. mlx4_cleanup_uar_table(dev);
  1713. err_steer:
  1714. if (!mlx4_is_slave(dev))
  1715. mlx4_clear_steering(dev);
  1716. err_free_eq:
  1717. mlx4_free_eq_table(dev);
  1718. err_master_mfunc:
  1719. if (mlx4_is_master(dev))
  1720. mlx4_multi_func_cleanup(dev);
  1721. err_close:
  1722. if (dev->flags & MLX4_FLAG_MSI_X)
  1723. pci_disable_msix(pdev);
  1724. mlx4_close_hca(dev);
  1725. err_mfunc:
  1726. if (mlx4_is_slave(dev))
  1727. mlx4_multi_func_cleanup(dev);
  1728. err_cmd:
  1729. mlx4_cmd_cleanup(dev);
  1730. err_sriov:
  1731. if (num_vfs && (dev->flags & MLX4_FLAG_SRIOV))
  1732. pci_disable_sriov(pdev);
  1733. err_rel_own:
  1734. if (!mlx4_is_slave(dev))
  1735. mlx4_free_ownership(dev);
  1736. err_free_dev:
  1737. kfree(priv);
  1738. err_release_regions:
  1739. pci_release_regions(pdev);
  1740. err_disable_pdev:
  1741. pci_disable_device(pdev);
  1742. pci_set_drvdata(pdev, NULL);
  1743. return err;
  1744. }
  1745. static int __devinit mlx4_init_one(struct pci_dev *pdev,
  1746. const struct pci_device_id *id)
  1747. {
  1748. printk_once(KERN_INFO "%s", mlx4_version);
  1749. return __mlx4_init_one(pdev, id);
  1750. }
  1751. static void mlx4_remove_one(struct pci_dev *pdev)
  1752. {
  1753. struct mlx4_dev *dev = pci_get_drvdata(pdev);
  1754. struct mlx4_priv *priv = mlx4_priv(dev);
  1755. int p;
  1756. if (dev) {
  1757. /* in SRIOV it is not allowed to unload the pf's
  1758. * driver while there are alive vf's */
  1759. if (mlx4_is_master(dev)) {
  1760. if (mlx4_how_many_lives_vf(dev))
  1761. printk(KERN_ERR "Removing PF when there are assigned VF's !!!\n");
  1762. }
  1763. mlx4_stop_sense(dev);
  1764. mlx4_unregister_device(dev);
  1765. for (p = 1; p <= dev->caps.num_ports; p++) {
  1766. mlx4_cleanup_port_info(&priv->port[p]);
  1767. mlx4_CLOSE_PORT(dev, p);
  1768. }
  1769. mlx4_cleanup_counters_table(dev);
  1770. mlx4_cleanup_mcg_table(dev);
  1771. mlx4_cleanup_qp_table(dev);
  1772. mlx4_cleanup_srq_table(dev);
  1773. mlx4_cleanup_cq_table(dev);
  1774. mlx4_cmd_use_polling(dev);
  1775. mlx4_cleanup_eq_table(dev);
  1776. mlx4_cleanup_mr_table(dev);
  1777. mlx4_cleanup_xrcd_table(dev);
  1778. mlx4_cleanup_pd_table(dev);
  1779. if (mlx4_is_master(dev))
  1780. mlx4_free_resource_tracker(dev);
  1781. iounmap(priv->kar);
  1782. mlx4_uar_free(dev, &priv->driver_uar);
  1783. mlx4_cleanup_uar_table(dev);
  1784. if (!mlx4_is_slave(dev))
  1785. mlx4_clear_steering(dev);
  1786. mlx4_free_eq_table(dev);
  1787. if (mlx4_is_master(dev))
  1788. mlx4_multi_func_cleanup(dev);
  1789. mlx4_close_hca(dev);
  1790. if (mlx4_is_slave(dev))
  1791. mlx4_multi_func_cleanup(dev);
  1792. mlx4_cmd_cleanup(dev);
  1793. if (dev->flags & MLX4_FLAG_MSI_X)
  1794. pci_disable_msix(pdev);
  1795. if (num_vfs && (dev->flags & MLX4_FLAG_SRIOV)) {
  1796. mlx4_warn(dev, "Disabling sriov\n");
  1797. pci_disable_sriov(pdev);
  1798. }
  1799. if (!mlx4_is_slave(dev))
  1800. mlx4_free_ownership(dev);
  1801. kfree(priv);
  1802. pci_release_regions(pdev);
  1803. pci_disable_device(pdev);
  1804. pci_set_drvdata(pdev, NULL);
  1805. }
  1806. }
  1807. int mlx4_restart_one(struct pci_dev *pdev)
  1808. {
  1809. mlx4_remove_one(pdev);
  1810. return __mlx4_init_one(pdev, NULL);
  1811. }
  1812. static DEFINE_PCI_DEVICE_TABLE(mlx4_pci_table) = {
  1813. /* MT25408 "Hermon" SDR */
  1814. { PCI_VDEVICE(MELLANOX, 0x6340), 0 },
  1815. /* MT25408 "Hermon" DDR */
  1816. { PCI_VDEVICE(MELLANOX, 0x634a), 0 },
  1817. /* MT25408 "Hermon" QDR */
  1818. { PCI_VDEVICE(MELLANOX, 0x6354), 0 },
  1819. /* MT25408 "Hermon" DDR PCIe gen2 */
  1820. { PCI_VDEVICE(MELLANOX, 0x6732), 0 },
  1821. /* MT25408 "Hermon" QDR PCIe gen2 */
  1822. { PCI_VDEVICE(MELLANOX, 0x673c), 0 },
  1823. /* MT25408 "Hermon" EN 10GigE */
  1824. { PCI_VDEVICE(MELLANOX, 0x6368), 0 },
  1825. /* MT25408 "Hermon" EN 10GigE PCIe gen2 */
  1826. { PCI_VDEVICE(MELLANOX, 0x6750), 0 },
  1827. /* MT25458 ConnectX EN 10GBASE-T 10GigE */
  1828. { PCI_VDEVICE(MELLANOX, 0x6372), 0 },
  1829. /* MT25458 ConnectX EN 10GBASE-T+Gen2 10GigE */
  1830. { PCI_VDEVICE(MELLANOX, 0x675a), 0 },
  1831. /* MT26468 ConnectX EN 10GigE PCIe gen2*/
  1832. { PCI_VDEVICE(MELLANOX, 0x6764), 0 },
  1833. /* MT26438 ConnectX EN 40GigE PCIe gen2 5GT/s */
  1834. { PCI_VDEVICE(MELLANOX, 0x6746), 0 },
  1835. /* MT26478 ConnectX2 40GigE PCIe gen2 */
  1836. { PCI_VDEVICE(MELLANOX, 0x676e), 0 },
  1837. /* MT25400 Family [ConnectX-2 Virtual Function] */
  1838. { PCI_VDEVICE(MELLANOX, 0x1002), MLX4_VF },
  1839. /* MT27500 Family [ConnectX-3] */
  1840. { PCI_VDEVICE(MELLANOX, 0x1003), 0 },
  1841. /* MT27500 Family [ConnectX-3 Virtual Function] */
  1842. { PCI_VDEVICE(MELLANOX, 0x1004), MLX4_VF },
  1843. { PCI_VDEVICE(MELLANOX, 0x1005), 0 }, /* MT27510 Family */
  1844. { PCI_VDEVICE(MELLANOX, 0x1006), 0 }, /* MT27511 Family */
  1845. { PCI_VDEVICE(MELLANOX, 0x1007), 0 }, /* MT27520 Family */
  1846. { PCI_VDEVICE(MELLANOX, 0x1008), 0 }, /* MT27521 Family */
  1847. { PCI_VDEVICE(MELLANOX, 0x1009), 0 }, /* MT27530 Family */
  1848. { PCI_VDEVICE(MELLANOX, 0x100a), 0 }, /* MT27531 Family */
  1849. { PCI_VDEVICE(MELLANOX, 0x100b), 0 }, /* MT27540 Family */
  1850. { PCI_VDEVICE(MELLANOX, 0x100c), 0 }, /* MT27541 Family */
  1851. { PCI_VDEVICE(MELLANOX, 0x100d), 0 }, /* MT27550 Family */
  1852. { PCI_VDEVICE(MELLANOX, 0x100e), 0 }, /* MT27551 Family */
  1853. { PCI_VDEVICE(MELLANOX, 0x100f), 0 }, /* MT27560 Family */
  1854. { PCI_VDEVICE(MELLANOX, 0x1010), 0 }, /* MT27561 Family */
  1855. { 0, }
  1856. };
  1857. MODULE_DEVICE_TABLE(pci, mlx4_pci_table);
  1858. static struct pci_driver mlx4_driver = {
  1859. .name = DRV_NAME,
  1860. .id_table = mlx4_pci_table,
  1861. .probe = mlx4_init_one,
  1862. .remove = __devexit_p(mlx4_remove_one)
  1863. };
  1864. static int __init mlx4_verify_params(void)
  1865. {
  1866. if ((log_num_mac < 0) || (log_num_mac > 7)) {
  1867. pr_warning("mlx4_core: bad num_mac: %d\n", log_num_mac);
  1868. return -1;
  1869. }
  1870. if (log_num_vlan != 0)
  1871. pr_warning("mlx4_core: log_num_vlan - obsolete module param, using %d\n",
  1872. MLX4_LOG_NUM_VLANS);
  1873. if ((log_mtts_per_seg < 1) || (log_mtts_per_seg > 7)) {
  1874. pr_warning("mlx4_core: bad log_mtts_per_seg: %d\n", log_mtts_per_seg);
  1875. return -1;
  1876. }
  1877. /* Check if module param for ports type has legal combination */
  1878. if (port_type_array[0] == false && port_type_array[1] == true) {
  1879. printk(KERN_WARNING "Module parameter configuration ETH/IB is not supported. Switching to default configuration IB/IB\n");
  1880. port_type_array[0] = true;
  1881. }
  1882. return 0;
  1883. }
  1884. static int __init mlx4_init(void)
  1885. {
  1886. int ret;
  1887. if (mlx4_verify_params())
  1888. return -EINVAL;
  1889. mlx4_catas_init();
  1890. mlx4_wq = create_singlethread_workqueue("mlx4");
  1891. if (!mlx4_wq)
  1892. return -ENOMEM;
  1893. ret = pci_register_driver(&mlx4_driver);
  1894. return ret < 0 ? ret : 0;
  1895. }
  1896. static void __exit mlx4_cleanup(void)
  1897. {
  1898. pci_unregister_driver(&mlx4_driver);
  1899. destroy_workqueue(mlx4_wq);
  1900. }
  1901. module_init(mlx4_init);
  1902. module_exit(mlx4_cleanup);