.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (c) 2008-2009 Atheros Communications Inc. |
---|
3 | | - * |
---|
4 | | - * This program is free software; you can redistribute it and/or modify |
---|
5 | | - * it under the terms of the GNU General Public License as published by |
---|
6 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
7 | | - * (at your option) any later version. |
---|
8 | | - * |
---|
9 | | - * This program is distributed in the hope that it will be useful, |
---|
10 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | | - * GNU General Public License for more details. |
---|
13 | | - * |
---|
14 | | - * You should have received a copy of the GNU General Public License |
---|
15 | | - * along with this program; if not, write to the Free Software |
---|
16 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | | - * |
---|
18 | 4 | */ |
---|
19 | 5 | |
---|
20 | 6 | |
---|
.. | .. |
---|
203 | 189 | { } /* Terminating entry */ |
---|
204 | 190 | }; |
---|
205 | 191 | |
---|
206 | | -static inline void ath3k_log_failed_loading(int err, int len, int size) |
---|
| 192 | +static inline void ath3k_log_failed_loading(int err, int len, int size, |
---|
| 193 | + int count) |
---|
207 | 194 | { |
---|
208 | | - BT_ERR("Error in firmware loading err = %d, len = %d, size = %d", |
---|
209 | | - err, len, size); |
---|
| 195 | + BT_ERR("Firmware loading err = %d, len = %d, size = %d, count = %d", |
---|
| 196 | + err, len, size, count); |
---|
210 | 197 | } |
---|
211 | 198 | |
---|
212 | 199 | #define USB_REQ_DFU_DNLOAD 1 |
---|
.. | .. |
---|
225 | 212 | |
---|
226 | 213 | BT_DBG("udev %p", udev); |
---|
227 | 214 | |
---|
228 | | - pipe = usb_sndctrlpipe(udev, 0); |
---|
229 | | - |
---|
230 | 215 | send_buf = kmalloc(BULK_SIZE, GFP_KERNEL); |
---|
231 | 216 | if (!send_buf) { |
---|
232 | 217 | BT_ERR("Can't allocate memory chunk for firmware"); |
---|
233 | 218 | return -ENOMEM; |
---|
234 | 219 | } |
---|
235 | 220 | |
---|
236 | | - memcpy(send_buf, firmware->data, FW_HDR_SIZE); |
---|
237 | | - err = usb_control_msg(udev, pipe, USB_REQ_DFU_DNLOAD, USB_TYPE_VENDOR, |
---|
238 | | - 0, 0, send_buf, FW_HDR_SIZE, |
---|
239 | | - USB_CTRL_SET_TIMEOUT); |
---|
240 | | - if (err < 0) { |
---|
| 221 | + err = usb_control_msg_send(udev, 0, USB_REQ_DFU_DNLOAD, USB_TYPE_VENDOR, |
---|
| 222 | + 0, 0, firmware->data, FW_HDR_SIZE, |
---|
| 223 | + USB_CTRL_SET_TIMEOUT, GFP_KERNEL); |
---|
| 224 | + if (err) { |
---|
241 | 225 | BT_ERR("Can't change to loading configuration err"); |
---|
242 | 226 | goto error; |
---|
243 | 227 | } |
---|
.. | .. |
---|
257 | 241 | &len, 3000); |
---|
258 | 242 | |
---|
259 | 243 | if (err || (len != size)) { |
---|
260 | | - ath3k_log_failed_loading(err, len, size); |
---|
| 244 | + ath3k_log_failed_loading(err, len, size, count); |
---|
261 | 245 | goto error; |
---|
262 | 246 | } |
---|
263 | 247 | |
---|
.. | .. |
---|
272 | 256 | |
---|
273 | 257 | static int ath3k_get_state(struct usb_device *udev, unsigned char *state) |
---|
274 | 258 | { |
---|
275 | | - int ret, pipe = 0; |
---|
276 | | - char *buf; |
---|
277 | | - |
---|
278 | | - buf = kmalloc(sizeof(*buf), GFP_KERNEL); |
---|
279 | | - if (!buf) |
---|
280 | | - return -ENOMEM; |
---|
281 | | - |
---|
282 | | - pipe = usb_rcvctrlpipe(udev, 0); |
---|
283 | | - ret = usb_control_msg(udev, pipe, ATH3K_GETSTATE, |
---|
284 | | - USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, |
---|
285 | | - buf, sizeof(*buf), USB_CTRL_SET_TIMEOUT); |
---|
286 | | - |
---|
287 | | - *state = *buf; |
---|
288 | | - kfree(buf); |
---|
289 | | - |
---|
290 | | - return ret; |
---|
| 259 | + return usb_control_msg_recv(udev, 0, ATH3K_GETSTATE, |
---|
| 260 | + USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, |
---|
| 261 | + state, 1, USB_CTRL_SET_TIMEOUT, |
---|
| 262 | + GFP_KERNEL); |
---|
291 | 263 | } |
---|
292 | 264 | |
---|
293 | 265 | static int ath3k_get_version(struct usb_device *udev, |
---|
294 | 266 | struct ath3k_version *version) |
---|
295 | 267 | { |
---|
296 | | - int ret, pipe = 0; |
---|
297 | | - struct ath3k_version *buf; |
---|
298 | | - const int size = sizeof(*buf); |
---|
299 | | - |
---|
300 | | - buf = kmalloc(size, GFP_KERNEL); |
---|
301 | | - if (!buf) |
---|
302 | | - return -ENOMEM; |
---|
303 | | - |
---|
304 | | - pipe = usb_rcvctrlpipe(udev, 0); |
---|
305 | | - ret = usb_control_msg(udev, pipe, ATH3K_GETVERSION, |
---|
306 | | - USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, |
---|
307 | | - buf, size, USB_CTRL_SET_TIMEOUT); |
---|
308 | | - |
---|
309 | | - memcpy(version, buf, size); |
---|
310 | | - kfree(buf); |
---|
311 | | - |
---|
312 | | - return ret; |
---|
| 268 | + return usb_control_msg_recv(udev, 0, ATH3K_GETVERSION, |
---|
| 269 | + USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, |
---|
| 270 | + version, sizeof(*version), USB_CTRL_SET_TIMEOUT, |
---|
| 271 | + GFP_KERNEL); |
---|
313 | 272 | } |
---|
314 | 273 | |
---|
315 | 274 | static int ath3k_load_fwfile(struct usb_device *udev, |
---|
.. | .. |
---|
329 | 288 | } |
---|
330 | 289 | |
---|
331 | 290 | size = min_t(uint, count, FW_HDR_SIZE); |
---|
332 | | - memcpy(send_buf, firmware->data, size); |
---|
333 | 291 | |
---|
334 | | - pipe = usb_sndctrlpipe(udev, 0); |
---|
335 | | - ret = usb_control_msg(udev, pipe, ATH3K_DNLOAD, |
---|
336 | | - USB_TYPE_VENDOR, 0, 0, send_buf, |
---|
337 | | - size, USB_CTRL_SET_TIMEOUT); |
---|
338 | | - if (ret < 0) { |
---|
| 292 | + ret = usb_control_msg_send(udev, 0, ATH3K_DNLOAD, USB_TYPE_VENDOR, 0, 0, |
---|
| 293 | + firmware->data, size, USB_CTRL_SET_TIMEOUT, |
---|
| 294 | + GFP_KERNEL); |
---|
| 295 | + if (ret) { |
---|
339 | 296 | BT_ERR("Can't change to loading configuration err"); |
---|
340 | 297 | kfree(send_buf); |
---|
341 | 298 | return ret; |
---|
.. | .. |
---|
356 | 313 | err = usb_bulk_msg(udev, pipe, send_buf, size, |
---|
357 | 314 | &len, 3000); |
---|
358 | 315 | if (err || (len != size)) { |
---|
359 | | - ath3k_log_failed_loading(err, len, size); |
---|
| 316 | + ath3k_log_failed_loading(err, len, size, count); |
---|
360 | 317 | kfree(send_buf); |
---|
361 | 318 | return err; |
---|
362 | 319 | } |
---|
.. | .. |
---|
368 | 325 | return 0; |
---|
369 | 326 | } |
---|
370 | 327 | |
---|
371 | | -static int ath3k_switch_pid(struct usb_device *udev) |
---|
| 328 | +static void ath3k_switch_pid(struct usb_device *udev) |
---|
372 | 329 | { |
---|
373 | | - int pipe = 0; |
---|
374 | | - |
---|
375 | | - pipe = usb_sndctrlpipe(udev, 0); |
---|
376 | | - return usb_control_msg(udev, pipe, USB_REG_SWITCH_VID_PID, |
---|
377 | | - USB_TYPE_VENDOR, 0, 0, |
---|
378 | | - NULL, 0, USB_CTRL_SET_TIMEOUT); |
---|
| 330 | + usb_control_msg_send(udev, 0, USB_REG_SWITCH_VID_PID, USB_TYPE_VENDOR, |
---|
| 331 | + 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT, GFP_KERNEL); |
---|
379 | 332 | } |
---|
380 | 333 | |
---|
381 | 334 | static int ath3k_set_normal_mode(struct usb_device *udev) |
---|
382 | 335 | { |
---|
383 | 336 | unsigned char fw_state; |
---|
384 | | - int pipe = 0, ret; |
---|
| 337 | + int ret; |
---|
385 | 338 | |
---|
386 | 339 | ret = ath3k_get_state(udev, &fw_state); |
---|
387 | | - if (ret < 0) { |
---|
| 340 | + if (ret) { |
---|
388 | 341 | BT_ERR("Can't get state to change to normal mode err"); |
---|
389 | 342 | return ret; |
---|
390 | 343 | } |
---|
.. | .. |
---|
394 | 347 | return 0; |
---|
395 | 348 | } |
---|
396 | 349 | |
---|
397 | | - pipe = usb_sndctrlpipe(udev, 0); |
---|
398 | | - return usb_control_msg(udev, pipe, ATH3K_SET_NORMAL_MODE, |
---|
399 | | - USB_TYPE_VENDOR, 0, 0, |
---|
400 | | - NULL, 0, USB_CTRL_SET_TIMEOUT); |
---|
| 350 | + return usb_control_msg_send(udev, 0, ATH3K_SET_NORMAL_MODE, |
---|
| 351 | + USB_TYPE_VENDOR, 0, 0, NULL, 0, |
---|
| 352 | + USB_CTRL_SET_TIMEOUT, GFP_KERNEL); |
---|
401 | 353 | } |
---|
402 | 354 | |
---|
403 | 355 | static int ath3k_load_patch(struct usb_device *udev) |
---|
.. | .. |
---|
410 | 362 | int ret; |
---|
411 | 363 | |
---|
412 | 364 | ret = ath3k_get_state(udev, &fw_state); |
---|
413 | | - if (ret < 0) { |
---|
| 365 | + if (ret) { |
---|
414 | 366 | BT_ERR("Can't get state to change to load ram patch err"); |
---|
415 | 367 | return ret; |
---|
416 | 368 | } |
---|
.. | .. |
---|
421 | 373 | } |
---|
422 | 374 | |
---|
423 | 375 | ret = ath3k_get_version(udev, &fw_version); |
---|
424 | | - if (ret < 0) { |
---|
| 376 | + if (ret) { |
---|
425 | 377 | BT_ERR("Can't get version to change to load ram patch err"); |
---|
426 | 378 | return ret; |
---|
427 | 379 | } |
---|
.. | .. |
---|
462 | 414 | int clk_value, ret; |
---|
463 | 415 | |
---|
464 | 416 | ret = ath3k_get_state(udev, &fw_state); |
---|
465 | | - if (ret < 0) { |
---|
| 417 | + if (ret) { |
---|
466 | 418 | BT_ERR("Can't get state to change to load configuration err"); |
---|
467 | 419 | return -EBUSY; |
---|
468 | 420 | } |
---|
469 | 421 | |
---|
470 | 422 | ret = ath3k_get_version(udev, &fw_version); |
---|
471 | | - if (ret < 0) { |
---|
| 423 | + if (ret) { |
---|
472 | 424 | BT_ERR("Can't get version to change to load ram patch err"); |
---|
473 | 425 | return ret; |
---|
474 | 426 | } |
---|
.. | .. |
---|
542 | 494 | return ret; |
---|
543 | 495 | } |
---|
544 | 496 | ret = ath3k_set_normal_mode(udev); |
---|
545 | | - if (ret < 0) { |
---|
| 497 | + if (ret) { |
---|
546 | 498 | BT_ERR("Set normal mode failed"); |
---|
547 | 499 | return ret; |
---|
548 | 500 | } |
---|