18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Special Initializers for certain USB Mass Storage devices
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Current development and maintenance by:
68c2ecf20Sopenharmony_ci *   (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * This driver is based on the 'USB Mass Storage Class' document. This
98c2ecf20Sopenharmony_ci * describes in detail the protocol used to communicate with such
108c2ecf20Sopenharmony_ci * devices.  Clearly, the designers had SCSI and ATAPI commands in
118c2ecf20Sopenharmony_ci * mind when they created this document.  The commands are all very
128c2ecf20Sopenharmony_ci * similar to commands in the SCSI-II and ATAPI specifications.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * It is important to note that in a number of cases this class
158c2ecf20Sopenharmony_ci * exhibits class-specific exemptions from the USB specification.
168c2ecf20Sopenharmony_ci * Notably the usage of NAK, STALL and ACK differs from the norm, in
178c2ecf20Sopenharmony_ci * that they are used to communicate wait, failed and OK on commands.
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci * Also, for certain devices, the interrupt endpoint is used to convey
208c2ecf20Sopenharmony_ci * status of a command.
218c2ecf20Sopenharmony_ci */
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#include <linux/errno.h>
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#include "usb.h"
268c2ecf20Sopenharmony_ci#include "initializers.h"
278c2ecf20Sopenharmony_ci#include "debug.h"
288c2ecf20Sopenharmony_ci#include "transport.h"
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/*
318c2ecf20Sopenharmony_ci * This places the Shuttle/SCM USB<->SCSI bridge devices in multi-target
328c2ecf20Sopenharmony_ci * mode
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ciint usb_stor_euscsi_init(struct us_data *us)
358c2ecf20Sopenharmony_ci{
368c2ecf20Sopenharmony_ci	int result;
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci	usb_stor_dbg(us, "Attempting to init eUSCSI bridge...\n");
398c2ecf20Sopenharmony_ci	result = usb_stor_control_msg(us, us->send_ctrl_pipe,
408c2ecf20Sopenharmony_ci			0x0C, USB_RECIP_INTERFACE | USB_TYPE_VENDOR,
418c2ecf20Sopenharmony_ci			0x01, 0x0, NULL, 0x0, 5 * HZ);
428c2ecf20Sopenharmony_ci	usb_stor_dbg(us, "-- result is %d\n", result);
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	return 0;
458c2ecf20Sopenharmony_ci}
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci/*
488c2ecf20Sopenharmony_ci * This function is required to activate all four slots on the UCR-61S2B
498c2ecf20Sopenharmony_ci * flash reader
508c2ecf20Sopenharmony_ci */
518c2ecf20Sopenharmony_ciint usb_stor_ucr61s2b_init(struct us_data *us)
528c2ecf20Sopenharmony_ci{
538c2ecf20Sopenharmony_ci	struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap*) us->iobuf;
548c2ecf20Sopenharmony_ci	struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap*) us->iobuf;
558c2ecf20Sopenharmony_ci	int res;
568c2ecf20Sopenharmony_ci	unsigned int partial;
578c2ecf20Sopenharmony_ci	static char init_string[] = "\xec\x0a\x06\x00$PCCHIPS";
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	usb_stor_dbg(us, "Sending UCR-61S2B initialization packet...\n");
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
628c2ecf20Sopenharmony_ci	bcb->Tag = 0;
638c2ecf20Sopenharmony_ci	bcb->DataTransferLength = cpu_to_le32(0);
648c2ecf20Sopenharmony_ci	bcb->Flags = bcb->Lun = 0;
658c2ecf20Sopenharmony_ci	bcb->Length = sizeof(init_string) - 1;
668c2ecf20Sopenharmony_ci	memset(bcb->CDB, 0, sizeof(bcb->CDB));
678c2ecf20Sopenharmony_ci	memcpy(bcb->CDB, init_string, sizeof(init_string) - 1);
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci	res = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, bcb,
708c2ecf20Sopenharmony_ci			US_BULK_CB_WRAP_LEN, &partial);
718c2ecf20Sopenharmony_ci	if (res)
728c2ecf20Sopenharmony_ci		return -EIO;
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	usb_stor_dbg(us, "Getting status packet...\n");
758c2ecf20Sopenharmony_ci	res = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs,
768c2ecf20Sopenharmony_ci			US_BULK_CS_WRAP_LEN, &partial);
778c2ecf20Sopenharmony_ci	if (res)
788c2ecf20Sopenharmony_ci		return -EIO;
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	return 0;
818c2ecf20Sopenharmony_ci}
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci/* This places the HUAWEI E220 devices in multi-port mode */
848c2ecf20Sopenharmony_ciint usb_stor_huawei_e220_init(struct us_data *us)
858c2ecf20Sopenharmony_ci{
868c2ecf20Sopenharmony_ci	int result;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	result = usb_stor_control_msg(us, us->send_ctrl_pipe,
898c2ecf20Sopenharmony_ci				      USB_REQ_SET_FEATURE,
908c2ecf20Sopenharmony_ci				      USB_TYPE_STANDARD | USB_RECIP_DEVICE,
918c2ecf20Sopenharmony_ci				      0x01, 0x0, NULL, 0x0, 1 * HZ);
928c2ecf20Sopenharmony_ci	usb_stor_dbg(us, "Huawei mode set result is %d\n", result);
938c2ecf20Sopenharmony_ci	return 0;
948c2ecf20Sopenharmony_ci}
95