aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/mei/hbm.c
diff options
context:
space:
mode:
authorTomas Winkler <tomas.winkler@intel.com>2012-12-25 12:06:10 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-01-07 13:31:29 -0500
commite46f187487a8c28e64417e51ba628746a5397838 (patch)
tree484cc0102c738d7aae646822baabd71ad715eaf9 /drivers/misc/mei/hbm.c
parentcd51ed649fa4bd55c6a78db52b57260797ed56b4 (diff)
mei: use structured buffer for the write buffer
We can drop useless castings and use proper types. We remove the casting in mei_hbm_hdr function and add new function mei_hbm_stop_request_prepare that utilize the new structure Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc/mei/hbm.c')
-rw-r--r--drivers/misc/mei/hbm.c134
1 files changed, 68 insertions, 66 deletions
diff --git a/drivers/misc/mei/hbm.c b/drivers/misc/mei/hbm.c
index bc36c23cd2db..e9ba51d5a46c 100644
--- a/drivers/misc/mei/hbm.c
+++ b/drivers/misc/mei/hbm.c
@@ -67,21 +67,21 @@ bool mei_hbm_cl_addr_equal(struct mei_cl *cl, void *buf)
67 */ 67 */
68void mei_host_start_message(struct mei_device *dev) 68void mei_host_start_message(struct mei_device *dev)
69{ 69{
70 struct mei_msg_hdr *mei_hdr; 70 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
71 struct hbm_host_version_request *start_req; 71 struct hbm_host_version_request *start_req;
72 const size_t len = sizeof(struct hbm_host_version_request); 72 const size_t len = sizeof(struct hbm_host_version_request);
73 73
74 mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 74 mei_hbm_hdr(mei_hdr, len);
75 75
76 /* host start message */ 76 /* host start message */
77 start_req = (struct hbm_host_version_request *)&dev->wr_msg_buf[1]; 77 start_req = (struct hbm_host_version_request *)dev->wr_msg.data;
78 memset(start_req, 0, len); 78 memset(start_req, 0, len);
79 start_req->hbm_cmd = HOST_START_REQ_CMD; 79 start_req->hbm_cmd = HOST_START_REQ_CMD;
80 start_req->host_version.major_version = HBM_MAJOR_VERSION; 80 start_req->host_version.major_version = HBM_MAJOR_VERSION;
81 start_req->host_version.minor_version = HBM_MINOR_VERSION; 81 start_req->host_version.minor_version = HBM_MINOR_VERSION;
82 82
83 dev->recvd_msg = false; 83 dev->recvd_msg = false;
84 if (mei_write_message(dev, mei_hdr, (unsigned char *)start_req)) { 84 if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) {
85 dev_dbg(&dev->pdev->dev, "write send version message to FW fail.\n"); 85 dev_dbg(&dev->pdev->dev, "write send version message to FW fail.\n");
86 dev->dev_state = MEI_DEV_RESETING; 86 dev->dev_state = MEI_DEV_RESETING;
87 mei_reset(dev, 1); 87 mei_reset(dev, 1);
@@ -100,17 +100,17 @@ void mei_host_start_message(struct mei_device *dev)
100 */ 100 */
101void mei_host_enum_clients_message(struct mei_device *dev) 101void mei_host_enum_clients_message(struct mei_device *dev)
102{ 102{
103 struct mei_msg_hdr *mei_hdr; 103 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
104 struct hbm_host_enum_request *enum_req; 104 struct hbm_host_enum_request *enum_req;
105 const size_t len = sizeof(struct hbm_host_enum_request); 105 const size_t len = sizeof(struct hbm_host_enum_request);
106 /* enumerate clients */ 106 /* enumerate clients */
107 mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 107 mei_hbm_hdr(mei_hdr, len);
108 108
109 enum_req = (struct hbm_host_enum_request *) &dev->wr_msg_buf[1]; 109 enum_req = (struct hbm_host_enum_request *)dev->wr_msg.data;
110 memset(enum_req, 0, sizeof(struct hbm_host_enum_request)); 110 memset(enum_req, 0, len);
111 enum_req->hbm_cmd = HOST_ENUM_REQ_CMD; 111 enum_req->hbm_cmd = HOST_ENUM_REQ_CMD;
112 112
113 if (mei_write_message(dev, mei_hdr, (unsigned char *)enum_req)) { 113 if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) {
114 dev->dev_state = MEI_DEV_RESETING; 114 dev->dev_state = MEI_DEV_RESETING;
115 dev_dbg(&dev->pdev->dev, "write send enumeration request message to FW fail.\n"); 115 dev_dbg(&dev->pdev->dev, "write send enumeration request message to FW fail.\n");
116 mei_reset(dev, 1); 116 mei_reset(dev, 1);
@@ -124,7 +124,7 @@ void mei_host_enum_clients_message(struct mei_device *dev)
124int mei_host_client_enumerate(struct mei_device *dev) 124int mei_host_client_enumerate(struct mei_device *dev)
125{ 125{
126 126
127 struct mei_msg_hdr *mei_hdr; 127 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
128 struct hbm_props_request *prop_req; 128 struct hbm_props_request *prop_req;
129 const size_t len = sizeof(struct hbm_props_request); 129 const size_t len = sizeof(struct hbm_props_request);
130 unsigned long next_client_index; 130 unsigned long next_client_index;
@@ -146,8 +146,8 @@ int mei_host_client_enumerate(struct mei_device *dev)
146 dev->me_clients[client_num].client_id = next_client_index; 146 dev->me_clients[client_num].client_id = next_client_index;
147 dev->me_clients[client_num].mei_flow_ctrl_creds = 0; 147 dev->me_clients[client_num].mei_flow_ctrl_creds = 0;
148 148
149 mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 149 mei_hbm_hdr(mei_hdr, len);
150 prop_req = (struct hbm_props_request *)&dev->wr_msg_buf[1]; 150 prop_req = (struct hbm_props_request *)dev->wr_msg.data;
151 151
152 memset(prop_req, 0, sizeof(struct hbm_props_request)); 152 memset(prop_req, 0, sizeof(struct hbm_props_request));
153 153
@@ -155,7 +155,7 @@ int mei_host_client_enumerate(struct mei_device *dev)
155 prop_req->hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD; 155 prop_req->hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD;
156 prop_req->address = next_client_index; 156 prop_req->address = next_client_index;
157 157
158 if (mei_write_message(dev, mei_hdr, (unsigned char *) prop_req)) { 158 if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) {
159 dev->dev_state = MEI_DEV_RESETING; 159 dev->dev_state = MEI_DEV_RESETING;
160 dev_err(&dev->pdev->dev, "Properties request command failed\n"); 160 dev_err(&dev->pdev->dev, "Properties request command failed\n");
161 mei_reset(dev, 1); 161 mei_reset(dev, 1);
@@ -170,6 +170,27 @@ int mei_host_client_enumerate(struct mei_device *dev)
170} 170}
171 171
172/** 172/**
173 * mei_hbm_stop_req_prepare - perpare stop request message
174 *
175 * @dev - mei device
176 * @mei_hdr - mei message header
177 * @data - hbm message body buffer
178 */
179static void mei_hbm_stop_req_prepare(struct mei_device *dev,
180 struct mei_msg_hdr *mei_hdr, unsigned char *data)
181{
182 struct hbm_host_stop_request *req =
183 (struct hbm_host_stop_request *)data;
184 const size_t len = sizeof(struct hbm_host_stop_request);
185
186 mei_hbm_hdr(mei_hdr, len);
187
188 memset(req, 0, len);
189 req->hbm_cmd = HOST_STOP_REQ_CMD;
190 req->reason = DRIVER_STOP_REQUEST;
191}
192
193/**
173 * mei_send_flow_control - sends flow control to fw. 194 * mei_send_flow_control - sends flow control to fw.
174 * 195 *
175 * @dev: the device structure 196 * @dev: the device structure
@@ -179,17 +200,16 @@ int mei_host_client_enumerate(struct mei_device *dev)
179 */ 200 */
180int mei_send_flow_control(struct mei_device *dev, struct mei_cl *cl) 201int mei_send_flow_control(struct mei_device *dev, struct mei_cl *cl)
181{ 202{
182 struct mei_msg_hdr *mei_hdr; 203 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
183 unsigned char *buf = (unsigned char *)&dev->wr_msg_buf[1];
184 const size_t len = sizeof(struct hbm_flow_control); 204 const size_t len = sizeof(struct hbm_flow_control);
185 205
186 mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 206 mei_hbm_hdr(mei_hdr, len);
187 mei_hbm_cl_hdr(cl, MEI_FLOW_CONTROL_CMD, buf, len); 207 mei_hbm_cl_hdr(cl, MEI_FLOW_CONTROL_CMD, dev->wr_msg.data, len);
188 208
189 dev_dbg(&dev->pdev->dev, "sending flow control host client = %d, ME client = %d\n", 209 dev_dbg(&dev->pdev->dev, "sending flow control host client = %d, ME client = %d\n",
190 cl->host_client_id, cl->me_client_id); 210 cl->host_client_id, cl->me_client_id);
191 211
192 return mei_write_message(dev, mei_hdr, buf); 212 return mei_write_message(dev, mei_hdr, dev->wr_msg.data);
193} 213}
194 214
195/** 215/**
@@ -202,14 +222,13 @@ int mei_send_flow_control(struct mei_device *dev, struct mei_cl *cl)
202 */ 222 */
203int mei_disconnect(struct mei_device *dev, struct mei_cl *cl) 223int mei_disconnect(struct mei_device *dev, struct mei_cl *cl)
204{ 224{
205 struct mei_msg_hdr *hdr; 225 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
206 unsigned char *buf = (unsigned char *)&dev->wr_msg_buf[1];
207 const size_t len = sizeof(struct hbm_client_connect_request); 226 const size_t len = sizeof(struct hbm_client_connect_request);
208 227
209 hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 228 mei_hbm_hdr(mei_hdr, len);
210 mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, buf, len); 229 mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, dev->wr_msg.data, len);
211 230
212 return mei_write_message(dev, hdr, buf); 231 return mei_write_message(dev, mei_hdr, dev->wr_msg.data);
213} 232}
214 233
215/** 234/**
@@ -222,14 +241,13 @@ int mei_disconnect(struct mei_device *dev, struct mei_cl *cl)
222 */ 241 */
223int mei_connect(struct mei_device *dev, struct mei_cl *cl) 242int mei_connect(struct mei_device *dev, struct mei_cl *cl)
224{ 243{
225 struct mei_msg_hdr *hdr; 244 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
226 unsigned char *buf = (unsigned char *)&dev->wr_msg_buf[1];
227 const size_t len = sizeof(struct hbm_client_connect_request); 245 const size_t len = sizeof(struct hbm_client_connect_request);
228 246
229 hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 247 mei_hbm_hdr(mei_hdr, len);
230 mei_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, buf, len); 248 mei_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, dev->wr_msg.data, len);
231 249
232 return mei_write_message(dev, hdr, buf); 250 return mei_write_message(dev, mei_hdr, dev->wr_msg.data);
233} 251}
234 252
235/** 253/**
@@ -257,9 +275,9 @@ static void mei_client_disconnect_request(struct mei_device *dev,
257 dev->iamthif_timer = 0; 275 dev->iamthif_timer = 0;
258 276
259 /* prepare disconnect response */ 277 /* prepare disconnect response */
260 (void)mei_hbm_hdr((u32 *)&dev->wr_ext_msg.hdr, len); 278 mei_hbm_hdr(&dev->wr_ext_msg.hdr, len);
261 mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_RES_CMD, 279 mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_RES_CMD,
262 &dev->wr_ext_msg.data, len); 280 dev->wr_ext_msg.data, len);
263 break; 281 break;
264 } 282 }
265 } 283 }
@@ -284,7 +302,6 @@ void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)
284 struct hbm_flow_control *flow_control; 302 struct hbm_flow_control *flow_control;
285 struct hbm_props_response *props_res; 303 struct hbm_props_response *props_res;
286 struct hbm_host_enum_response *enum_res; 304 struct hbm_host_enum_response *enum_res;
287 struct hbm_host_stop_request *stop_req;
288 305
289 /* read the message to our buffer */ 306 /* read the message to our buffer */
290 BUG_ON(hdr->length >= sizeof(dev->rd_msg_buf)); 307 BUG_ON(hdr->length >= sizeof(dev->rd_msg_buf));
@@ -294,34 +311,27 @@ void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)
294 switch (mei_msg->hbm_cmd) { 311 switch (mei_msg->hbm_cmd) {
295 case HOST_START_RES_CMD: 312 case HOST_START_RES_CMD:
296 version_res = (struct hbm_host_version_response *)mei_msg; 313 version_res = (struct hbm_host_version_response *)mei_msg;
297 if (version_res->host_version_supported) { 314 if (!version_res->host_version_supported) {
298 dev->version.major_version = HBM_MAJOR_VERSION;
299 dev->version.minor_version = HBM_MINOR_VERSION;
300 if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
301 dev->init_clients_state == MEI_START_MESSAGE) {
302 dev->init_clients_timer = 0;
303 mei_host_enum_clients_message(dev);
304 } else {
305 dev->recvd_msg = false;
306 dev_dbg(&dev->pdev->dev, "IMEI reset due to received host start response bus message.\n");
307 mei_reset(dev, 1);
308 return;
309 }
310 } else {
311 u32 *buf = dev->wr_msg_buf;
312 const size_t len = sizeof(struct hbm_host_stop_request);
313
314 dev->version = version_res->me_max_version; 315 dev->version = version_res->me_max_version;
316 dev_dbg(&dev->pdev->dev, "version mismatch.\n");
315 317
316 /* send stop message */ 318 mei_hbm_stop_req_prepare(dev, &dev->wr_msg.hdr,
317 hdr = mei_hbm_hdr(&buf[0], len); 319 dev->wr_msg.data);
318 stop_req = (struct hbm_host_stop_request *)&buf[1]; 320 mei_write_message(dev, &dev->wr_msg.hdr,
319 memset(stop_req, 0, len); 321 dev->wr_msg.data);
320 stop_req->hbm_cmd = HOST_STOP_REQ_CMD; 322 return;
321 stop_req->reason = DRIVER_STOP_REQUEST; 323 }
322 324
323 mei_write_message(dev, hdr, (unsigned char *)stop_req); 325 dev->version.major_version = HBM_MAJOR_VERSION;
324 dev_dbg(&dev->pdev->dev, "version mismatch.\n"); 326 dev->version.minor_version = HBM_MINOR_VERSION;
327 if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
328 dev->init_clients_state == MEI_START_MESSAGE) {
329 dev->init_clients_timer = 0;
330 mei_host_enum_clients_message(dev);
331 } else {
332 dev->recvd_msg = false;
333 dev_dbg(&dev->pdev->dev, "reset due to received hbm: host start\n");
334 mei_reset(dev, 1);
325 return; 335 return;
326 } 336 }
327 337
@@ -417,18 +427,10 @@ void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)
417 break; 427 break;
418 428
419 case ME_STOP_REQ_CMD: 429 case ME_STOP_REQ_CMD:
420 {
421 /* prepare stop request: sent in next interrupt event */
422 430
423 const size_t len = sizeof(struct hbm_host_stop_request); 431 mei_hbm_stop_req_prepare(dev, &dev->wr_ext_msg.hdr,
424 432 dev->wr_ext_msg.data);
425 hdr = mei_hbm_hdr((u32 *)&dev->wr_ext_msg.hdr, len);
426 stop_req = (struct hbm_host_stop_request *)&dev->wr_ext_msg.data;
427 memset(stop_req, 0, len);
428 stop_req->hbm_cmd = HOST_STOP_REQ_CMD;
429 stop_req->reason = DRIVER_STOP_REQUEST;
430 break; 433 break;
431 }
432 default: 434 default:
433 BUG(); 435 BUG();
434 break; 436 break;