mad.c (020abf03cd659388f94cb328e1e1df0656e0d7ff) mad.c (c37791349cc79d025df6e9a4f896a7b0a97cdbd3)
1/*
2 * Copyright (c) 2007 Cisco Systems, Inc. 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:

--- 21 unchanged lines hidden (view full) ---

30 * SOFTWARE.
31 */
32
33#include <rdma/ib_mad.h>
34#include <rdma/ib_smi.h>
35
36#include <linux/mlx4/cmd.h>
37#include <linux/gfp.h>
1/*
2 * Copyright (c) 2007 Cisco Systems, Inc. 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:

--- 21 unchanged lines hidden (view full) ---

30 * SOFTWARE.
31 */
32
33#include <rdma/ib_mad.h>
34#include <rdma/ib_smi.h>
35
36#include <linux/mlx4/cmd.h>
37#include <linux/gfp.h>
38#include <rdma/ib_pma.h>
38
39#include "mlx4_ib.h"
40
41enum {
42 MLX4_IB_VENDOR_CLASS1 = 0x9,
43 MLX4_IB_VENDOR_CLASS2 = 0xa
44};
45

--- 181 unchanged lines hidden (view full) ---

227 ret = -EINVAL;
228 spin_unlock(&dev->sm_lock);
229
230 if (ret)
231 ib_free_send_mad(send_buf);
232 }
233}
234
39
40#include "mlx4_ib.h"
41
42enum {
43 MLX4_IB_VENDOR_CLASS1 = 0x9,
44 MLX4_IB_VENDOR_CLASS2 = 0xa
45};
46

--- 181 unchanged lines hidden (view full) ---

228 ret = -EINVAL;
229 spin_unlock(&dev->sm_lock);
230
231 if (ret)
232 ib_free_send_mad(send_buf);
233 }
234}
235
235int mlx4_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
236static int ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
236 struct ib_wc *in_wc, struct ib_grh *in_grh,
237 struct ib_mad *in_mad, struct ib_mad *out_mad)
238{
239 u16 slid, prev_lid = 0;
240 int err;
241 struct ib_port_attr pattr;
242
243 slid = in_wc ? in_wc->slid : be16_to_cpu(IB_LID_PERMISSIVE);

--- 53 unchanged lines hidden (view full) ---

297
298 if (in_mad->mad_hdr.method == IB_MGMT_METHOD_TRAP_REPRESS)
299 /* no response for trap repress */
300 return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
301
302 return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
303}
304
237 struct ib_wc *in_wc, struct ib_grh *in_grh,
238 struct ib_mad *in_mad, struct ib_mad *out_mad)
239{
240 u16 slid, prev_lid = 0;
241 int err;
242 struct ib_port_attr pattr;
243
244 slid = in_wc ? in_wc->slid : be16_to_cpu(IB_LID_PERMISSIVE);

--- 53 unchanged lines hidden (view full) ---

298
299 if (in_mad->mad_hdr.method == IB_MGMT_METHOD_TRAP_REPRESS)
300 /* no response for trap repress */
301 return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
302
303 return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
304}
305
306static void edit_counter(struct mlx4_counter *cnt,
307 struct ib_pma_portcounters *pma_cnt)
308{
309 pma_cnt->port_xmit_data = cpu_to_be32((be64_to_cpu(cnt->tx_bytes)>>2));
310 pma_cnt->port_rcv_data = cpu_to_be32((be64_to_cpu(cnt->rx_bytes)>>2));
311 pma_cnt->port_xmit_packets = cpu_to_be32(be64_to_cpu(cnt->tx_frames));
312 pma_cnt->port_rcv_packets = cpu_to_be32(be64_to_cpu(cnt->rx_frames));
313}
314
315static int iboe_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
316 struct ib_wc *in_wc, struct ib_grh *in_grh,
317 struct ib_mad *in_mad, struct ib_mad *out_mad)
318{
319 struct mlx4_cmd_mailbox *mailbox;
320 struct mlx4_ib_dev *dev = to_mdev(ibdev);
321 int err;
322 u32 inmod = dev->counters[port_num - 1] & 0xffff;
323 u8 mode;
324
325 if (in_mad->mad_hdr.mgmt_class != IB_MGMT_CLASS_PERF_MGMT)
326 return -EINVAL;
327
328 mailbox = mlx4_alloc_cmd_mailbox(dev->dev);
329 if (IS_ERR(mailbox))
330 return IB_MAD_RESULT_FAILURE;
331
332 err = mlx4_cmd_box(dev->dev, 0, mailbox->dma, inmod, 0,
333 MLX4_CMD_QUERY_IF_STAT, MLX4_CMD_TIME_CLASS_C);
334 if (err)
335 err = IB_MAD_RESULT_FAILURE;
336 else {
337 memset(out_mad->data, 0, sizeof out_mad->data);
338 mode = ((struct mlx4_counter *)mailbox->buf)->counter_mode;
339 switch (mode & 0xf) {
340 case 0:
341 edit_counter(mailbox->buf,
342 (void *)(out_mad->data + 40));
343 err = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
344 break;
345 default:
346 err = IB_MAD_RESULT_FAILURE;
347 }
348 }
349
350 mlx4_free_cmd_mailbox(dev->dev, mailbox);
351
352 return err;
353}
354
355int mlx4_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
356 struct ib_wc *in_wc, struct ib_grh *in_grh,
357 struct ib_mad *in_mad, struct ib_mad *out_mad)
358{
359 switch (rdma_port_get_link_layer(ibdev, port_num)) {
360 case IB_LINK_LAYER_INFINIBAND:
361 return ib_process_mad(ibdev, mad_flags, port_num, in_wc,
362 in_grh, in_mad, out_mad);
363 case IB_LINK_LAYER_ETHERNET:
364 return iboe_process_mad(ibdev, mad_flags, port_num, in_wc,
365 in_grh, in_mad, out_mad);
366 default:
367 return -EINVAL;
368 }
369}
370
305static void send_handler(struct ib_mad_agent *agent,
306 struct ib_mad_send_wc *mad_send_wc)
307{
308 ib_free_send_mad(mad_send_wc->send_buf);
309}
310
311int mlx4_ib_mad_init(struct mlx4_ib_dev *dev)
312{

--- 52 unchanged lines hidden ---
371static void send_handler(struct ib_mad_agent *agent,
372 struct ib_mad_send_wc *mad_send_wc)
373{
374 ib_free_send_mad(mad_send_wc->send_buf);
375}
376
377int mlx4_ib_mad_init(struct mlx4_ib_dev *dev)
378{

--- 52 unchanged lines hidden ---