162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Special Initializers for certain USB Mass Storage devices 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Current development and maintenance by: 662306a36Sopenharmony_ci * (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net) 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * This driver is based on the 'USB Mass Storage Class' document. This 962306a36Sopenharmony_ci * describes in detail the protocol used to communicate with such 1062306a36Sopenharmony_ci * devices. Clearly, the designers had SCSI and ATAPI commands in 1162306a36Sopenharmony_ci * mind when they created this document. The commands are all very 1262306a36Sopenharmony_ci * similar to commands in the SCSI-II and ATAPI specifications. 1362306a36Sopenharmony_ci * 1462306a36Sopenharmony_ci * It is important to note that in a number of cases this class 1562306a36Sopenharmony_ci * exhibits class-specific exemptions from the USB specification. 1662306a36Sopenharmony_ci * Notably the usage of NAK, STALL and ACK differs from the norm, in 1762306a36Sopenharmony_ci * that they are used to communicate wait, failed and OK on commands. 1862306a36Sopenharmony_ci * 1962306a36Sopenharmony_ci * Also, for certain devices, the interrupt endpoint is used to convey 2062306a36Sopenharmony_ci * status of a command. 2162306a36Sopenharmony_ci */ 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci#include <linux/errno.h> 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci#include "usb.h" 2662306a36Sopenharmony_ci#include "initializers.h" 2762306a36Sopenharmony_ci#include "debug.h" 2862306a36Sopenharmony_ci#include "transport.h" 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci/* 3162306a36Sopenharmony_ci * This places the Shuttle/SCM USB<->SCSI bridge devices in multi-target 3262306a36Sopenharmony_ci * mode 3362306a36Sopenharmony_ci */ 3462306a36Sopenharmony_ciint usb_stor_euscsi_init(struct us_data *us) 3562306a36Sopenharmony_ci{ 3662306a36Sopenharmony_ci int result; 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci usb_stor_dbg(us, "Attempting to init eUSCSI bridge...\n"); 3962306a36Sopenharmony_ci result = usb_stor_control_msg(us, us->send_ctrl_pipe, 4062306a36Sopenharmony_ci 0x0C, USB_RECIP_INTERFACE | USB_TYPE_VENDOR, 4162306a36Sopenharmony_ci 0x01, 0x0, NULL, 0x0, 5 * HZ); 4262306a36Sopenharmony_ci usb_stor_dbg(us, "-- result is %d\n", result); 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci return 0; 4562306a36Sopenharmony_ci} 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci/* 4862306a36Sopenharmony_ci * This function is required to activate all four slots on the UCR-61S2B 4962306a36Sopenharmony_ci * flash reader 5062306a36Sopenharmony_ci */ 5162306a36Sopenharmony_ciint usb_stor_ucr61s2b_init(struct us_data *us) 5262306a36Sopenharmony_ci{ 5362306a36Sopenharmony_ci struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap*) us->iobuf; 5462306a36Sopenharmony_ci struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap*) us->iobuf; 5562306a36Sopenharmony_ci int res; 5662306a36Sopenharmony_ci unsigned int partial; 5762306a36Sopenharmony_ci static char init_string[] = "\xec\x0a\x06\x00$PCCHIPS"; 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci usb_stor_dbg(us, "Sending UCR-61S2B initialization packet...\n"); 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 6262306a36Sopenharmony_ci bcb->Tag = 0; 6362306a36Sopenharmony_ci bcb->DataTransferLength = cpu_to_le32(0); 6462306a36Sopenharmony_ci bcb->Flags = bcb->Lun = 0; 6562306a36Sopenharmony_ci bcb->Length = sizeof(init_string) - 1; 6662306a36Sopenharmony_ci memset(bcb->CDB, 0, sizeof(bcb->CDB)); 6762306a36Sopenharmony_ci memcpy(bcb->CDB, init_string, sizeof(init_string) - 1); 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci res = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, bcb, 7062306a36Sopenharmony_ci US_BULK_CB_WRAP_LEN, &partial); 7162306a36Sopenharmony_ci if (res) 7262306a36Sopenharmony_ci return -EIO; 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci usb_stor_dbg(us, "Getting status packet...\n"); 7562306a36Sopenharmony_ci res = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, 7662306a36Sopenharmony_ci US_BULK_CS_WRAP_LEN, &partial); 7762306a36Sopenharmony_ci if (res) 7862306a36Sopenharmony_ci return -EIO; 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci return 0; 8162306a36Sopenharmony_ci} 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci/* This places the HUAWEI E220 devices in multi-port mode */ 8462306a36Sopenharmony_ciint usb_stor_huawei_e220_init(struct us_data *us) 8562306a36Sopenharmony_ci{ 8662306a36Sopenharmony_ci int result; 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci result = usb_stor_control_msg(us, us->send_ctrl_pipe, 8962306a36Sopenharmony_ci USB_REQ_SET_FEATURE, 9062306a36Sopenharmony_ci USB_TYPE_STANDARD | USB_RECIP_DEVICE, 9162306a36Sopenharmony_ci 0x01, 0x0, NULL, 0x0, 1 * HZ); 9262306a36Sopenharmony_ci usb_stor_dbg(us, "Huawei mode set result is %d\n", result); 9362306a36Sopenharmony_ci return 0; 9462306a36Sopenharmony_ci} 95