alias_GUID.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. * Copyright (c) 2012 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. /***********************************************************/
  33. /*This file support the handling of the Alias GUID feature. */
  34. /***********************************************************/
  35. #include <rdma/ib_mad.h>
  36. #include <rdma/ib_smi.h>
  37. #include <rdma/ib_cache.h>
  38. #include <rdma/ib_sa.h>
  39. #include <rdma/ib_pack.h>
  40. #include <linux/mlx4/cmd.h>
  41. #include <linux/module.h>
  42. #include <linux/init.h>
  43. #include <linux/errno.h>
  44. #include <rdma/ib_user_verbs.h>
  45. #include <linux/delay.h>
  46. #include "mlx4_ib.h"
  47. /*
  48. The driver keeps the current state of all guids, as they are in the HW.
  49. Whenever we receive an smp mad GUIDInfo record, the data will be cached.
  50. */
  51. struct mlx4_alias_guid_work_context {
  52. u8 port;
  53. struct mlx4_ib_dev *dev ;
  54. struct ib_sa_query *sa_query;
  55. struct completion done;
  56. int query_id;
  57. struct list_head list;
  58. int block_num;
  59. };
  60. struct mlx4_next_alias_guid_work {
  61. u8 port;
  62. u8 block_num;
  63. struct mlx4_sriov_alias_guid_info_rec_det rec_det;
  64. };
  65. void mlx4_ib_update_cache_on_guid_change(struct mlx4_ib_dev *dev, int block_num,
  66. u8 port_num, u8 *p_data)
  67. {
  68. int i;
  69. u64 guid_indexes;
  70. int slave_id;
  71. int port_index = port_num - 1;
  72. if (!mlx4_is_master(dev->dev))
  73. return;
  74. guid_indexes = be64_to_cpu((__force __be64) dev->sriov.alias_guid.
  75. ports_guid[port_num - 1].
  76. all_rec_per_port[block_num].guid_indexes);
  77. pr_debug("port: %d, guid_indexes: 0x%llx\n", port_num, guid_indexes);
  78. for (i = 0; i < NUM_ALIAS_GUID_IN_REC; i++) {
  79. /* The location of the specific index starts from bit number 4
  80. * until bit num 11 */
  81. if (test_bit(i + 4, (unsigned long *)&guid_indexes)) {
  82. slave_id = (block_num * NUM_ALIAS_GUID_IN_REC) + i ;
  83. if (slave_id >= dev->dev->num_slaves) {
  84. pr_debug("The last slave: %d\n", slave_id);
  85. return;
  86. }
  87. /* cache the guid: */
  88. memcpy(&dev->sriov.demux[port_index].guid_cache[slave_id],
  89. &p_data[i * GUID_REC_SIZE],
  90. GUID_REC_SIZE);
  91. } else
  92. pr_debug("Guid number: %d in block: %d"
  93. " was not updated\n", i, block_num);
  94. }
  95. }
  96. static __be64 get_cached_alias_guid(struct mlx4_ib_dev *dev, int port, int index)
  97. {
  98. if (index >= NUM_ALIAS_GUID_PER_PORT) {
  99. pr_err("%s: ERROR: asked for index:%d\n", __func__, index);
  100. return (__force __be64) ((u64) 0xFFFFFFFFFFFFFFFFUL);
  101. }
  102. return *(__be64 *)&dev->sriov.demux[port - 1].guid_cache[index];
  103. }
  104. ib_sa_comp_mask mlx4_ib_get_aguid_comp_mask_from_ix(int index)
  105. {
  106. return IB_SA_COMP_MASK(4 + index);
  107. }
  108. /*
  109. * Whenever new GUID is set/unset (guid table change) create event and
  110. * notify the relevant slave (master also should be notified).
  111. * If the GUID value is not as we have in the cache the slave will not be
  112. * updated; in this case it waits for the smp_snoop or the port management
  113. * event to call the function and to update the slave.
  114. * block_number - the index of the block (16 blocks available)
  115. * port_number - 1 or 2
  116. */
  117. void mlx4_ib_notify_slaves_on_guid_change(struct mlx4_ib_dev *dev,
  118. int block_num, u8 port_num,
  119. u8 *p_data)
  120. {
  121. int i;
  122. u64 guid_indexes;
  123. int slave_id;
  124. enum slave_port_state new_state;
  125. enum slave_port_state prev_state;
  126. __be64 tmp_cur_ag, form_cache_ag;
  127. enum slave_port_gen_event gen_event;
  128. if (!mlx4_is_master(dev->dev))
  129. return;
  130. guid_indexes = be64_to_cpu((__force __be64) dev->sriov.alias_guid.
  131. ports_guid[port_num - 1].
  132. all_rec_per_port[block_num].guid_indexes);
  133. pr_debug("port: %d, guid_indexes: 0x%llx\n", port_num, guid_indexes);
  134. /*calculate the slaves and notify them*/
  135. for (i = 0; i < NUM_ALIAS_GUID_IN_REC; i++) {
  136. /* the location of the specific index runs from bits 4..11 */
  137. if (!(test_bit(i + 4, (unsigned long *)&guid_indexes)))
  138. continue;
  139. slave_id = (block_num * NUM_ALIAS_GUID_IN_REC) + i ;
  140. if (slave_id >= dev->dev->num_slaves)
  141. return;
  142. tmp_cur_ag = *(__be64 *)&p_data[i * GUID_REC_SIZE];
  143. form_cache_ag = get_cached_alias_guid(dev, port_num,
  144. (NUM_ALIAS_GUID_IN_REC * block_num) + i);
  145. /*
  146. * Check if guid is not the same as in the cache,
  147. * If it is different, wait for the snoop_smp or the port mgmt
  148. * change event to update the slave on its port state change
  149. */
  150. if (tmp_cur_ag != form_cache_ag)
  151. continue;
  152. mlx4_gen_guid_change_eqe(dev->dev, slave_id, port_num);
  153. /*2 cases: Valid GUID, and Invalid Guid*/
  154. if (tmp_cur_ag != MLX4_NOT_SET_GUID) { /*valid GUID*/
  155. prev_state = mlx4_get_slave_port_state(dev->dev, slave_id, port_num);
  156. new_state = set_and_calc_slave_port_state(dev->dev, slave_id, port_num,
  157. MLX4_PORT_STATE_IB_PORT_STATE_EVENT_GID_VALID,
  158. &gen_event);
  159. pr_debug("slave: %d, port: %d prev_port_state: %d,"
  160. " new_port_state: %d, gen_event: %d\n",
  161. slave_id, port_num, prev_state, new_state, gen_event);
  162. if (gen_event == SLAVE_PORT_GEN_EVENT_UP) {
  163. pr_debug("sending PORT_UP event to slave: %d, port: %d\n",
  164. slave_id, port_num);
  165. mlx4_gen_port_state_change_eqe(dev->dev, slave_id,
  166. port_num, MLX4_PORT_CHANGE_SUBTYPE_ACTIVE);
  167. }
  168. } else { /* request to invalidate GUID */
  169. set_and_calc_slave_port_state(dev->dev, slave_id, port_num,
  170. MLX4_PORT_STATE_IB_EVENT_GID_INVALID,
  171. &gen_event);
  172. pr_debug("sending PORT DOWN event to slave: %d, port: %d\n",
  173. slave_id, port_num);
  174. mlx4_gen_port_state_change_eqe(dev->dev, slave_id, port_num,
  175. MLX4_PORT_CHANGE_SUBTYPE_DOWN);
  176. }
  177. }
  178. }
  179. static void aliasguid_query_handler(int status,
  180. struct ib_sa_guidinfo_rec *guid_rec,
  181. void *context)
  182. {
  183. struct mlx4_ib_dev *dev;
  184. struct mlx4_alias_guid_work_context *cb_ctx = context;
  185. u8 port_index ;
  186. int i;
  187. struct mlx4_sriov_alias_guid_info_rec_det *rec;
  188. unsigned long flags, flags1;
  189. if (!context)
  190. return;
  191. dev = cb_ctx->dev;
  192. port_index = cb_ctx->port - 1;
  193. rec = &dev->sriov.alias_guid.ports_guid[port_index].
  194. all_rec_per_port[cb_ctx->block_num];
  195. if (status) {
  196. rec->status = MLX4_GUID_INFO_STATUS_IDLE;
  197. pr_debug("(port: %d) failed: status = %d\n",
  198. cb_ctx->port, status);
  199. goto out;
  200. }
  201. if (guid_rec->block_num != cb_ctx->block_num) {
  202. pr_err("block num mismatch: %d != %d\n",
  203. cb_ctx->block_num, guid_rec->block_num);
  204. goto out;
  205. }
  206. pr_debug("lid/port: %d/%d, block_num: %d\n",
  207. be16_to_cpu(guid_rec->lid), cb_ctx->port,
  208. guid_rec->block_num);
  209. rec = &dev->sriov.alias_guid.ports_guid[port_index].
  210. all_rec_per_port[guid_rec->block_num];
  211. rec->status = MLX4_GUID_INFO_STATUS_SET;
  212. rec->method = MLX4_GUID_INFO_RECORD_SET;
  213. for (i = 0 ; i < NUM_ALIAS_GUID_IN_REC; i++) {
  214. __be64 tmp_cur_ag;
  215. tmp_cur_ag = *(__be64 *)&guid_rec->guid_info_list[i * GUID_REC_SIZE];
  216. /* check if the SM didn't assign one of the records.
  217. * if it didn't, if it was not sysadmin request:
  218. * ask the SM to give a new GUID, (instead of the driver request).
  219. */
  220. if (tmp_cur_ag == MLX4_NOT_SET_GUID) {
  221. mlx4_ib_warn(&dev->ib_dev, "%s:Record num %d in "
  222. "block_num: %d was declined by SM, "
  223. "ownership by %d (0 = driver, 1=sysAdmin,"
  224. " 2=None)\n", __func__, i,
  225. guid_rec->block_num, rec->ownership);
  226. if (rec->ownership == MLX4_GUID_DRIVER_ASSIGN) {
  227. /* if it is driver assign, asks for new GUID from SM*/
  228. *(__be64 *)&rec->all_recs[i * GUID_REC_SIZE] =
  229. MLX4_NOT_SET_GUID;
  230. /* Mark the record as not assigned, and let it
  231. * be sent again in the next work sched.*/
  232. rec->status = MLX4_GUID_INFO_STATUS_IDLE;
  233. rec->guid_indexes |= mlx4_ib_get_aguid_comp_mask_from_ix(i);
  234. }
  235. } else {
  236. /* properly assigned record. */
  237. /* We save the GUID we just got from the SM in the
  238. * admin_guid in order to be persistent, and in the
  239. * request from the sm the process will ask for the same GUID */
  240. if (rec->ownership == MLX4_GUID_SYSADMIN_ASSIGN &&
  241. tmp_cur_ag != *(__be64 *)&rec->all_recs[i * GUID_REC_SIZE]) {
  242. /* the sysadmin assignment failed.*/
  243. mlx4_ib_warn(&dev->ib_dev, "%s: Failed to set"
  244. " admin guid after SysAdmin "
  245. "configuration. "
  246. "Record num %d in block_num:%d "
  247. "was declined by SM, "
  248. "new val(0x%llx) was kept\n",
  249. __func__, i,
  250. guid_rec->block_num,
  251. be64_to_cpu(*(__be64 *) &
  252. rec->all_recs[i * GUID_REC_SIZE]));
  253. } else {
  254. memcpy(&rec->all_recs[i * GUID_REC_SIZE],
  255. &guid_rec->guid_info_list[i * GUID_REC_SIZE],
  256. GUID_REC_SIZE);
  257. }
  258. }
  259. }
  260. /*
  261. The func is call here to close the cases when the
  262. sm doesn't send smp, so in the sa response the driver
  263. notifies the slave.
  264. */
  265. mlx4_ib_notify_slaves_on_guid_change(dev, guid_rec->block_num,
  266. cb_ctx->port,
  267. guid_rec->guid_info_list);
  268. out:
  269. spin_lock_irqsave(&dev->sriov.going_down_lock, flags);
  270. spin_lock_irqsave(&dev->sriov.alias_guid.ag_work_lock, flags1);
  271. if (!dev->sriov.is_going_down)
  272. queue_delayed_work(dev->sriov.alias_guid.ports_guid[port_index].wq,
  273. &dev->sriov.alias_guid.ports_guid[port_index].
  274. alias_guid_work, 0);
  275. if (cb_ctx->sa_query) {
  276. list_del(&cb_ctx->list);
  277. kfree(cb_ctx);
  278. } else
  279. complete(&cb_ctx->done);
  280. spin_unlock_irqrestore(&dev->sriov.alias_guid.ag_work_lock, flags1);
  281. spin_unlock_irqrestore(&dev->sriov.going_down_lock, flags);
  282. }
  283. static void invalidate_guid_record(struct mlx4_ib_dev *dev, u8 port, int index)
  284. {
  285. int i;
  286. u64 cur_admin_val;
  287. ib_sa_comp_mask comp_mask = 0;
  288. dev->sriov.alias_guid.ports_guid[port - 1].all_rec_per_port[index].status
  289. = MLX4_GUID_INFO_STATUS_IDLE;
  290. dev->sriov.alias_guid.ports_guid[port - 1].all_rec_per_port[index].method
  291. = MLX4_GUID_INFO_RECORD_SET;
  292. /* calculate the comp_mask for that record.*/
  293. for (i = 0; i < NUM_ALIAS_GUID_IN_REC; i++) {
  294. cur_admin_val =
  295. *(u64 *)&dev->sriov.alias_guid.ports_guid[port - 1].
  296. all_rec_per_port[index].all_recs[GUID_REC_SIZE * i];
  297. /*
  298. check the admin value: if it's for delete (~00LL) or
  299. it is the first guid of the first record (hw guid) or
  300. the records is not in ownership of the sysadmin and the sm doesn't
  301. need to assign GUIDs, then don't put it up for assignment.
  302. */
  303. if (MLX4_GUID_FOR_DELETE_VAL == cur_admin_val ||
  304. (!index && !i) ||
  305. MLX4_GUID_NONE_ASSIGN == dev->sriov.alias_guid.
  306. ports_guid[port - 1].all_rec_per_port[index].ownership)
  307. continue;
  308. comp_mask |= mlx4_ib_get_aguid_comp_mask_from_ix(i);
  309. }
  310. dev->sriov.alias_guid.ports_guid[port - 1].
  311. all_rec_per_port[index].guid_indexes = comp_mask;
  312. }
  313. static int set_guid_rec(struct ib_device *ibdev,
  314. u8 port, int index,
  315. struct mlx4_sriov_alias_guid_info_rec_det *rec_det)
  316. {
  317. int err;
  318. struct mlx4_ib_dev *dev = to_mdev(ibdev);
  319. struct ib_sa_guidinfo_rec guid_info_rec;
  320. ib_sa_comp_mask comp_mask;
  321. struct ib_port_attr attr;
  322. struct mlx4_alias_guid_work_context *callback_context;
  323. unsigned long resched_delay, flags, flags1;
  324. struct list_head *head =
  325. &dev->sriov.alias_guid.ports_guid[port - 1].cb_list;
  326. err = __mlx4_ib_query_port(ibdev, port, &attr, 1);
  327. if (err) {
  328. pr_debug("mlx4_ib_query_port failed (err: %d), port: %d\n",
  329. err, port);
  330. return err;
  331. }
  332. /*check the port was configured by the sm, otherwise no need to send */
  333. if (attr.state != IB_PORT_ACTIVE) {
  334. pr_debug("port %d not active...rescheduling\n", port);
  335. resched_delay = 5 * HZ;
  336. err = -EAGAIN;
  337. goto new_schedule;
  338. }
  339. callback_context = kmalloc(sizeof *callback_context, GFP_KERNEL);
  340. if (!callback_context) {
  341. err = -ENOMEM;
  342. resched_delay = HZ * 5;
  343. goto new_schedule;
  344. }
  345. callback_context->port = port;
  346. callback_context->dev = dev;
  347. callback_context->block_num = index;
  348. memset(&guid_info_rec, 0, sizeof (struct ib_sa_guidinfo_rec));
  349. guid_info_rec.lid = cpu_to_be16(attr.lid);
  350. guid_info_rec.block_num = index;
  351. memcpy(guid_info_rec.guid_info_list, rec_det->all_recs,
  352. GUID_REC_SIZE * NUM_ALIAS_GUID_IN_REC);
  353. comp_mask = IB_SA_GUIDINFO_REC_LID | IB_SA_GUIDINFO_REC_BLOCK_NUM |
  354. rec_det->guid_indexes;
  355. init_completion(&callback_context->done);
  356. spin_lock_irqsave(&dev->sriov.alias_guid.ag_work_lock, flags1);
  357. list_add_tail(&callback_context->list, head);
  358. spin_unlock_irqrestore(&dev->sriov.alias_guid.ag_work_lock, flags1);
  359. callback_context->query_id =
  360. ib_sa_guid_info_rec_query(dev->sriov.alias_guid.sa_client,
  361. ibdev, port, &guid_info_rec,
  362. comp_mask, rec_det->method, 1000,
  363. GFP_KERNEL, aliasguid_query_handler,
  364. callback_context,
  365. &callback_context->sa_query);
  366. if (callback_context->query_id < 0) {
  367. pr_debug("ib_sa_guid_info_rec_query failed, query_id: "
  368. "%d. will reschedule to the next 1 sec.\n",
  369. callback_context->query_id);
  370. spin_lock_irqsave(&dev->sriov.alias_guid.ag_work_lock, flags1);
  371. list_del(&callback_context->list);
  372. kfree(callback_context);
  373. spin_unlock_irqrestore(&dev->sriov.alias_guid.ag_work_lock, flags1);
  374. resched_delay = 1 * HZ;
  375. err = -EAGAIN;
  376. goto new_schedule;
  377. }
  378. err = 0;
  379. goto out;
  380. new_schedule:
  381. spin_lock_irqsave(&dev->sriov.going_down_lock, flags);
  382. spin_lock_irqsave(&dev->sriov.alias_guid.ag_work_lock, flags1);
  383. invalidate_guid_record(dev, port, index);
  384. if (!dev->sriov.is_going_down) {
  385. queue_delayed_work(dev->sriov.alias_guid.ports_guid[port - 1].wq,
  386. &dev->sriov.alias_guid.ports_guid[port - 1].alias_guid_work,
  387. resched_delay);
  388. }
  389. spin_unlock_irqrestore(&dev->sriov.alias_guid.ag_work_lock, flags1);
  390. spin_unlock_irqrestore(&dev->sriov.going_down_lock, flags);
  391. out:
  392. return err;
  393. }
  394. void mlx4_ib_invalidate_all_guid_record(struct mlx4_ib_dev *dev, int port)
  395. {
  396. int i;
  397. unsigned long flags, flags1;
  398. pr_debug("port %d\n", port);
  399. spin_lock_irqsave(&dev->sriov.going_down_lock, flags);
  400. spin_lock_irqsave(&dev->sriov.alias_guid.ag_work_lock, flags1);
  401. for (i = 0; i < NUM_ALIAS_GUID_REC_IN_PORT; i++)
  402. invalidate_guid_record(dev, port, i);
  403. if (mlx4_is_master(dev->dev) && !dev->sriov.is_going_down) {
  404. /*
  405. make sure no work waits in the queue, if the work is already
  406. queued(not on the timer) the cancel will fail. That is not a problem
  407. because we just want the work started.
  408. */
  409. cancel_delayed_work(&dev->sriov.alias_guid.
  410. ports_guid[port - 1].alias_guid_work);
  411. queue_delayed_work(dev->sriov.alias_guid.ports_guid[port - 1].wq,
  412. &dev->sriov.alias_guid.ports_guid[port - 1].alias_guid_work,
  413. 0);
  414. }
  415. spin_unlock_irqrestore(&dev->sriov.alias_guid.ag_work_lock, flags1);
  416. spin_unlock_irqrestore(&dev->sriov.going_down_lock, flags);
  417. }
  418. /* The function returns the next record that was
  419. * not configured (or failed to be configured) */
  420. static int get_next_record_to_update(struct mlx4_ib_dev *dev, u8 port,
  421. struct mlx4_next_alias_guid_work *rec)
  422. {
  423. int j;
  424. unsigned long flags;
  425. for (j = 0; j < NUM_ALIAS_GUID_REC_IN_PORT; j++) {
  426. spin_lock_irqsave(&dev->sriov.alias_guid.ag_work_lock, flags);
  427. if (dev->sriov.alias_guid.ports_guid[port].all_rec_per_port[j].status ==
  428. MLX4_GUID_INFO_STATUS_IDLE) {
  429. memcpy(&rec->rec_det,
  430. &dev->sriov.alias_guid.ports_guid[port].all_rec_per_port[j],
  431. sizeof (struct mlx4_sriov_alias_guid_info_rec_det));
  432. rec->port = port;
  433. rec->block_num = j;
  434. dev->sriov.alias_guid.ports_guid[port].all_rec_per_port[j].status =
  435. MLX4_GUID_INFO_STATUS_PENDING;
  436. spin_unlock_irqrestore(&dev->sriov.alias_guid.ag_work_lock, flags);
  437. return 0;
  438. }
  439. spin_unlock_irqrestore(&dev->sriov.alias_guid.ag_work_lock, flags);
  440. }
  441. return -ENOENT;
  442. }
  443. static void set_administratively_guid_record(struct mlx4_ib_dev *dev, int port,
  444. int rec_index,
  445. struct mlx4_sriov_alias_guid_info_rec_det *rec_det)
  446. {
  447. dev->sriov.alias_guid.ports_guid[port].all_rec_per_port[rec_index].guid_indexes =
  448. rec_det->guid_indexes;
  449. memcpy(dev->sriov.alias_guid.ports_guid[port].all_rec_per_port[rec_index].all_recs,
  450. rec_det->all_recs, NUM_ALIAS_GUID_IN_REC * GUID_REC_SIZE);
  451. dev->sriov.alias_guid.ports_guid[port].all_rec_per_port[rec_index].status =
  452. rec_det->status;
  453. }
  454. static void set_all_slaves_guids(struct mlx4_ib_dev *dev, int port)
  455. {
  456. int j;
  457. struct mlx4_sriov_alias_guid_info_rec_det rec_det ;
  458. for (j = 0 ; j < NUM_ALIAS_GUID_REC_IN_PORT ; j++) {
  459. memset(rec_det.all_recs, 0, NUM_ALIAS_GUID_IN_REC * GUID_REC_SIZE);
  460. rec_det.guid_indexes = (!j ? 0 : IB_SA_GUIDINFO_REC_GID0) |
  461. IB_SA_GUIDINFO_REC_GID1 | IB_SA_GUIDINFO_REC_GID2 |
  462. IB_SA_GUIDINFO_REC_GID3 | IB_SA_GUIDINFO_REC_GID4 |
  463. IB_SA_GUIDINFO_REC_GID5 | IB_SA_GUIDINFO_REC_GID6 |
  464. IB_SA_GUIDINFO_REC_GID7;
  465. rec_det.status = MLX4_GUID_INFO_STATUS_IDLE;
  466. set_administratively_guid_record(dev, port, j, &rec_det);
  467. }
  468. }
  469. static void alias_guid_work(struct work_struct *work)
  470. {
  471. struct delayed_work *delay = to_delayed_work(work);
  472. int ret = 0;
  473. struct mlx4_next_alias_guid_work *rec;
  474. struct mlx4_sriov_alias_guid_port_rec_det *sriov_alias_port =
  475. container_of(delay, struct mlx4_sriov_alias_guid_port_rec_det,
  476. alias_guid_work);
  477. struct mlx4_sriov_alias_guid *sriov_alias_guid = sriov_alias_port->parent;
  478. struct mlx4_ib_sriov *ib_sriov = container_of(sriov_alias_guid,
  479. struct mlx4_ib_sriov,
  480. alias_guid);
  481. struct mlx4_ib_dev *dev = container_of(ib_sriov, struct mlx4_ib_dev, sriov);
  482. rec = kzalloc(sizeof *rec, GFP_KERNEL);
  483. if (!rec) {
  484. pr_err("alias_guid_work: No Memory\n");
  485. return;
  486. }
  487. pr_debug("starting [port: %d]...\n", sriov_alias_port->port + 1);
  488. ret = get_next_record_to_update(dev, sriov_alias_port->port, rec);
  489. if (ret) {
  490. pr_debug("No more records to update.\n");
  491. goto out;
  492. }
  493. set_guid_rec(&dev->ib_dev, rec->port + 1, rec->block_num,
  494. &rec->rec_det);
  495. out:
  496. kfree(rec);
  497. }
  498. void mlx4_ib_init_alias_guid_work(struct mlx4_ib_dev *dev, int port)
  499. {
  500. unsigned long flags, flags1;
  501. if (!mlx4_is_master(dev->dev))
  502. return;
  503. spin_lock_irqsave(&dev->sriov.going_down_lock, flags);
  504. spin_lock_irqsave(&dev->sriov.alias_guid.ag_work_lock, flags1);
  505. if (!dev->sriov.is_going_down) {
  506. queue_delayed_work(dev->sriov.alias_guid.ports_guid[port].wq,
  507. &dev->sriov.alias_guid.ports_guid[port].alias_guid_work, 0);
  508. }
  509. spin_unlock_irqrestore(&dev->sriov.alias_guid.ag_work_lock, flags1);
  510. spin_unlock_irqrestore(&dev->sriov.going_down_lock, flags);
  511. }
  512. void mlx4_ib_destroy_alias_guid_service(struct mlx4_ib_dev *dev)
  513. {
  514. int i;
  515. struct mlx4_ib_sriov *sriov = &dev->sriov;
  516. struct mlx4_alias_guid_work_context *cb_ctx;
  517. struct mlx4_sriov_alias_guid_port_rec_det *det;
  518. struct ib_sa_query *sa_query;
  519. unsigned long flags;
  520. for (i = 0 ; i < dev->num_ports; i++) {
  521. cancel_delayed_work(&dev->sriov.alias_guid.ports_guid[i].alias_guid_work);
  522. det = &sriov->alias_guid.ports_guid[i];
  523. spin_lock_irqsave(&sriov->alias_guid.ag_work_lock, flags);
  524. while (!list_empty(&det->cb_list)) {
  525. cb_ctx = list_entry(det->cb_list.next,
  526. struct mlx4_alias_guid_work_context,
  527. list);
  528. sa_query = cb_ctx->sa_query;
  529. cb_ctx->sa_query = NULL;
  530. list_del(&cb_ctx->list);
  531. spin_unlock_irqrestore(&sriov->alias_guid.ag_work_lock, flags);
  532. ib_sa_cancel_query(cb_ctx->query_id, sa_query);
  533. wait_for_completion(&cb_ctx->done);
  534. kfree(cb_ctx);
  535. spin_lock_irqsave(&sriov->alias_guid.ag_work_lock, flags);
  536. }
  537. spin_unlock_irqrestore(&sriov->alias_guid.ag_work_lock, flags);
  538. }
  539. for (i = 0 ; i < dev->num_ports; i++) {
  540. flush_workqueue(dev->sriov.alias_guid.ports_guid[i].wq);
  541. destroy_workqueue(dev->sriov.alias_guid.ports_guid[i].wq);
  542. }
  543. ib_sa_unregister_client(dev->sriov.alias_guid.sa_client);
  544. kfree(dev->sriov.alias_guid.sa_client);
  545. }
  546. int mlx4_ib_init_alias_guid_service(struct mlx4_ib_dev *dev)
  547. {
  548. char alias_wq_name[15];
  549. int ret = 0;
  550. int i, j, k;
  551. union ib_gid gid;
  552. if (!mlx4_is_master(dev->dev))
  553. return 0;
  554. dev->sriov.alias_guid.sa_client =
  555. kzalloc(sizeof *dev->sriov.alias_guid.sa_client, GFP_KERNEL);
  556. if (!dev->sriov.alias_guid.sa_client)
  557. return -ENOMEM;
  558. ib_sa_register_client(dev->sriov.alias_guid.sa_client);
  559. spin_lock_init(&dev->sriov.alias_guid.ag_work_lock);
  560. for (i = 1; i <= dev->num_ports; ++i) {
  561. if (dev->ib_dev.query_gid(&dev->ib_dev , i, 0, &gid)) {
  562. ret = -EFAULT;
  563. goto err_unregister;
  564. }
  565. }
  566. for (i = 0 ; i < dev->num_ports; i++) {
  567. memset(&dev->sriov.alias_guid.ports_guid[i], 0,
  568. sizeof (struct mlx4_sriov_alias_guid_port_rec_det));
  569. /*Check if the SM doesn't need to assign the GUIDs*/
  570. for (j = 0; j < NUM_ALIAS_GUID_REC_IN_PORT; j++) {
  571. if (mlx4_ib_sm_guid_assign) {
  572. dev->sriov.alias_guid.ports_guid[i].
  573. all_rec_per_port[j].
  574. ownership = MLX4_GUID_DRIVER_ASSIGN;
  575. continue;
  576. }
  577. dev->sriov.alias_guid.ports_guid[i].all_rec_per_port[j].
  578. ownership = MLX4_GUID_NONE_ASSIGN;
  579. /*mark each val as it was deleted,
  580. till the sysAdmin will give it valid val*/
  581. for (k = 0; k < NUM_ALIAS_GUID_IN_REC; k++) {
  582. *(__be64 *)&dev->sriov.alias_guid.ports_guid[i].
  583. all_rec_per_port[j].all_recs[GUID_REC_SIZE * k] =
  584. cpu_to_be64(MLX4_GUID_FOR_DELETE_VAL);
  585. }
  586. }
  587. INIT_LIST_HEAD(&dev->sriov.alias_guid.ports_guid[i].cb_list);
  588. /*prepare the records, set them to be allocated by sm*/
  589. for (j = 0 ; j < NUM_ALIAS_GUID_REC_IN_PORT; j++)
  590. invalidate_guid_record(dev, i + 1, j);
  591. dev->sriov.alias_guid.ports_guid[i].parent = &dev->sriov.alias_guid;
  592. dev->sriov.alias_guid.ports_guid[i].port = i;
  593. if (mlx4_ib_sm_guid_assign)
  594. set_all_slaves_guids(dev, i);
  595. snprintf(alias_wq_name, sizeof alias_wq_name, "alias_guid%d", i);
  596. dev->sriov.alias_guid.ports_guid[i].wq =
  597. create_singlethread_workqueue(alias_wq_name);
  598. if (!dev->sriov.alias_guid.ports_guid[i].wq) {
  599. ret = -ENOMEM;
  600. goto err_thread;
  601. }
  602. INIT_DELAYED_WORK(&dev->sriov.alias_guid.ports_guid[i].alias_guid_work,
  603. alias_guid_work);
  604. }
  605. return 0;
  606. err_thread:
  607. for (--i; i >= 0; i--) {
  608. destroy_workqueue(dev->sriov.alias_guid.ports_guid[i].wq);
  609. dev->sriov.alias_guid.ports_guid[i].wq = NULL;
  610. }
  611. err_unregister:
  612. ib_sa_unregister_client(dev->sriov.alias_guid.sa_client);
  613. kfree(dev->sriov.alias_guid.sa_client);
  614. dev->sriov.alias_guid.sa_client = NULL;
  615. pr_err("init_alias_guid_service: Failed. (ret:%d)\n", ret);
  616. return ret;
  617. }