This source file includes following definitions.
- mlx4_SENSE_PORT
- mlx4_do_sense_ports
- mlx4_sense_port
- mlx4_start_sense
- mlx4_stop_sense
- mlx4_sense_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 #include <linux/errno.h>
35 #include <linux/if_ether.h>
36
37 #include <linux/mlx4/cmd.h>
38
39 #include "mlx4.h"
40
41 int mlx4_SENSE_PORT(struct mlx4_dev *dev, int port,
42 enum mlx4_port_type *type)
43 {
44 u64 out_param;
45 int err = 0;
46
47 err = mlx4_cmd_imm(dev, 0, &out_param, port, 0,
48 MLX4_CMD_SENSE_PORT, MLX4_CMD_TIME_CLASS_B,
49 MLX4_CMD_WRAPPED);
50 if (err) {
51 mlx4_err(dev, "Sense command failed for port: %d\n", port);
52 return err;
53 }
54
55 if (out_param > 2) {
56 mlx4_err(dev, "Sense returned illegal value: 0x%llx\n", out_param);
57 return -EINVAL;
58 }
59
60 *type = out_param;
61 return 0;
62 }
63
64 void mlx4_do_sense_ports(struct mlx4_dev *dev,
65 enum mlx4_port_type *stype,
66 enum mlx4_port_type *defaults)
67 {
68 struct mlx4_sense *sense = &mlx4_priv(dev)->sense;
69 int err;
70 int i;
71
72 for (i = 1; i <= dev->caps.num_ports; i++) {
73 stype[i - 1] = 0;
74 if (sense->do_sense_port[i] && sense->sense_allowed[i] &&
75 dev->caps.possible_type[i] == MLX4_PORT_TYPE_AUTO) {
76 err = mlx4_SENSE_PORT(dev, i, &stype[i - 1]);
77 if (err)
78 stype[i - 1] = defaults[i - 1];
79 } else
80 stype[i - 1] = defaults[i - 1];
81 }
82
83
84
85
86 for (i = 0; i < dev->caps.num_ports; i++)
87 stype[i] = stype[i] ? stype[i] : defaults[i];
88
89 }
90
91 static void mlx4_sense_port(struct work_struct *work)
92 {
93 struct delayed_work *delay = to_delayed_work(work);
94 struct mlx4_sense *sense = container_of(delay, struct mlx4_sense,
95 sense_poll);
96 struct mlx4_dev *dev = sense->dev;
97 struct mlx4_priv *priv = mlx4_priv(dev);
98 enum mlx4_port_type stype[MLX4_MAX_PORTS];
99
100 mutex_lock(&priv->port_mutex);
101 mlx4_do_sense_ports(dev, stype, &dev->caps.port_type[1]);
102
103 if (mlx4_check_port_params(dev, stype))
104 goto sense_again;
105
106 if (mlx4_change_port_types(dev, stype))
107 mlx4_err(dev, "Failed to change port_types\n");
108
109 sense_again:
110 mutex_unlock(&priv->port_mutex);
111 queue_delayed_work(mlx4_wq , &sense->sense_poll,
112 round_jiffies_relative(MLX4_SENSE_RANGE));
113 }
114
115 void mlx4_start_sense(struct mlx4_dev *dev)
116 {
117 struct mlx4_priv *priv = mlx4_priv(dev);
118 struct mlx4_sense *sense = &priv->sense;
119
120 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP))
121 return;
122
123 queue_delayed_work(mlx4_wq , &sense->sense_poll,
124 round_jiffies_relative(MLX4_SENSE_RANGE));
125 }
126
127 void mlx4_stop_sense(struct mlx4_dev *dev)
128 {
129 cancel_delayed_work_sync(&mlx4_priv(dev)->sense.sense_poll);
130 }
131
132 void mlx4_sense_init(struct mlx4_dev *dev)
133 {
134 struct mlx4_priv *priv = mlx4_priv(dev);
135 struct mlx4_sense *sense = &priv->sense;
136 int port;
137
138 sense->dev = dev;
139 for (port = 1; port <= dev->caps.num_ports; port++)
140 sense->do_sense_port[port] = 1;
141
142 INIT_DEFERRABLE_WORK(&sense->sense_poll, mlx4_sense_port);
143 }