···228228#define HIDPP20_ERROR_INVALID_ARGS 0x02229229#define HIDPP20_ERROR_OUT_OF_RANGE 0x03230230#define HIDPP20_ERROR_HW_ERROR 0x04231231-#define HIDPP20_ERROR_LOGITECH_INTERNAL 0x05231231+#define HIDPP20_ERROR_NOT_ALLOWED 0x05232232#define HIDPP20_ERROR_INVALID_FEATURE_INDEX 0x06233233#define HIDPP20_ERROR_INVALID_FUNCTION_ID 0x07234234#define HIDPP20_ERROR_BUSY 0x08···275275}276276277277/*278278- * hidpp_send_message_sync() returns 0 in case of success, and something else279279- * in case of a failure.280280- * - If ' something else' is positive, that means that an error has been raised281281- * by the protocol itself.282282- * - If ' something else' is negative, that means that we had a classic error283283- * (-ENOMEM, -EPIPE, etc...)278278+ * Effectively send the message to the device, waiting for its answer.279279+ *280280+ * Must be called with hidpp->send_mutex locked281281+ *282282+ * Same return protocol than hidpp_send_message_sync():283283+ * - success on 0284284+ * - negative error means transport error285285+ * - positive value means protocol error284286 */285285-static int hidpp_send_message_sync(struct hidpp_device *hidpp,287287+static int __do_hidpp_send_message_sync(struct hidpp_device *hidpp,286288 struct hidpp_report *message,287289 struct hidpp_report *response)288290{289289- int ret = -1;290290- int max_retries = 3;291291+ int ret;291292292292- mutex_lock(&hidpp->send_mutex);293293+ __must_hold(&hidpp->send_mutex);293294294295 hidpp->send_receive_buf = response;295296 hidpp->answer_available = false;···301300 */302301 *response = *message;303302304304- for (; max_retries != 0 && ret; max_retries--) {305305- ret = __hidpp_send_report(hidpp->hid_dev, message);306306-307307- if (ret) {308308- dbg_hid("__hidpp_send_report returned err: %d\n", ret);309309- memset(response, 0, sizeof(struct hidpp_report));310310- break;311311- }312312-313313- if (!wait_event_timeout(hidpp->wait, hidpp->answer_available,314314- 5*HZ)) {315315- dbg_hid("%s:timeout waiting for response\n", __func__);316316- memset(response, 0, sizeof(struct hidpp_report));317317- ret = -ETIMEDOUT;318318- break;319319- }320320-321321- if (response->report_id == REPORT_ID_HIDPP_SHORT &&322322- response->rap.sub_id == HIDPP_ERROR) {323323- ret = response->rap.params[1];324324- dbg_hid("%s:got hidpp error %02X\n", __func__, ret);325325- break;326326- }327327-328328- if ((response->report_id == REPORT_ID_HIDPP_LONG ||329329- response->report_id == REPORT_ID_HIDPP_VERY_LONG) &&330330- response->fap.feature_index == HIDPP20_ERROR) {331331- ret = response->fap.params[1];332332- if (ret != HIDPP20_ERROR_BUSY) {333333- dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, ret);334334- break;335335- }336336- dbg_hid("%s:got busy hidpp 2.0 error %02X, retrying\n", __func__, ret);337337- }303303+ ret = __hidpp_send_report(hidpp->hid_dev, message);304304+ if (ret) {305305+ dbg_hid("__hidpp_send_report returned err: %d\n", ret);306306+ memset(response, 0, sizeof(struct hidpp_report));307307+ return ret;338308 }309309+310310+ if (!wait_event_timeout(hidpp->wait, hidpp->answer_available,311311+ 5*HZ)) {312312+ dbg_hid("%s:timeout waiting for response\n", __func__);313313+ memset(response, 0, sizeof(struct hidpp_report));314314+ return -ETIMEDOUT;315315+ }316316+317317+ if (response->report_id == REPORT_ID_HIDPP_SHORT &&318318+ response->rap.sub_id == HIDPP_ERROR) {319319+ ret = response->rap.params[1];320320+ dbg_hid("%s:got hidpp error %02X\n", __func__, ret);321321+ return ret;322322+ }323323+324324+ if ((response->report_id == REPORT_ID_HIDPP_LONG ||325325+ response->report_id == REPORT_ID_HIDPP_VERY_LONG) &&326326+ response->fap.feature_index == HIDPP20_ERROR) {327327+ ret = response->fap.params[1];328328+ dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, ret);329329+ return ret;330330+ }331331+332332+ return 0;333333+}334334+335335+/*336336+ * hidpp_send_message_sync() returns 0 in case of success, and something else337337+ * in case of a failure.338338+ *339339+ * See __do_hidpp_send_message_sync() for a detailed explanation of the returned340340+ * value.341341+ */342342+static int hidpp_send_message_sync(struct hidpp_device *hidpp,343343+ struct hidpp_report *message,344344+ struct hidpp_report *response)345345+{346346+ int ret;347347+ int max_retries = 3;348348+349349+ mutex_lock(&hidpp->send_mutex);350350+351351+ do {352352+ ret = __do_hidpp_send_message_sync(hidpp, message, response);353353+ if (ret != HIDPP20_ERROR_BUSY)354354+ break;355355+356356+ dbg_hid("%s:got busy hidpp 2.0 error %02X, retrying\n", __func__, ret);357357+ } while (--max_retries);339358340359 mutex_unlock(&hidpp->send_mutex);341360 return ret;342361343362}344363364364+/*365365+ * hidpp_send_fap_command_sync() returns 0 in case of success, and something else366366+ * in case of a failure.367367+ *368368+ * See __do_hidpp_send_message_sync() for a detailed explanation of the returned369369+ * value.370370+ */345371static int hidpp_send_fap_command_sync(struct hidpp_device *hidpp,346372 u8 feat_index, u8 funcindex_clientid, u8 *params, int param_count,347373 struct hidpp_report *response)···401373 return ret;402374}403375376376+/*377377+ * hidpp_send_rap_command_sync() returns 0 in case of success, and something else378378+ * in case of a failure.379379+ *380380+ * See __do_hidpp_send_message_sync() for a detailed explanation of the returned381381+ * value.382382+ */404383static int hidpp_send_rap_command_sync(struct hidpp_device *hidpp_dev,405384 u8 report_id, u8 sub_id, u8 reg_address, u8 *params, int param_count,406385 struct hidpp_report *response)···46554620 .driver_data = HIDPP_QUIRK_CLASS_G920 | HIDPP_QUIRK_FORCE_OUTPUT_REPORTS },46564621 { /* Logitech G Pro Gaming Mouse over USB */46574622 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC088) },46234623+ { /* Logitech G Pro X Superlight Gaming Mouse over USB */46244624+ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC094) },4658462546594626 { /* G935 Gaming Headset */46604627 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0x0a87),···46844647 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb02a) },46854648 { /* MX Master 3 mouse over Bluetooth */46864649 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb023) },46504650+ { /* MX Anywhere 3 mouse over Bluetooth */46514651+ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb025) },46874652 { /* MX Master 3S mouse over Bluetooth */46884653 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb034) },46894654 {}