port.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. /*
  2. * Copyright (c) 2007 Mellanox Technologies. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/errno.h>
  33. #include <linux/if_ether.h>
  34. #include <linux/if_vlan.h>
  35. #include <linux/export.h>
  36. #include <linux/mlx4/cmd.h>
  37. #include "mlx4.h"
  38. #define MLX4_MAC_VALID (1ull << 63)
  39. #define MLX4_VLAN_VALID (1u << 31)
  40. #define MLX4_VLAN_MASK 0xfff
  41. #define MLX4_STATS_TRAFFIC_COUNTERS_MASK 0xfULL
  42. #define MLX4_STATS_TRAFFIC_DROPS_MASK 0xc0ULL
  43. #define MLX4_STATS_ERROR_COUNTERS_MASK 0x1ffc30ULL
  44. #define MLX4_STATS_PORT_COUNTERS_MASK 0x1fe00000ULL
  45. void mlx4_init_mac_table(struct mlx4_dev *dev, struct mlx4_mac_table *table)
  46. {
  47. int i;
  48. mutex_init(&table->mutex);
  49. for (i = 0; i < MLX4_MAX_MAC_NUM; i++) {
  50. table->entries[i] = 0;
  51. table->refs[i] = 0;
  52. }
  53. table->max = 1 << dev->caps.log_num_macs;
  54. table->total = 0;
  55. }
  56. void mlx4_init_vlan_table(struct mlx4_dev *dev, struct mlx4_vlan_table *table)
  57. {
  58. int i;
  59. mutex_init(&table->mutex);
  60. for (i = 0; i < MLX4_MAX_VLAN_NUM; i++) {
  61. table->entries[i] = 0;
  62. table->refs[i] = 0;
  63. }
  64. table->max = (1 << dev->caps.log_num_vlans) - MLX4_VLAN_REGULAR;
  65. table->total = 0;
  66. }
  67. static int validate_index(struct mlx4_dev *dev,
  68. struct mlx4_mac_table *table, int index)
  69. {
  70. int err = 0;
  71. if (index < 0 || index >= table->max || !table->entries[index]) {
  72. mlx4_warn(dev, "No valid Mac entry for the given index\n");
  73. err = -EINVAL;
  74. }
  75. return err;
  76. }
  77. static int find_index(struct mlx4_dev *dev,
  78. struct mlx4_mac_table *table, u64 mac)
  79. {
  80. int i;
  81. for (i = 0; i < MLX4_MAX_MAC_NUM; i++) {
  82. if ((mac & MLX4_MAC_MASK) ==
  83. (MLX4_MAC_MASK & be64_to_cpu(table->entries[i])))
  84. return i;
  85. }
  86. /* Mac not found */
  87. return -EINVAL;
  88. }
  89. static int mlx4_set_port_mac_table(struct mlx4_dev *dev, u8 port,
  90. __be64 *entries)
  91. {
  92. struct mlx4_cmd_mailbox *mailbox;
  93. u32 in_mod;
  94. int err;
  95. mailbox = mlx4_alloc_cmd_mailbox(dev);
  96. if (IS_ERR(mailbox))
  97. return PTR_ERR(mailbox);
  98. memcpy(mailbox->buf, entries, MLX4_MAC_TABLE_SIZE);
  99. in_mod = MLX4_SET_PORT_MAC_TABLE << 8 | port;
  100. err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
  101. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
  102. mlx4_free_cmd_mailbox(dev, mailbox);
  103. return err;
  104. }
  105. int __mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac)
  106. {
  107. struct mlx4_port_info *info = &mlx4_priv(dev)->port[port];
  108. struct mlx4_mac_table *table = &info->mac_table;
  109. int i, err = 0;
  110. int free = -1;
  111. mlx4_dbg(dev, "Registering MAC: 0x%llx for port %d\n",
  112. (unsigned long long) mac, port);
  113. mutex_lock(&table->mutex);
  114. for (i = 0; i < MLX4_MAX_MAC_NUM; i++) {
  115. if (free < 0 && !table->entries[i]) {
  116. free = i;
  117. continue;
  118. }
  119. if (mac == (MLX4_MAC_MASK & be64_to_cpu(table->entries[i]))) {
  120. /* MAC already registered, increment ref count */
  121. err = i;
  122. ++table->refs[i];
  123. goto out;
  124. }
  125. }
  126. mlx4_dbg(dev, "Free MAC index is %d\n", free);
  127. if (table->total == table->max) {
  128. /* No free mac entries */
  129. err = -ENOSPC;
  130. goto out;
  131. }
  132. /* Register new MAC */
  133. table->entries[free] = cpu_to_be64(mac | MLX4_MAC_VALID);
  134. err = mlx4_set_port_mac_table(dev, port, table->entries);
  135. if (unlikely(err)) {
  136. mlx4_err(dev, "Failed adding MAC: 0x%llx\n",
  137. (unsigned long long) mac);
  138. table->entries[free] = 0;
  139. goto out;
  140. }
  141. table->refs[free] = 1;
  142. err = free;
  143. ++table->total;
  144. out:
  145. mutex_unlock(&table->mutex);
  146. return err;
  147. }
  148. EXPORT_SYMBOL_GPL(__mlx4_register_mac);
  149. int mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac)
  150. {
  151. u64 out_param = 0;
  152. int err;
  153. if (mlx4_is_mfunc(dev)) {
  154. set_param_l(&out_param, port);
  155. err = mlx4_cmd_imm(dev, mac, &out_param, RES_MAC,
  156. RES_OP_RESERVE_AND_MAP, MLX4_CMD_ALLOC_RES,
  157. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
  158. if (err)
  159. return err;
  160. return get_param_l(&out_param);
  161. }
  162. return __mlx4_register_mac(dev, port, mac);
  163. }
  164. EXPORT_SYMBOL_GPL(mlx4_register_mac);
  165. int mlx4_get_base_qpn(struct mlx4_dev *dev, u8 port)
  166. {
  167. return dev->caps.reserved_qps_base[MLX4_QP_REGION_ETH_ADDR] +
  168. (port - 1) * (1 << dev->caps.log_num_macs);
  169. }
  170. EXPORT_SYMBOL_GPL(mlx4_get_base_qpn);
  171. void __mlx4_unregister_mac(struct mlx4_dev *dev, u8 port, u64 mac)
  172. {
  173. struct mlx4_port_info *info = &mlx4_priv(dev)->port[port];
  174. struct mlx4_mac_table *table = &info->mac_table;
  175. int index;
  176. mutex_lock(&table->mutex);
  177. index = find_index(dev, table, mac);
  178. if (validate_index(dev, table, index))
  179. goto out;
  180. if (--table->refs[index]) {
  181. mlx4_dbg(dev, "Have more references for index %d,"
  182. "no need to modify mac table\n", index);
  183. goto out;
  184. }
  185. table->entries[index] = 0;
  186. mlx4_set_port_mac_table(dev, port, table->entries);
  187. --table->total;
  188. out:
  189. mutex_unlock(&table->mutex);
  190. }
  191. EXPORT_SYMBOL_GPL(__mlx4_unregister_mac);
  192. void mlx4_unregister_mac(struct mlx4_dev *dev, u8 port, u64 mac)
  193. {
  194. u64 out_param = 0;
  195. if (mlx4_is_mfunc(dev)) {
  196. set_param_l(&out_param, port);
  197. (void) mlx4_cmd_imm(dev, mac, &out_param, RES_MAC,
  198. RES_OP_RESERVE_AND_MAP, MLX4_CMD_FREE_RES,
  199. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
  200. return;
  201. }
  202. __mlx4_unregister_mac(dev, port, mac);
  203. return;
  204. }
  205. EXPORT_SYMBOL_GPL(mlx4_unregister_mac);
  206. int __mlx4_replace_mac(struct mlx4_dev *dev, u8 port, int qpn, u64 new_mac)
  207. {
  208. struct mlx4_port_info *info = &mlx4_priv(dev)->port[port];
  209. struct mlx4_mac_table *table = &info->mac_table;
  210. int index = qpn - info->base_qpn;
  211. int err = 0;
  212. /* CX1 doesn't support multi-functions */
  213. mutex_lock(&table->mutex);
  214. err = validate_index(dev, table, index);
  215. if (err)
  216. goto out;
  217. table->entries[index] = cpu_to_be64(new_mac | MLX4_MAC_VALID);
  218. err = mlx4_set_port_mac_table(dev, port, table->entries);
  219. if (unlikely(err)) {
  220. mlx4_err(dev, "Failed adding MAC: 0x%llx\n",
  221. (unsigned long long) new_mac);
  222. table->entries[index] = 0;
  223. }
  224. out:
  225. mutex_unlock(&table->mutex);
  226. return err;
  227. }
  228. EXPORT_SYMBOL_GPL(__mlx4_replace_mac);
  229. static int mlx4_set_port_vlan_table(struct mlx4_dev *dev, u8 port,
  230. __be32 *entries)
  231. {
  232. struct mlx4_cmd_mailbox *mailbox;
  233. u32 in_mod;
  234. int err;
  235. mailbox = mlx4_alloc_cmd_mailbox(dev);
  236. if (IS_ERR(mailbox))
  237. return PTR_ERR(mailbox);
  238. memcpy(mailbox->buf, entries, MLX4_VLAN_TABLE_SIZE);
  239. in_mod = MLX4_SET_PORT_VLAN_TABLE << 8 | port;
  240. err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
  241. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED);
  242. mlx4_free_cmd_mailbox(dev, mailbox);
  243. return err;
  244. }
  245. int mlx4_find_cached_vlan(struct mlx4_dev *dev, u8 port, u16 vid, int *idx)
  246. {
  247. struct mlx4_vlan_table *table = &mlx4_priv(dev)->port[port].vlan_table;
  248. int i;
  249. for (i = 0; i < MLX4_MAX_VLAN_NUM; ++i) {
  250. if (table->refs[i] &&
  251. (vid == (MLX4_VLAN_MASK &
  252. be32_to_cpu(table->entries[i])))) {
  253. /* VLAN already registered, increase reference count */
  254. *idx = i;
  255. return 0;
  256. }
  257. }
  258. return -ENOENT;
  259. }
  260. EXPORT_SYMBOL_GPL(mlx4_find_cached_vlan);
  261. int __mlx4_register_vlan(struct mlx4_dev *dev, u8 port, u16 vlan,
  262. int *index)
  263. {
  264. struct mlx4_vlan_table *table = &mlx4_priv(dev)->port[port].vlan_table;
  265. int i, err = 0;
  266. int free = -1;
  267. mutex_lock(&table->mutex);
  268. if (table->total == table->max) {
  269. /* No free vlan entries */
  270. err = -ENOSPC;
  271. goto out;
  272. }
  273. for (i = MLX4_VLAN_REGULAR; i < MLX4_MAX_VLAN_NUM; i++) {
  274. if (free < 0 && (table->refs[i] == 0)) {
  275. free = i;
  276. continue;
  277. }
  278. if (table->refs[i] &&
  279. (vlan == (MLX4_VLAN_MASK &
  280. be32_to_cpu(table->entries[i])))) {
  281. /* Vlan already registered, increase references count */
  282. *index = i;
  283. ++table->refs[i];
  284. goto out;
  285. }
  286. }
  287. if (free < 0) {
  288. err = -ENOMEM;
  289. goto out;
  290. }
  291. /* Register new VLAN */
  292. table->refs[free] = 1;
  293. table->entries[free] = cpu_to_be32(vlan | MLX4_VLAN_VALID);
  294. err = mlx4_set_port_vlan_table(dev, port, table->entries);
  295. if (unlikely(err)) {
  296. mlx4_warn(dev, "Failed adding vlan: %u\n", vlan);
  297. table->refs[free] = 0;
  298. table->entries[free] = 0;
  299. goto out;
  300. }
  301. *index = free;
  302. ++table->total;
  303. out:
  304. mutex_unlock(&table->mutex);
  305. return err;
  306. }
  307. int mlx4_register_vlan(struct mlx4_dev *dev, u8 port, u16 vlan, int *index)
  308. {
  309. u64 out_param = 0;
  310. int err;
  311. if (mlx4_is_mfunc(dev)) {
  312. set_param_l(&out_param, port);
  313. err = mlx4_cmd_imm(dev, vlan, &out_param, RES_VLAN,
  314. RES_OP_RESERVE_AND_MAP, MLX4_CMD_ALLOC_RES,
  315. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
  316. if (!err)
  317. *index = get_param_l(&out_param);
  318. return err;
  319. }
  320. return __mlx4_register_vlan(dev, port, vlan, index);
  321. }
  322. EXPORT_SYMBOL_GPL(mlx4_register_vlan);
  323. void __mlx4_unregister_vlan(struct mlx4_dev *dev, u8 port, int index)
  324. {
  325. struct mlx4_vlan_table *table = &mlx4_priv(dev)->port[port].vlan_table;
  326. if (index < MLX4_VLAN_REGULAR) {
  327. mlx4_warn(dev, "Trying to free special vlan index %d\n", index);
  328. return;
  329. }
  330. mutex_lock(&table->mutex);
  331. if (!table->refs[index]) {
  332. mlx4_warn(dev, "No vlan entry for index %d\n", index);
  333. goto out;
  334. }
  335. if (--table->refs[index]) {
  336. mlx4_dbg(dev, "Have more references for index %d,"
  337. "no need to modify vlan table\n", index);
  338. goto out;
  339. }
  340. table->entries[index] = 0;
  341. mlx4_set_port_vlan_table(dev, port, table->entries);
  342. --table->total;
  343. out:
  344. mutex_unlock(&table->mutex);
  345. }
  346. void mlx4_unregister_vlan(struct mlx4_dev *dev, u8 port, int index)
  347. {
  348. u64 in_param = 0;
  349. int err;
  350. if (mlx4_is_mfunc(dev)) {
  351. set_param_l(&in_param, port);
  352. err = mlx4_cmd(dev, in_param, RES_VLAN, RES_OP_RESERVE_AND_MAP,
  353. MLX4_CMD_FREE_RES, MLX4_CMD_TIME_CLASS_A,
  354. MLX4_CMD_WRAPPED);
  355. if (!err)
  356. mlx4_warn(dev, "Failed freeing vlan at index:%d\n",
  357. index);
  358. return;
  359. }
  360. __mlx4_unregister_vlan(dev, port, index);
  361. }
  362. EXPORT_SYMBOL_GPL(mlx4_unregister_vlan);
  363. int mlx4_get_port_ib_caps(struct mlx4_dev *dev, u8 port, __be32 *caps)
  364. {
  365. struct mlx4_cmd_mailbox *inmailbox, *outmailbox;
  366. u8 *inbuf, *outbuf;
  367. int err;
  368. inmailbox = mlx4_alloc_cmd_mailbox(dev);
  369. if (IS_ERR(inmailbox))
  370. return PTR_ERR(inmailbox);
  371. outmailbox = mlx4_alloc_cmd_mailbox(dev);
  372. if (IS_ERR(outmailbox)) {
  373. mlx4_free_cmd_mailbox(dev, inmailbox);
  374. return PTR_ERR(outmailbox);
  375. }
  376. inbuf = inmailbox->buf;
  377. outbuf = outmailbox->buf;
  378. memset(inbuf, 0, 256);
  379. memset(outbuf, 0, 256);
  380. inbuf[0] = 1;
  381. inbuf[1] = 1;
  382. inbuf[2] = 1;
  383. inbuf[3] = 1;
  384. *(__be16 *) (&inbuf[16]) = cpu_to_be16(0x0015);
  385. *(__be32 *) (&inbuf[20]) = cpu_to_be32(port);
  386. err = mlx4_cmd_box(dev, inmailbox->dma, outmailbox->dma, port, 3,
  387. MLX4_CMD_MAD_IFC, MLX4_CMD_TIME_CLASS_C,
  388. MLX4_CMD_NATIVE);
  389. if (!err)
  390. *caps = *(__be32 *) (outbuf + 84);
  391. mlx4_free_cmd_mailbox(dev, inmailbox);
  392. mlx4_free_cmd_mailbox(dev, outmailbox);
  393. return err;
  394. }
  395. static int mlx4_common_set_port(struct mlx4_dev *dev, int slave, u32 in_mod,
  396. u8 op_mod, struct mlx4_cmd_mailbox *inbox)
  397. {
  398. struct mlx4_priv *priv = mlx4_priv(dev);
  399. struct mlx4_port_info *port_info;
  400. struct mlx4_mfunc_master_ctx *master = &priv->mfunc.master;
  401. struct mlx4_slave_state *slave_st = &master->slave_state[slave];
  402. struct mlx4_set_port_rqp_calc_context *qpn_context;
  403. struct mlx4_set_port_general_context *gen_context;
  404. int reset_qkey_viols;
  405. int port;
  406. int is_eth;
  407. u32 in_modifier;
  408. u32 promisc;
  409. u16 mtu, prev_mtu;
  410. int err;
  411. int i;
  412. __be32 agg_cap_mask;
  413. __be32 slave_cap_mask;
  414. __be32 new_cap_mask;
  415. port = in_mod & 0xff;
  416. in_modifier = in_mod >> 8;
  417. is_eth = op_mod;
  418. port_info = &priv->port[port];
  419. /* Slaves cannot perform SET_PORT operations except changing MTU */
  420. if (is_eth) {
  421. if (slave != dev->caps.function &&
  422. in_modifier != MLX4_SET_PORT_GENERAL) {
  423. mlx4_warn(dev, "denying SET_PORT for slave:%d\n",
  424. slave);
  425. return -EINVAL;
  426. }
  427. switch (in_modifier) {
  428. case MLX4_SET_PORT_RQP_CALC:
  429. qpn_context = inbox->buf;
  430. qpn_context->base_qpn =
  431. cpu_to_be32(port_info->base_qpn);
  432. qpn_context->n_mac = 0x7;
  433. promisc = be32_to_cpu(qpn_context->promisc) >>
  434. SET_PORT_PROMISC_SHIFT;
  435. qpn_context->promisc = cpu_to_be32(
  436. promisc << SET_PORT_PROMISC_SHIFT |
  437. port_info->base_qpn);
  438. promisc = be32_to_cpu(qpn_context->mcast) >>
  439. SET_PORT_MC_PROMISC_SHIFT;
  440. qpn_context->mcast = cpu_to_be32(
  441. promisc << SET_PORT_MC_PROMISC_SHIFT |
  442. port_info->base_qpn);
  443. break;
  444. case MLX4_SET_PORT_GENERAL:
  445. gen_context = inbox->buf;
  446. /* Mtu is configured as the max MTU among all the
  447. * the functions on the port. */
  448. mtu = be16_to_cpu(gen_context->mtu);
  449. mtu = min_t(int, mtu, dev->caps.eth_mtu_cap[port] +
  450. ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN);
  451. prev_mtu = slave_st->mtu[port];
  452. slave_st->mtu[port] = mtu;
  453. if (mtu > master->max_mtu[port])
  454. master->max_mtu[port] = mtu;
  455. if (mtu < prev_mtu && prev_mtu ==
  456. master->max_mtu[port]) {
  457. slave_st->mtu[port] = mtu;
  458. master->max_mtu[port] = mtu;
  459. for (i = 0; i < dev->num_slaves; i++) {
  460. master->max_mtu[port] =
  461. max(master->max_mtu[port],
  462. master->slave_state[i].mtu[port]);
  463. }
  464. }
  465. gen_context->mtu = cpu_to_be16(master->max_mtu[port]);
  466. break;
  467. }
  468. return mlx4_cmd(dev, inbox->dma, in_mod, op_mod,
  469. MLX4_CMD_SET_PORT, MLX4_CMD_TIME_CLASS_B,
  470. MLX4_CMD_NATIVE);
  471. }
  472. /* For IB, we only consider:
  473. * - The capability mask, which is set to the aggregate of all
  474. * slave function capabilities
  475. * - The QKey violatin counter - reset according to each request.
  476. */
  477. if (dev->flags & MLX4_FLAG_OLD_PORT_CMDS) {
  478. reset_qkey_viols = (*(u8 *) inbox->buf) & 0x40;
  479. new_cap_mask = ((__be32 *) inbox->buf)[2];
  480. } else {
  481. reset_qkey_viols = ((u8 *) inbox->buf)[3] & 0x1;
  482. new_cap_mask = ((__be32 *) inbox->buf)[1];
  483. }
  484. /* slave may not set the IS_SM capability for the port */
  485. if (slave != mlx4_master_func_num(dev) &&
  486. (be32_to_cpu(new_cap_mask) & MLX4_PORT_CAP_IS_SM))
  487. return -EINVAL;
  488. /* No DEV_MGMT in multifunc mode */
  489. if (mlx4_is_mfunc(dev) &&
  490. (be32_to_cpu(new_cap_mask) & MLX4_PORT_CAP_DEV_MGMT_SUP))
  491. return -EINVAL;
  492. agg_cap_mask = 0;
  493. slave_cap_mask =
  494. priv->mfunc.master.slave_state[slave].ib_cap_mask[port];
  495. priv->mfunc.master.slave_state[slave].ib_cap_mask[port] = new_cap_mask;
  496. for (i = 0; i < dev->num_slaves; i++)
  497. agg_cap_mask |=
  498. priv->mfunc.master.slave_state[i].ib_cap_mask[port];
  499. /* only clear mailbox for guests. Master may be setting
  500. * MTU or PKEY table size
  501. */
  502. if (slave != dev->caps.function)
  503. memset(inbox->buf, 0, 256);
  504. if (dev->flags & MLX4_FLAG_OLD_PORT_CMDS) {
  505. *(u8 *) inbox->buf |= !!reset_qkey_viols << 6;
  506. ((__be32 *) inbox->buf)[2] = agg_cap_mask;
  507. } else {
  508. ((u8 *) inbox->buf)[3] |= !!reset_qkey_viols;
  509. ((__be32 *) inbox->buf)[1] = agg_cap_mask;
  510. }
  511. err = mlx4_cmd(dev, inbox->dma, port, is_eth, MLX4_CMD_SET_PORT,
  512. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
  513. if (err)
  514. priv->mfunc.master.slave_state[slave].ib_cap_mask[port] =
  515. slave_cap_mask;
  516. return err;
  517. }
  518. int mlx4_SET_PORT_wrapper(struct mlx4_dev *dev, int slave,
  519. struct mlx4_vhcr *vhcr,
  520. struct mlx4_cmd_mailbox *inbox,
  521. struct mlx4_cmd_mailbox *outbox,
  522. struct mlx4_cmd_info *cmd)
  523. {
  524. return mlx4_common_set_port(dev, slave, vhcr->in_modifier,
  525. vhcr->op_modifier, inbox);
  526. }
  527. /* bit locations for set port command with zero op modifier */
  528. enum {
  529. MLX4_SET_PORT_VL_CAP = 4, /* bits 7:4 */
  530. MLX4_SET_PORT_MTU_CAP = 12, /* bits 15:12 */
  531. MLX4_CHANGE_PORT_PKEY_TBL_SZ = 20,
  532. MLX4_CHANGE_PORT_VL_CAP = 21,
  533. MLX4_CHANGE_PORT_MTU_CAP = 22,
  534. };
  535. int mlx4_SET_PORT(struct mlx4_dev *dev, u8 port, int pkey_tbl_sz)
  536. {
  537. struct mlx4_cmd_mailbox *mailbox;
  538. int err, vl_cap, pkey_tbl_flag = 0;
  539. if (dev->caps.port_type[port] == MLX4_PORT_TYPE_ETH)
  540. return 0;
  541. mailbox = mlx4_alloc_cmd_mailbox(dev);
  542. if (IS_ERR(mailbox))
  543. return PTR_ERR(mailbox);
  544. memset(mailbox->buf, 0, 256);
  545. ((__be32 *) mailbox->buf)[1] = dev->caps.ib_port_def_cap[port];
  546. if (pkey_tbl_sz >= 0 && mlx4_is_master(dev)) {
  547. pkey_tbl_flag = 1;
  548. ((__be16 *) mailbox->buf)[20] = cpu_to_be16(pkey_tbl_sz);
  549. }
  550. /* IB VL CAP enum isn't used by the firmware, just numerical values */
  551. for (vl_cap = 8; vl_cap >= 1; vl_cap >>= 1) {
  552. ((__be32 *) mailbox->buf)[0] = cpu_to_be32(
  553. (1 << MLX4_CHANGE_PORT_MTU_CAP) |
  554. (1 << MLX4_CHANGE_PORT_VL_CAP) |
  555. (pkey_tbl_flag << MLX4_CHANGE_PORT_PKEY_TBL_SZ) |
  556. (dev->caps.port_ib_mtu[port] << MLX4_SET_PORT_MTU_CAP) |
  557. (vl_cap << MLX4_SET_PORT_VL_CAP));
  558. err = mlx4_cmd(dev, mailbox->dma, port, 0, MLX4_CMD_SET_PORT,
  559. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED);
  560. if (err != -ENOMEM)
  561. break;
  562. }
  563. mlx4_free_cmd_mailbox(dev, mailbox);
  564. return err;
  565. }
  566. int mlx4_SET_PORT_general(struct mlx4_dev *dev, u8 port, int mtu,
  567. u8 pptx, u8 pfctx, u8 pprx, u8 pfcrx)
  568. {
  569. struct mlx4_cmd_mailbox *mailbox;
  570. struct mlx4_set_port_general_context *context;
  571. int err;
  572. u32 in_mod;
  573. mailbox = mlx4_alloc_cmd_mailbox(dev);
  574. if (IS_ERR(mailbox))
  575. return PTR_ERR(mailbox);
  576. context = mailbox->buf;
  577. memset(context, 0, sizeof *context);
  578. context->flags = SET_PORT_GEN_ALL_VALID;
  579. context->mtu = cpu_to_be16(mtu);
  580. context->pptx = (pptx * (!pfctx)) << 7;
  581. context->pfctx = pfctx;
  582. context->pprx = (pprx * (!pfcrx)) << 7;
  583. context->pfcrx = pfcrx;
  584. in_mod = MLX4_SET_PORT_GENERAL << 8 | port;
  585. err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
  586. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED);
  587. mlx4_free_cmd_mailbox(dev, mailbox);
  588. return err;
  589. }
  590. EXPORT_SYMBOL(mlx4_SET_PORT_general);
  591. int mlx4_SET_PORT_qpn_calc(struct mlx4_dev *dev, u8 port, u32 base_qpn,
  592. u8 promisc)
  593. {
  594. struct mlx4_cmd_mailbox *mailbox;
  595. struct mlx4_set_port_rqp_calc_context *context;
  596. int err;
  597. u32 in_mod;
  598. u32 m_promisc = (dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER) ?
  599. MCAST_DIRECT : MCAST_DEFAULT;
  600. if (dev->caps.steering_mode != MLX4_STEERING_MODE_A0)
  601. return 0;
  602. mailbox = mlx4_alloc_cmd_mailbox(dev);
  603. if (IS_ERR(mailbox))
  604. return PTR_ERR(mailbox);
  605. context = mailbox->buf;
  606. memset(context, 0, sizeof *context);
  607. context->base_qpn = cpu_to_be32(base_qpn);
  608. context->n_mac = dev->caps.log_num_macs;
  609. context->promisc = cpu_to_be32(promisc << SET_PORT_PROMISC_SHIFT |
  610. base_qpn);
  611. context->mcast = cpu_to_be32(m_promisc << SET_PORT_MC_PROMISC_SHIFT |
  612. base_qpn);
  613. context->intra_no_vlan = 0;
  614. context->no_vlan = MLX4_NO_VLAN_IDX;
  615. context->intra_vlan_miss = 0;
  616. context->vlan_miss = MLX4_VLAN_MISS_IDX;
  617. in_mod = MLX4_SET_PORT_RQP_CALC << 8 | port;
  618. err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
  619. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED);
  620. mlx4_free_cmd_mailbox(dev, mailbox);
  621. return err;
  622. }
  623. EXPORT_SYMBOL(mlx4_SET_PORT_qpn_calc);
  624. int mlx4_SET_PORT_PRIO2TC(struct mlx4_dev *dev, u8 port, u8 *prio2tc)
  625. {
  626. struct mlx4_cmd_mailbox *mailbox;
  627. struct mlx4_set_port_prio2tc_context *context;
  628. int err;
  629. u32 in_mod;
  630. int i;
  631. mailbox = mlx4_alloc_cmd_mailbox(dev);
  632. if (IS_ERR(mailbox))
  633. return PTR_ERR(mailbox);
  634. context = mailbox->buf;
  635. memset(context, 0, sizeof *context);
  636. for (i = 0; i < MLX4_NUM_UP; i += 2)
  637. context->prio2tc[i >> 1] = prio2tc[i] << 4 | prio2tc[i + 1];
  638. in_mod = MLX4_SET_PORT_PRIO2TC << 8 | port;
  639. err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
  640. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
  641. mlx4_free_cmd_mailbox(dev, mailbox);
  642. return err;
  643. }
  644. EXPORT_SYMBOL(mlx4_SET_PORT_PRIO2TC);
  645. int mlx4_SET_PORT_SCHEDULER(struct mlx4_dev *dev, u8 port, u8 *tc_tx_bw,
  646. u8 *pg, u16 *ratelimit)
  647. {
  648. struct mlx4_cmd_mailbox *mailbox;
  649. struct mlx4_set_port_scheduler_context *context;
  650. int err;
  651. u32 in_mod;
  652. int i;
  653. mailbox = mlx4_alloc_cmd_mailbox(dev);
  654. if (IS_ERR(mailbox))
  655. return PTR_ERR(mailbox);
  656. context = mailbox->buf;
  657. memset(context, 0, sizeof *context);
  658. for (i = 0; i < MLX4_NUM_TC; i++) {
  659. struct mlx4_port_scheduler_tc_cfg_be *tc = &context->tc[i];
  660. u16 r = ratelimit && ratelimit[i] ? ratelimit[i] :
  661. MLX4_RATELIMIT_DEFAULT;
  662. tc->pg = htons(pg[i]);
  663. tc->bw_precentage = htons(tc_tx_bw[i]);
  664. tc->max_bw_units = htons(MLX4_RATELIMIT_UNITS);
  665. tc->max_bw_value = htons(r);
  666. }
  667. in_mod = MLX4_SET_PORT_SCHEDULER << 8 | port;
  668. err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
  669. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
  670. mlx4_free_cmd_mailbox(dev, mailbox);
  671. return err;
  672. }
  673. EXPORT_SYMBOL(mlx4_SET_PORT_SCHEDULER);
  674. int mlx4_SET_MCAST_FLTR_wrapper(struct mlx4_dev *dev, int slave,
  675. struct mlx4_vhcr *vhcr,
  676. struct mlx4_cmd_mailbox *inbox,
  677. struct mlx4_cmd_mailbox *outbox,
  678. struct mlx4_cmd_info *cmd)
  679. {
  680. int err = 0;
  681. return err;
  682. }
  683. int mlx4_SET_MCAST_FLTR(struct mlx4_dev *dev, u8 port,
  684. u64 mac, u64 clear, u8 mode)
  685. {
  686. return mlx4_cmd(dev, (mac | (clear << 63)), port, mode,
  687. MLX4_CMD_SET_MCAST_FLTR, MLX4_CMD_TIME_CLASS_B,
  688. MLX4_CMD_WRAPPED);
  689. }
  690. EXPORT_SYMBOL(mlx4_SET_MCAST_FLTR);
  691. int mlx4_SET_VLAN_FLTR_wrapper(struct mlx4_dev *dev, int slave,
  692. struct mlx4_vhcr *vhcr,
  693. struct mlx4_cmd_mailbox *inbox,
  694. struct mlx4_cmd_mailbox *outbox,
  695. struct mlx4_cmd_info *cmd)
  696. {
  697. int err = 0;
  698. return err;
  699. }
  700. int mlx4_common_dump_eth_stats(struct mlx4_dev *dev, int slave,
  701. u32 in_mod, struct mlx4_cmd_mailbox *outbox)
  702. {
  703. return mlx4_cmd_box(dev, 0, outbox->dma, in_mod, 0,
  704. MLX4_CMD_DUMP_ETH_STATS, MLX4_CMD_TIME_CLASS_B,
  705. MLX4_CMD_NATIVE);
  706. }
  707. int mlx4_DUMP_ETH_STATS_wrapper(struct mlx4_dev *dev, int slave,
  708. struct mlx4_vhcr *vhcr,
  709. struct mlx4_cmd_mailbox *inbox,
  710. struct mlx4_cmd_mailbox *outbox,
  711. struct mlx4_cmd_info *cmd)
  712. {
  713. if (slave != dev->caps.function)
  714. return 0;
  715. return mlx4_common_dump_eth_stats(dev, slave,
  716. vhcr->in_modifier, outbox);
  717. }
  718. void mlx4_set_stats_bitmap(struct mlx4_dev *dev, u64 *stats_bitmap)
  719. {
  720. if (!mlx4_is_mfunc(dev)) {
  721. *stats_bitmap = 0;
  722. return;
  723. }
  724. *stats_bitmap = (MLX4_STATS_TRAFFIC_COUNTERS_MASK |
  725. MLX4_STATS_TRAFFIC_DROPS_MASK |
  726. MLX4_STATS_PORT_COUNTERS_MASK);
  727. if (mlx4_is_master(dev))
  728. *stats_bitmap |= MLX4_STATS_ERROR_COUNTERS_MASK;
  729. }
  730. EXPORT_SYMBOL(mlx4_set_stats_bitmap);