mcg.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  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. #include <rdma/ib_mad.h>
  33. #include <rdma/ib_smi.h>
  34. #include <rdma/ib_cache.h>
  35. #include <rdma/ib_sa.h>
  36. #include <linux/mlx4/cmd.h>
  37. #include <linux/rbtree.h>
  38. #include <linux/delay.h>
  39. #include "mlx4_ib.h"
  40. #define MAX_VFS 80
  41. #define MAX_PEND_REQS_PER_FUNC 4
  42. #define MAD_TIMEOUT_MS 2000
  43. #define mcg_warn(fmt, arg...) pr_warn("MCG WARNING: " fmt, ##arg)
  44. #define mcg_error(fmt, arg...) pr_err(fmt, ##arg)
  45. #define mcg_warn_group(group, format, arg...) \
  46. pr_warn("%s-%d: %16s (port %d): WARNING: " format, __func__, __LINE__,\
  47. (group)->name, group->demux->port, ## arg)
  48. #define mcg_error_group(group, format, arg...) \
  49. pr_err(" %16s: " format, (group)->name, ## arg)
  50. static union ib_gid mgid0;
  51. static struct workqueue_struct *clean_wq;
  52. enum mcast_state {
  53. MCAST_NOT_MEMBER = 0,
  54. MCAST_MEMBER,
  55. };
  56. enum mcast_group_state {
  57. MCAST_IDLE,
  58. MCAST_JOIN_SENT,
  59. MCAST_LEAVE_SENT,
  60. MCAST_RESP_READY
  61. };
  62. struct mcast_member {
  63. enum mcast_state state;
  64. uint8_t join_state;
  65. int num_pend_reqs;
  66. struct list_head pending;
  67. };
  68. struct ib_sa_mcmember_data {
  69. union ib_gid mgid;
  70. union ib_gid port_gid;
  71. __be32 qkey;
  72. __be16 mlid;
  73. u8 mtusel_mtu;
  74. u8 tclass;
  75. __be16 pkey;
  76. u8 ratesel_rate;
  77. u8 lifetmsel_lifetm;
  78. __be32 sl_flowlabel_hoplimit;
  79. u8 scope_join_state;
  80. u8 proxy_join;
  81. u8 reserved[2];
  82. };
  83. struct mcast_group {
  84. struct ib_sa_mcmember_data rec;
  85. struct rb_node node;
  86. struct list_head mgid0_list;
  87. struct mlx4_ib_demux_ctx *demux;
  88. struct mcast_member func[MAX_VFS];
  89. struct mutex lock;
  90. struct work_struct work;
  91. struct list_head pending_list;
  92. int members[3];
  93. enum mcast_group_state state;
  94. enum mcast_group_state prev_state;
  95. struct ib_sa_mad response_sa_mad;
  96. __be64 last_req_tid;
  97. char name[33]; /* MGID string */
  98. /* refcount is the reference count for the following:
  99. 1. Each queued request
  100. 2. Each invocation of the worker thread
  101. 3. Membership of the port at the SA
  102. */
  103. atomic_t refcount;
  104. /* delayed work to clean pending SM request */
  105. struct delayed_work timeout_work;
  106. struct list_head cleanup_list;
  107. };
  108. struct mcast_req {
  109. int func;
  110. struct ib_sa_mad sa_mad;
  111. struct list_head group_list;
  112. struct list_head func_list;
  113. struct mcast_group *group;
  114. int clean;
  115. };
  116. #define safe_atomic_dec(ref) \
  117. do {\
  118. if (atomic_dec_and_test(ref)) \
  119. mcg_warn_group(group, "did not expect to reach zero\n"); \
  120. } while (0)
  121. static const char *get_state_string(enum mcast_group_state state)
  122. {
  123. switch (state) {
  124. case MCAST_IDLE:
  125. return "MCAST_IDLE";
  126. case MCAST_JOIN_SENT:
  127. return "MCAST_JOIN_SENT";
  128. case MCAST_LEAVE_SENT:
  129. return "MCAST_LEAVE_SENT";
  130. case MCAST_RESP_READY:
  131. return "MCAST_RESP_READY";
  132. }
  133. return "Invalid State";
  134. }
  135. static struct mcast_group *mcast_find(struct mlx4_ib_demux_ctx *ctx,
  136. union ib_gid *mgid)
  137. {
  138. struct rb_node *node = ctx->mcg_table.rb_node;
  139. struct mcast_group *group;
  140. int ret;
  141. while (node) {
  142. group = rb_entry(node, struct mcast_group, node);
  143. ret = memcmp(mgid->raw, group->rec.mgid.raw, sizeof *mgid);
  144. if (!ret)
  145. return group;
  146. if (ret < 0)
  147. node = node->rb_left;
  148. else
  149. node = node->rb_right;
  150. }
  151. return NULL;
  152. }
  153. static struct mcast_group *mcast_insert(struct mlx4_ib_demux_ctx *ctx,
  154. struct mcast_group *group)
  155. {
  156. struct rb_node **link = &ctx->mcg_table.rb_node;
  157. struct rb_node *parent = NULL;
  158. struct mcast_group *cur_group;
  159. int ret;
  160. while (*link) {
  161. parent = *link;
  162. cur_group = rb_entry(parent, struct mcast_group, node);
  163. ret = memcmp(group->rec.mgid.raw, cur_group->rec.mgid.raw,
  164. sizeof group->rec.mgid);
  165. if (ret < 0)
  166. link = &(*link)->rb_left;
  167. else if (ret > 0)
  168. link = &(*link)->rb_right;
  169. else
  170. return cur_group;
  171. }
  172. rb_link_node(&group->node, parent, link);
  173. rb_insert_color(&group->node, &ctx->mcg_table);
  174. return NULL;
  175. }
  176. static int send_mad_to_wire(struct mlx4_ib_demux_ctx *ctx, struct ib_mad *mad)
  177. {
  178. struct mlx4_ib_dev *dev = ctx->dev;
  179. struct ib_ah_attr ah_attr;
  180. spin_lock(&dev->sm_lock);
  181. if (!dev->sm_ah[ctx->port - 1]) {
  182. /* port is not yet Active, sm_ah not ready */
  183. spin_unlock(&dev->sm_lock);
  184. return -EAGAIN;
  185. }
  186. mlx4_ib_query_ah(dev->sm_ah[ctx->port - 1], &ah_attr);
  187. spin_unlock(&dev->sm_lock);
  188. return mlx4_ib_send_to_wire(dev, mlx4_master_func_num(dev->dev), ctx->port,
  189. IB_QPT_GSI, 0, 1, IB_QP1_QKEY, &ah_attr, mad);
  190. }
  191. static int send_mad_to_slave(int slave, struct mlx4_ib_demux_ctx *ctx,
  192. struct ib_mad *mad)
  193. {
  194. struct mlx4_ib_dev *dev = ctx->dev;
  195. struct ib_mad_agent *agent = dev->send_agent[ctx->port - 1][1];
  196. struct ib_wc wc;
  197. struct ib_ah_attr ah_attr;
  198. /* Our agent might not yet be registered when mads start to arrive */
  199. if (!agent)
  200. return -EAGAIN;
  201. ib_query_ah(dev->sm_ah[ctx->port - 1], &ah_attr);
  202. wc.pkey_index = 0;
  203. wc.sl = 0;
  204. wc.dlid_path_bits = 0;
  205. wc.port_num = ctx->port;
  206. wc.slid = ah_attr.dlid; /* opensm lid */
  207. wc.src_qp = 1;
  208. return mlx4_ib_send_to_slave(dev, slave, ctx->port, IB_QPT_GSI, &wc, NULL, mad);
  209. }
  210. static int send_join_to_wire(struct mcast_group *group, struct ib_sa_mad *sa_mad)
  211. {
  212. struct ib_sa_mad mad;
  213. struct ib_sa_mcmember_data *sa_mad_data = (struct ib_sa_mcmember_data *)&mad.data;
  214. int ret;
  215. /* we rely on a mad request as arrived from a VF */
  216. memcpy(&mad, sa_mad, sizeof mad);
  217. /* fix port GID to be the real one (slave 0) */
  218. sa_mad_data->port_gid.global.interface_id = group->demux->guid_cache[0];
  219. /* assign our own TID */
  220. mad.mad_hdr.tid = mlx4_ib_get_new_demux_tid(group->demux);
  221. group->last_req_tid = mad.mad_hdr.tid; /* keep it for later validation */
  222. ret = send_mad_to_wire(group->demux, (struct ib_mad *)&mad);
  223. /* set timeout handler */
  224. if (!ret) {
  225. /* calls mlx4_ib_mcg_timeout_handler */
  226. queue_delayed_work(group->demux->mcg_wq, &group->timeout_work,
  227. msecs_to_jiffies(MAD_TIMEOUT_MS));
  228. }
  229. return ret;
  230. }
  231. static int send_leave_to_wire(struct mcast_group *group, u8 join_state)
  232. {
  233. struct ib_sa_mad mad;
  234. struct ib_sa_mcmember_data *sa_data = (struct ib_sa_mcmember_data *)&mad.data;
  235. int ret;
  236. memset(&mad, 0, sizeof mad);
  237. mad.mad_hdr.base_version = 1;
  238. mad.mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_ADM;
  239. mad.mad_hdr.class_version = 2;
  240. mad.mad_hdr.method = IB_SA_METHOD_DELETE;
  241. mad.mad_hdr.status = cpu_to_be16(0);
  242. mad.mad_hdr.class_specific = cpu_to_be16(0);
  243. mad.mad_hdr.tid = mlx4_ib_get_new_demux_tid(group->demux);
  244. group->last_req_tid = mad.mad_hdr.tid; /* keep it for later validation */
  245. mad.mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_MC_MEMBER_REC);
  246. mad.mad_hdr.attr_mod = cpu_to_be32(0);
  247. mad.sa_hdr.sm_key = 0x0;
  248. mad.sa_hdr.attr_offset = cpu_to_be16(7);
  249. mad.sa_hdr.comp_mask = IB_SA_MCMEMBER_REC_MGID |
  250. IB_SA_MCMEMBER_REC_PORT_GID | IB_SA_MCMEMBER_REC_JOIN_STATE;
  251. *sa_data = group->rec;
  252. sa_data->scope_join_state = join_state;
  253. ret = send_mad_to_wire(group->demux, (struct ib_mad *)&mad);
  254. if (ret)
  255. group->state = MCAST_IDLE;
  256. /* set timeout handler */
  257. if (!ret) {
  258. /* calls mlx4_ib_mcg_timeout_handler */
  259. queue_delayed_work(group->demux->mcg_wq, &group->timeout_work,
  260. msecs_to_jiffies(MAD_TIMEOUT_MS));
  261. }
  262. return ret;
  263. }
  264. static int send_reply_to_slave(int slave, struct mcast_group *group,
  265. struct ib_sa_mad *req_sa_mad, u16 status)
  266. {
  267. struct ib_sa_mad mad;
  268. struct ib_sa_mcmember_data *sa_data = (struct ib_sa_mcmember_data *)&mad.data;
  269. struct ib_sa_mcmember_data *req_sa_data = (struct ib_sa_mcmember_data *)&req_sa_mad->data;
  270. int ret;
  271. memset(&mad, 0, sizeof mad);
  272. mad.mad_hdr.base_version = 1;
  273. mad.mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_ADM;
  274. mad.mad_hdr.class_version = 2;
  275. mad.mad_hdr.method = IB_MGMT_METHOD_GET_RESP;
  276. mad.mad_hdr.status = cpu_to_be16(status);
  277. mad.mad_hdr.class_specific = cpu_to_be16(0);
  278. mad.mad_hdr.tid = req_sa_mad->mad_hdr.tid;
  279. *(u8 *)&mad.mad_hdr.tid = 0; /* resetting tid to 0 */
  280. mad.mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_MC_MEMBER_REC);
  281. mad.mad_hdr.attr_mod = cpu_to_be32(0);
  282. mad.sa_hdr.sm_key = req_sa_mad->sa_hdr.sm_key;
  283. mad.sa_hdr.attr_offset = cpu_to_be16(7);
  284. mad.sa_hdr.comp_mask = 0; /* ignored on responses, see IBTA spec */
  285. *sa_data = group->rec;
  286. /* reconstruct VF's requested join_state and port_gid */
  287. sa_data->scope_join_state &= 0xf0;
  288. sa_data->scope_join_state |= (group->func[slave].join_state & 0x0f);
  289. memcpy(&sa_data->port_gid, &req_sa_data->port_gid, sizeof req_sa_data->port_gid);
  290. ret = send_mad_to_slave(slave, group->demux, (struct ib_mad *)&mad);
  291. return ret;
  292. }
  293. static int check_selector(ib_sa_comp_mask comp_mask,
  294. ib_sa_comp_mask selector_mask,
  295. ib_sa_comp_mask value_mask,
  296. u8 src_value, u8 dst_value)
  297. {
  298. int err;
  299. u8 selector = dst_value >> 6;
  300. dst_value &= 0x3f;
  301. src_value &= 0x3f;
  302. if (!(comp_mask & selector_mask) || !(comp_mask & value_mask))
  303. return 0;
  304. switch (selector) {
  305. case IB_SA_GT:
  306. err = (src_value <= dst_value);
  307. break;
  308. case IB_SA_LT:
  309. err = (src_value >= dst_value);
  310. break;
  311. case IB_SA_EQ:
  312. err = (src_value != dst_value);
  313. break;
  314. default:
  315. err = 0;
  316. break;
  317. }
  318. return err;
  319. }
  320. static u16 cmp_rec(struct ib_sa_mcmember_data *src,
  321. struct ib_sa_mcmember_data *dst, ib_sa_comp_mask comp_mask)
  322. {
  323. /* src is group record, dst is request record */
  324. /* MGID must already match */
  325. /* Port_GID we always replace to our Port_GID, so it is a match */
  326. #define MAD_STATUS_REQ_INVALID 0x0200
  327. if (comp_mask & IB_SA_MCMEMBER_REC_QKEY && src->qkey != dst->qkey)
  328. return MAD_STATUS_REQ_INVALID;
  329. if (comp_mask & IB_SA_MCMEMBER_REC_MLID && src->mlid != dst->mlid)
  330. return MAD_STATUS_REQ_INVALID;
  331. if (check_selector(comp_mask, IB_SA_MCMEMBER_REC_MTU_SELECTOR,
  332. IB_SA_MCMEMBER_REC_MTU,
  333. src->mtusel_mtu, dst->mtusel_mtu))
  334. return MAD_STATUS_REQ_INVALID;
  335. if (comp_mask & IB_SA_MCMEMBER_REC_TRAFFIC_CLASS &&
  336. src->tclass != dst->tclass)
  337. return MAD_STATUS_REQ_INVALID;
  338. if (comp_mask & IB_SA_MCMEMBER_REC_PKEY && src->pkey != dst->pkey)
  339. return MAD_STATUS_REQ_INVALID;
  340. if (check_selector(comp_mask, IB_SA_MCMEMBER_REC_RATE_SELECTOR,
  341. IB_SA_MCMEMBER_REC_RATE,
  342. src->ratesel_rate, dst->ratesel_rate))
  343. return MAD_STATUS_REQ_INVALID;
  344. if (check_selector(comp_mask,
  345. IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME_SELECTOR,
  346. IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME,
  347. src->lifetmsel_lifetm, dst->lifetmsel_lifetm))
  348. return MAD_STATUS_REQ_INVALID;
  349. if (comp_mask & IB_SA_MCMEMBER_REC_SL &&
  350. (be32_to_cpu(src->sl_flowlabel_hoplimit) & 0xf0000000) !=
  351. (be32_to_cpu(dst->sl_flowlabel_hoplimit) & 0xf0000000))
  352. return MAD_STATUS_REQ_INVALID;
  353. if (comp_mask & IB_SA_MCMEMBER_REC_FLOW_LABEL &&
  354. (be32_to_cpu(src->sl_flowlabel_hoplimit) & 0x0fffff00) !=
  355. (be32_to_cpu(dst->sl_flowlabel_hoplimit) & 0x0fffff00))
  356. return MAD_STATUS_REQ_INVALID;
  357. if (comp_mask & IB_SA_MCMEMBER_REC_HOP_LIMIT &&
  358. (be32_to_cpu(src->sl_flowlabel_hoplimit) & 0x000000ff) !=
  359. (be32_to_cpu(dst->sl_flowlabel_hoplimit) & 0x000000ff))
  360. return MAD_STATUS_REQ_INVALID;
  361. if (comp_mask & IB_SA_MCMEMBER_REC_SCOPE &&
  362. (src->scope_join_state & 0xf0) !=
  363. (dst->scope_join_state & 0xf0))
  364. return MAD_STATUS_REQ_INVALID;
  365. /* join_state checked separately, proxy_join ignored */
  366. return 0;
  367. }
  368. /* release group, return 1 if this was last release and group is destroyed
  369. * timout work is canceled sync */
  370. static int release_group(struct mcast_group *group, int from_timeout_handler)
  371. {
  372. struct mlx4_ib_demux_ctx *ctx = group->demux;
  373. int nzgroup;
  374. mutex_lock(&ctx->mcg_table_lock);
  375. mutex_lock(&group->lock);
  376. if (atomic_dec_and_test(&group->refcount)) {
  377. if (!from_timeout_handler) {
  378. if (group->state != MCAST_IDLE &&
  379. !cancel_delayed_work(&group->timeout_work)) {
  380. atomic_inc(&group->refcount);
  381. mutex_unlock(&group->lock);
  382. mutex_unlock(&ctx->mcg_table_lock);
  383. return 0;
  384. }
  385. }
  386. nzgroup = memcmp(&group->rec.mgid, &mgid0, sizeof mgid0);
  387. if (!list_empty(&group->pending_list))
  388. mcg_warn_group(group, "releasing a group with non empty pending list\n");
  389. if (nzgroup)
  390. rb_erase(&group->node, &ctx->mcg_table);
  391. list_del_init(&group->mgid0_list);
  392. mutex_unlock(&group->lock);
  393. mutex_unlock(&ctx->mcg_table_lock);
  394. kfree(group);
  395. return 1;
  396. } else {
  397. mutex_unlock(&group->lock);
  398. mutex_unlock(&ctx->mcg_table_lock);
  399. }
  400. return 0;
  401. }
  402. static void adjust_membership(struct mcast_group *group, u8 join_state, int inc)
  403. {
  404. int i;
  405. for (i = 0; i < 3; i++, join_state >>= 1)
  406. if (join_state & 0x1)
  407. group->members[i] += inc;
  408. }
  409. static u8 get_leave_state(struct mcast_group *group)
  410. {
  411. u8 leave_state = 0;
  412. int i;
  413. for (i = 0; i < 3; i++)
  414. if (!group->members[i])
  415. leave_state |= (1 << i);
  416. return leave_state & (group->rec.scope_join_state & 7);
  417. }
  418. static int join_group(struct mcast_group *group, int slave, u8 join_mask)
  419. {
  420. int ret = 0;
  421. u8 join_state;
  422. /* remove bits that slave is already member of, and adjust */
  423. join_state = join_mask & (~group->func[slave].join_state);
  424. adjust_membership(group, join_state, 1);
  425. group->func[slave].join_state |= join_state;
  426. if (group->func[slave].state != MCAST_MEMBER && join_state) {
  427. group->func[slave].state = MCAST_MEMBER;
  428. ret = 1;
  429. }
  430. return ret;
  431. }
  432. static int leave_group(struct mcast_group *group, int slave, u8 leave_state)
  433. {
  434. int ret = 0;
  435. adjust_membership(group, leave_state, -1);
  436. group->func[slave].join_state &= ~leave_state;
  437. if (!group->func[slave].join_state) {
  438. group->func[slave].state = MCAST_NOT_MEMBER;
  439. ret = 1;
  440. }
  441. return ret;
  442. }
  443. static int check_leave(struct mcast_group *group, int slave, u8 leave_mask)
  444. {
  445. if (group->func[slave].state != MCAST_MEMBER)
  446. return MAD_STATUS_REQ_INVALID;
  447. /* make sure we're not deleting unset bits */
  448. if (~group->func[slave].join_state & leave_mask)
  449. return MAD_STATUS_REQ_INVALID;
  450. if (!leave_mask)
  451. return MAD_STATUS_REQ_INVALID;
  452. return 0;
  453. }
  454. static void mlx4_ib_mcg_timeout_handler(struct work_struct *work)
  455. {
  456. struct delayed_work *delay = to_delayed_work(work);
  457. struct mcast_group *group;
  458. struct mcast_req *req = NULL;
  459. group = container_of(delay, typeof(*group), timeout_work);
  460. mutex_lock(&group->lock);
  461. if (group->state == MCAST_JOIN_SENT) {
  462. if (!list_empty(&group->pending_list)) {
  463. req = list_first_entry(&group->pending_list, struct mcast_req, group_list);
  464. list_del(&req->group_list);
  465. list_del(&req->func_list);
  466. --group->func[req->func].num_pend_reqs;
  467. mutex_unlock(&group->lock);
  468. kfree(req);
  469. if (memcmp(&group->rec.mgid, &mgid0, sizeof mgid0)) {
  470. if (release_group(group, 1))
  471. return;
  472. } else {
  473. kfree(group);
  474. return;
  475. }
  476. mutex_lock(&group->lock);
  477. } else
  478. mcg_warn_group(group, "DRIVER BUG\n");
  479. } else if (group->state == MCAST_LEAVE_SENT) {
  480. if (group->rec.scope_join_state & 7)
  481. group->rec.scope_join_state &= 0xf8;
  482. group->state = MCAST_IDLE;
  483. mutex_unlock(&group->lock);
  484. if (release_group(group, 1))
  485. return;
  486. mutex_lock(&group->lock);
  487. } else
  488. mcg_warn_group(group, "invalid state %s\n", get_state_string(group->state));
  489. group->state = MCAST_IDLE;
  490. atomic_inc(&group->refcount);
  491. if (!queue_work(group->demux->mcg_wq, &group->work))
  492. safe_atomic_dec(&group->refcount);
  493. mutex_unlock(&group->lock);
  494. }
  495. static int handle_leave_req(struct mcast_group *group, u8 leave_mask,
  496. struct mcast_req *req)
  497. {
  498. u16 status;
  499. if (req->clean)
  500. leave_mask = group->func[req->func].join_state;
  501. status = check_leave(group, req->func, leave_mask);
  502. if (!status)
  503. leave_group(group, req->func, leave_mask);
  504. if (!req->clean)
  505. send_reply_to_slave(req->func, group, &req->sa_mad, status);
  506. --group->func[req->func].num_pend_reqs;
  507. list_del(&req->group_list);
  508. list_del(&req->func_list);
  509. kfree(req);
  510. return 1;
  511. }
  512. static int handle_join_req(struct mcast_group *group, u8 join_mask,
  513. struct mcast_req *req)
  514. {
  515. u8 group_join_state = group->rec.scope_join_state & 7;
  516. int ref = 0;
  517. u16 status;
  518. struct ib_sa_mcmember_data *sa_data = (struct ib_sa_mcmember_data *)req->sa_mad.data;
  519. if (join_mask == (group_join_state & join_mask)) {
  520. /* port's membership need not change */
  521. status = cmp_rec(&group->rec, sa_data, req->sa_mad.sa_hdr.comp_mask);
  522. if (!status)
  523. join_group(group, req->func, join_mask);
  524. --group->func[req->func].num_pend_reqs;
  525. send_reply_to_slave(req->func, group, &req->sa_mad, status);
  526. list_del(&req->group_list);
  527. list_del(&req->func_list);
  528. kfree(req);
  529. ++ref;
  530. } else {
  531. /* port's membership needs to be updated */
  532. group->prev_state = group->state;
  533. if (send_join_to_wire(group, &req->sa_mad)) {
  534. --group->func[req->func].num_pend_reqs;
  535. list_del(&req->group_list);
  536. list_del(&req->func_list);
  537. kfree(req);
  538. ref = 1;
  539. group->state = group->prev_state;
  540. } else
  541. group->state = MCAST_JOIN_SENT;
  542. }
  543. return ref;
  544. }
  545. static void mlx4_ib_mcg_work_handler(struct work_struct *work)
  546. {
  547. struct mcast_group *group;
  548. struct mcast_req *req = NULL;
  549. struct ib_sa_mcmember_data *sa_data;
  550. u8 req_join_state;
  551. int rc = 1; /* release_count - this is for the scheduled work */
  552. u16 status;
  553. u8 method;
  554. group = container_of(work, typeof(*group), work);
  555. mutex_lock(&group->lock);
  556. /* First, let's see if a response from SM is waiting regarding this group.
  557. * If so, we need to update the group's REC. If this is a bad response, we
  558. * may need to send a bad response to a VF waiting for it. If VF is waiting
  559. * and this is a good response, the VF will be answered later in this func. */
  560. if (group->state == MCAST_RESP_READY) {
  561. /* cancels mlx4_ib_mcg_timeout_handler */
  562. cancel_delayed_work(&group->timeout_work);
  563. status = be16_to_cpu(group->response_sa_mad.mad_hdr.status);
  564. method = group->response_sa_mad.mad_hdr.method;
  565. if (group->last_req_tid != group->response_sa_mad.mad_hdr.tid) {
  566. mcg_warn_group(group, "Got MAD response to existing MGID but wrong TID, dropping. Resp TID=%llx, group TID=%llx\n",
  567. be64_to_cpu(group->response_sa_mad.mad_hdr.tid),
  568. be64_to_cpu(group->last_req_tid));
  569. group->state = group->prev_state;
  570. goto process_requests;
  571. }
  572. if (status) {
  573. if (!list_empty(&group->pending_list))
  574. req = list_first_entry(&group->pending_list,
  575. struct mcast_req, group_list);
  576. if ((method == IB_MGMT_METHOD_GET_RESP)) {
  577. if (req) {
  578. send_reply_to_slave(req->func, group, &req->sa_mad, status);
  579. --group->func[req->func].num_pend_reqs;
  580. list_del(&req->group_list);
  581. list_del(&req->func_list);
  582. kfree(req);
  583. ++rc;
  584. } else
  585. mcg_warn_group(group, "no request for failed join\n");
  586. } else if (method == IB_SA_METHOD_DELETE_RESP && group->demux->flushing)
  587. ++rc;
  588. } else {
  589. u8 resp_join_state;
  590. u8 cur_join_state;
  591. resp_join_state = ((struct ib_sa_mcmember_data *)
  592. group->response_sa_mad.data)->scope_join_state & 7;
  593. cur_join_state = group->rec.scope_join_state & 7;
  594. if (method == IB_MGMT_METHOD_GET_RESP) {
  595. /* successfull join */
  596. if (!cur_join_state && resp_join_state)
  597. --rc;
  598. } else if (!resp_join_state)
  599. ++rc;
  600. memcpy(&group->rec, group->response_sa_mad.data, sizeof group->rec);
  601. }
  602. group->state = MCAST_IDLE;
  603. }
  604. process_requests:
  605. /* We should now go over pending join/leave requests, as long as we are idle. */
  606. while (!list_empty(&group->pending_list) && group->state == MCAST_IDLE) {
  607. req = list_first_entry(&group->pending_list, struct mcast_req,
  608. group_list);
  609. sa_data = (struct ib_sa_mcmember_data *)req->sa_mad.data;
  610. req_join_state = sa_data->scope_join_state & 0x7;
  611. /* For a leave request, we will immediately answer the VF, and
  612. * update our internal counters. The actual leave will be sent
  613. * to SM later, if at all needed. We dequeue the request now. */
  614. if (req->sa_mad.mad_hdr.method == IB_SA_METHOD_DELETE)
  615. rc += handle_leave_req(group, req_join_state, req);
  616. else
  617. rc += handle_join_req(group, req_join_state, req);
  618. }
  619. /* Handle leaves */
  620. if (group->state == MCAST_IDLE) {
  621. req_join_state = get_leave_state(group);
  622. if (req_join_state) {
  623. group->rec.scope_join_state &= ~req_join_state;
  624. group->prev_state = group->state;
  625. if (send_leave_to_wire(group, req_join_state)) {
  626. group->state = group->prev_state;
  627. ++rc;
  628. } else
  629. group->state = MCAST_LEAVE_SENT;
  630. }
  631. }
  632. if (!list_empty(&group->pending_list) && group->state == MCAST_IDLE)
  633. goto process_requests;
  634. mutex_unlock(&group->lock);
  635. while (rc--)
  636. release_group(group, 0);
  637. }
  638. static struct mcast_group *search_relocate_mgid0_group(struct mlx4_ib_demux_ctx *ctx,
  639. __be64 tid,
  640. union ib_gid *new_mgid)
  641. {
  642. struct mcast_group *group = NULL, *cur_group;
  643. struct mcast_req *req;
  644. struct list_head *pos;
  645. struct list_head *n;
  646. mutex_lock(&ctx->mcg_table_lock);
  647. list_for_each_safe(pos, n, &ctx->mcg_mgid0_list) {
  648. group = list_entry(pos, struct mcast_group, mgid0_list);
  649. mutex_lock(&group->lock);
  650. if (group->last_req_tid == tid) {
  651. if (memcmp(new_mgid, &mgid0, sizeof mgid0)) {
  652. group->rec.mgid = *new_mgid;
  653. sprintf(group->name, "%016llx%016llx",
  654. be64_to_cpu(group->rec.mgid.global.subnet_prefix),
  655. be64_to_cpu(group->rec.mgid.global.interface_id));
  656. list_del_init(&group->mgid0_list);
  657. cur_group = mcast_insert(ctx, group);
  658. if (cur_group) {
  659. /* A race between our code and SM. Silently cleaning the new one */
  660. req = list_first_entry(&group->pending_list,
  661. struct mcast_req, group_list);
  662. --group->func[req->func].num_pend_reqs;
  663. list_del(&req->group_list);
  664. list_del(&req->func_list);
  665. kfree(req);
  666. mutex_unlock(&group->lock);
  667. mutex_unlock(&ctx->mcg_table_lock);
  668. release_group(group, 0);
  669. return NULL;
  670. }
  671. atomic_inc(&group->refcount);
  672. mutex_unlock(&group->lock);
  673. mutex_unlock(&ctx->mcg_table_lock);
  674. return group;
  675. } else {
  676. struct mcast_req *tmp1, *tmp2;
  677. list_del(&group->mgid0_list);
  678. if (!list_empty(&group->pending_list) && group->state != MCAST_IDLE)
  679. cancel_delayed_work_sync(&group->timeout_work);
  680. list_for_each_entry_safe(tmp1, tmp2, &group->pending_list, group_list) {
  681. list_del(&tmp1->group_list);
  682. kfree(tmp1);
  683. }
  684. mutex_unlock(&group->lock);
  685. mutex_unlock(&ctx->mcg_table_lock);
  686. kfree(group);
  687. return NULL;
  688. }
  689. }
  690. mutex_unlock(&group->lock);
  691. }
  692. mutex_unlock(&ctx->mcg_table_lock);
  693. return NULL;
  694. }
  695. static struct mcast_group *acquire_group(struct mlx4_ib_demux_ctx *ctx,
  696. union ib_gid *mgid, int create,
  697. gfp_t gfp_mask)
  698. {
  699. struct mcast_group *group, *cur_group;
  700. int is_mgid0;
  701. int i;
  702. is_mgid0 = !memcmp(&mgid0, mgid, sizeof mgid0);
  703. if (!is_mgid0) {
  704. group = mcast_find(ctx, mgid);
  705. if (group)
  706. goto found;
  707. }
  708. if (!create)
  709. return ERR_PTR(-ENOENT);
  710. group = kzalloc(sizeof *group, gfp_mask);
  711. if (!group)
  712. return ERR_PTR(-ENOMEM);
  713. group->demux = ctx;
  714. group->rec.mgid = *mgid;
  715. INIT_LIST_HEAD(&group->pending_list);
  716. INIT_LIST_HEAD(&group->mgid0_list);
  717. for (i = 0; i < MAX_VFS; ++i)
  718. INIT_LIST_HEAD(&group->func[i].pending);
  719. INIT_WORK(&group->work, mlx4_ib_mcg_work_handler);
  720. INIT_DELAYED_WORK(&group->timeout_work, mlx4_ib_mcg_timeout_handler);
  721. mutex_init(&group->lock);
  722. sprintf(group->name, "%016llx%016llx",
  723. be64_to_cpu(group->rec.mgid.global.subnet_prefix),
  724. be64_to_cpu(group->rec.mgid.global.interface_id));
  725. group->state = MCAST_IDLE;
  726. if (is_mgid0) {
  727. list_add(&group->mgid0_list, &ctx->mcg_mgid0_list);
  728. goto found;
  729. }
  730. cur_group = mcast_insert(ctx, group);
  731. if (cur_group) {
  732. mcg_warn("group just showed up %s - confused\n", cur_group->name);
  733. kfree(group);
  734. return ERR_PTR(-EINVAL);
  735. }
  736. found:
  737. atomic_inc(&group->refcount);
  738. return group;
  739. }
  740. static void queue_req(struct mcast_req *req)
  741. {
  742. struct mcast_group *group = req->group;
  743. atomic_inc(&group->refcount); /* for the request */
  744. atomic_inc(&group->refcount); /* for scheduling the work */
  745. list_add_tail(&req->group_list, &group->pending_list);
  746. list_add_tail(&req->func_list, &group->func[req->func].pending);
  747. /* calls mlx4_ib_mcg_work_handler */
  748. if (!queue_work(group->demux->mcg_wq, &group->work))
  749. safe_atomic_dec(&group->refcount);
  750. }
  751. int mlx4_ib_mcg_demux_handler(struct ib_device *ibdev, int port, int slave,
  752. struct ib_sa_mad *mad)
  753. {
  754. struct mlx4_ib_dev *dev = to_mdev(ibdev);
  755. struct ib_sa_mcmember_data *rec = (struct ib_sa_mcmember_data *)mad->data;
  756. struct mlx4_ib_demux_ctx *ctx = &dev->sriov.demux[port - 1];
  757. struct mcast_group *group;
  758. switch (mad->mad_hdr.method) {
  759. case IB_MGMT_METHOD_GET_RESP:
  760. case IB_SA_METHOD_DELETE_RESP:
  761. mutex_lock(&ctx->mcg_table_lock);
  762. group = acquire_group(ctx, &rec->mgid, 0, GFP_KERNEL);
  763. mutex_unlock(&ctx->mcg_table_lock);
  764. if (IS_ERR(group)) {
  765. if (mad->mad_hdr.method == IB_MGMT_METHOD_GET_RESP) {
  766. __be64 tid = mad->mad_hdr.tid;
  767. *(u8 *)(&tid) = (u8)slave; /* in group we kept the modified TID */
  768. group = search_relocate_mgid0_group(ctx, tid, &rec->mgid);
  769. } else
  770. group = NULL;
  771. }
  772. if (!group)
  773. return 1;
  774. mutex_lock(&group->lock);
  775. group->response_sa_mad = *mad;
  776. group->prev_state = group->state;
  777. group->state = MCAST_RESP_READY;
  778. /* calls mlx4_ib_mcg_work_handler */
  779. atomic_inc(&group->refcount);
  780. if (!queue_work(ctx->mcg_wq, &group->work))
  781. safe_atomic_dec(&group->refcount);
  782. mutex_unlock(&group->lock);
  783. release_group(group, 0);
  784. return 1; /* consumed */
  785. case IB_MGMT_METHOD_SET:
  786. case IB_SA_METHOD_GET_TABLE:
  787. case IB_SA_METHOD_GET_TABLE_RESP:
  788. case IB_SA_METHOD_DELETE:
  789. return 0; /* not consumed, pass-through to guest over tunnel */
  790. default:
  791. mcg_warn("In demux, port %d: unexpected MCMember method: 0x%x, dropping\n",
  792. port, mad->mad_hdr.method);
  793. return 1; /* consumed */
  794. }
  795. }
  796. int mlx4_ib_mcg_multiplex_handler(struct ib_device *ibdev, int port,
  797. int slave, struct ib_sa_mad *sa_mad)
  798. {
  799. struct mlx4_ib_dev *dev = to_mdev(ibdev);
  800. struct ib_sa_mcmember_data *rec = (struct ib_sa_mcmember_data *)sa_mad->data;
  801. struct mlx4_ib_demux_ctx *ctx = &dev->sriov.demux[port - 1];
  802. struct mcast_group *group;
  803. struct mcast_req *req;
  804. int may_create = 0;
  805. if (ctx->flushing)
  806. return -EAGAIN;
  807. switch (sa_mad->mad_hdr.method) {
  808. case IB_MGMT_METHOD_SET:
  809. may_create = 1;
  810. case IB_SA_METHOD_DELETE:
  811. req = kzalloc(sizeof *req, GFP_KERNEL);
  812. if (!req)
  813. return -ENOMEM;
  814. req->func = slave;
  815. req->sa_mad = *sa_mad;
  816. mutex_lock(&ctx->mcg_table_lock);
  817. group = acquire_group(ctx, &rec->mgid, may_create, GFP_KERNEL);
  818. mutex_unlock(&ctx->mcg_table_lock);
  819. if (IS_ERR(group)) {
  820. kfree(req);
  821. return PTR_ERR(group);
  822. }
  823. mutex_lock(&group->lock);
  824. if (group->func[slave].num_pend_reqs > MAX_PEND_REQS_PER_FUNC) {
  825. mutex_unlock(&group->lock);
  826. mcg_warn_group(group, "Port %d, Func %d has too many pending requests (%d), dropping\n",
  827. port, slave, MAX_PEND_REQS_PER_FUNC);
  828. release_group(group, 0);
  829. kfree(req);
  830. return -ENOMEM;
  831. }
  832. ++group->func[slave].num_pend_reqs;
  833. req->group = group;
  834. queue_req(req);
  835. mutex_unlock(&group->lock);
  836. release_group(group, 0);
  837. return 1; /* consumed */
  838. case IB_SA_METHOD_GET_TABLE:
  839. case IB_MGMT_METHOD_GET_RESP:
  840. case IB_SA_METHOD_GET_TABLE_RESP:
  841. case IB_SA_METHOD_DELETE_RESP:
  842. return 0; /* not consumed, pass-through */
  843. default:
  844. mcg_warn("In multiplex, port %d, func %d: unexpected MCMember method: 0x%x, dropping\n",
  845. port, slave, sa_mad->mad_hdr.method);
  846. return 1; /* consumed */
  847. }
  848. }
  849. int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
  850. {
  851. char name[20];
  852. atomic_set(&ctx->tid, 0);
  853. sprintf(name, "mlx4_ib_mcg%d", ctx->port);
  854. ctx->mcg_wq = create_singlethread_workqueue(name);
  855. if (!ctx->mcg_wq)
  856. return -ENOMEM;
  857. mutex_init(&ctx->mcg_table_lock);
  858. ctx->mcg_table = RB_ROOT;
  859. INIT_LIST_HEAD(&ctx->mcg_mgid0_list);
  860. ctx->flushing = 0;
  861. return 0;
  862. }
  863. static void force_clean_group(struct mcast_group *group)
  864. {
  865. struct mcast_req *req, *tmp
  866. ;
  867. list_for_each_entry_safe(req, tmp, &group->pending_list, group_list) {
  868. list_del(&req->group_list);
  869. kfree(req);
  870. }
  871. rb_erase(&group->node, &group->demux->mcg_table);
  872. kfree(group);
  873. }
  874. static void _mlx4_ib_mcg_port_cleanup(struct mlx4_ib_demux_ctx *ctx, int destroy_wq)
  875. {
  876. int i;
  877. struct rb_node *p;
  878. struct mcast_group *group;
  879. unsigned long end;
  880. int count;
  881. if (ctx->flushing)
  882. return;
  883. ctx->flushing = 1;
  884. for (i = 0; i < MAX_VFS; ++i)
  885. clean_vf_mcast(ctx, i);
  886. end = jiffies + msecs_to_jiffies(MAD_TIMEOUT_MS + 3000);
  887. do {
  888. count = 0;
  889. mutex_lock(&ctx->mcg_table_lock);
  890. for (p = rb_first(&ctx->mcg_table); p; p = rb_next(p))
  891. ++count;
  892. mutex_unlock(&ctx->mcg_table_lock);
  893. if (!count)
  894. break;
  895. msleep(1);
  896. } while (time_after(end, jiffies));
  897. flush_workqueue(ctx->mcg_wq);
  898. if (destroy_wq)
  899. destroy_workqueue(ctx->mcg_wq);
  900. mutex_lock(&ctx->mcg_table_lock);
  901. while ((p = rb_first(&ctx->mcg_table)) != NULL) {
  902. group = rb_entry(p, struct mcast_group, node);
  903. if (atomic_read(&group->refcount))
  904. mcg_warn_group(group, "group refcount %d!!! (pointer %p)\n", atomic_read(&group->refcount), group);
  905. force_clean_group(group);
  906. }
  907. mutex_unlock(&ctx->mcg_table_lock);
  908. if (!destroy_wq)
  909. ctx->flushing = 0;
  910. }
  911. struct clean_work {
  912. struct work_struct work;
  913. struct mlx4_ib_demux_ctx *ctx;
  914. int destroy_wq;
  915. };
  916. static void mcg_clean_task(struct work_struct *work)
  917. {
  918. struct clean_work *cw = container_of(work, struct clean_work, work);
  919. _mlx4_ib_mcg_port_cleanup(cw->ctx, cw->destroy_wq);
  920. kfree(cw);
  921. }
  922. void mlx4_ib_mcg_port_cleanup(struct mlx4_ib_demux_ctx *ctx, int destroy_wq)
  923. {
  924. struct clean_work *work;
  925. if (destroy_wq) {
  926. _mlx4_ib_mcg_port_cleanup(ctx, destroy_wq);
  927. return;
  928. }
  929. work = kmalloc(sizeof *work, GFP_KERNEL);
  930. if (!work) {
  931. mcg_warn("failed allocating work for cleanup\n");
  932. return;
  933. }
  934. work->ctx = ctx;
  935. work->destroy_wq = destroy_wq;
  936. INIT_WORK(&work->work, mcg_clean_task);
  937. queue_work(clean_wq, &work->work);
  938. }
  939. static void build_leave_mad(struct mcast_req *req)
  940. {
  941. struct ib_sa_mad *mad = &req->sa_mad;
  942. mad->mad_hdr.method = IB_SA_METHOD_DELETE;
  943. }
  944. static void clear_pending_reqs(struct mcast_group *group, int vf)
  945. {
  946. struct mcast_req *req, *tmp, *group_first = NULL;
  947. int clear;
  948. int pend = 0;
  949. if (!list_empty(&group->pending_list))
  950. group_first = list_first_entry(&group->pending_list, struct mcast_req, group_list);
  951. list_for_each_entry_safe(req, tmp, &group->func[vf].pending, func_list) {
  952. clear = 1;
  953. if (group_first == req &&
  954. (group->state == MCAST_JOIN_SENT ||
  955. group->state == MCAST_LEAVE_SENT)) {
  956. clear = cancel_delayed_work(&group->timeout_work);
  957. pend = !clear;
  958. group->state = MCAST_IDLE;
  959. }
  960. if (clear) {
  961. --group->func[vf].num_pend_reqs;
  962. list_del(&req->group_list);
  963. list_del(&req->func_list);
  964. kfree(req);
  965. atomic_dec(&group->refcount);
  966. }
  967. }
  968. if (!pend && (!list_empty(&group->func[vf].pending) || group->func[vf].num_pend_reqs)) {
  969. mcg_warn_group(group, "DRIVER BUG: list_empty %d, num_pend_reqs %d\n",
  970. list_empty(&group->func[vf].pending), group->func[vf].num_pend_reqs);
  971. }
  972. }
  973. static int push_deleteing_req(struct mcast_group *group, int slave)
  974. {
  975. struct mcast_req *req;
  976. struct mcast_req *pend_req;
  977. if (!group->func[slave].join_state)
  978. return 0;
  979. req = kzalloc(sizeof *req, GFP_KERNEL);
  980. if (!req) {
  981. mcg_warn_group(group, "failed allocation - may leave stall groups\n");
  982. return -ENOMEM;
  983. }
  984. if (!list_empty(&group->func[slave].pending)) {
  985. pend_req = list_entry(group->func[slave].pending.prev, struct mcast_req, group_list);
  986. if (pend_req->clean) {
  987. kfree(req);
  988. return 0;
  989. }
  990. }
  991. req->clean = 1;
  992. req->func = slave;
  993. req->group = group;
  994. ++group->func[slave].num_pend_reqs;
  995. build_leave_mad(req);
  996. queue_req(req);
  997. return 0;
  998. }
  999. void clean_vf_mcast(struct mlx4_ib_demux_ctx *ctx, int slave)
  1000. {
  1001. struct mcast_group *group;
  1002. struct rb_node *p;
  1003. mutex_lock(&ctx->mcg_table_lock);
  1004. for (p = rb_first(&ctx->mcg_table); p; p = rb_next(p)) {
  1005. group = rb_entry(p, struct mcast_group, node);
  1006. mutex_lock(&group->lock);
  1007. if (atomic_read(&group->refcount)) {
  1008. /* clear pending requests of this VF */
  1009. clear_pending_reqs(group, slave);
  1010. push_deleteing_req(group, slave);
  1011. }
  1012. mutex_unlock(&group->lock);
  1013. }
  1014. mutex_unlock(&ctx->mcg_table_lock);
  1015. }
  1016. int mlx4_ib_mcg_init(void)
  1017. {
  1018. clean_wq = create_singlethread_workqueue("mlx4_ib_mcg");
  1019. if (!clean_wq)
  1020. return -ENOMEM;
  1021. return 0;
  1022. }
  1023. void mlx4_ib_mcg_destroy(void)
  1024. {
  1025. destroy_workqueue(clean_wq);
  1026. }