main.c 60 KB

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