18c2ecf20Sopenharmony_ci/* bnx2i_sysfs.c: QLogic NetXtreme II iSCSI driver. 28c2ecf20Sopenharmony_ci * 38c2ecf20Sopenharmony_ci * Copyright (c) 2004 - 2013 Broadcom Corporation 48c2ecf20Sopenharmony_ci * Copyright (c) 2014, QLogic Corporation 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify 78c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by 88c2ecf20Sopenharmony_ci * the Free Software Foundation. 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * Written by: Anil Veerabhadrappa (anilgv@broadcom.com) 118c2ecf20Sopenharmony_ci * Previously Maintained by: Eddie Wai (eddie.wai@broadcom.com) 128c2ecf20Sopenharmony_ci * Maintained by: QLogic-Storage-Upstream@qlogic.com 138c2ecf20Sopenharmony_ci */ 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include "bnx2i.h" 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/** 188c2ecf20Sopenharmony_ci * bnx2i_dev_to_hba - maps dev pointer to adapter struct 198c2ecf20Sopenharmony_ci * @dev: device pointer 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * Map device to hba structure 228c2ecf20Sopenharmony_ci */ 238c2ecf20Sopenharmony_cistatic inline struct bnx2i_hba *bnx2i_dev_to_hba(struct device *dev) 248c2ecf20Sopenharmony_ci{ 258c2ecf20Sopenharmony_ci struct Scsi_Host *shost = class_to_shost(dev); 268c2ecf20Sopenharmony_ci return iscsi_host_priv(shost); 278c2ecf20Sopenharmony_ci} 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/** 318c2ecf20Sopenharmony_ci * bnx2i_show_sq_info - return(s currently configured send queue (SQ) size 328c2ecf20Sopenharmony_ci * @dev: device pointer 338c2ecf20Sopenharmony_ci * @attr: device attribute (unused) 348c2ecf20Sopenharmony_ci * @buf: buffer to return current SQ size parameter 358c2ecf20Sopenharmony_ci * 368c2ecf20Sopenharmony_ci * Returns current SQ size parameter, this paramater determines the number 378c2ecf20Sopenharmony_ci * outstanding iSCSI commands supported on a connection 388c2ecf20Sopenharmony_ci */ 398c2ecf20Sopenharmony_cistatic ssize_t bnx2i_show_sq_info(struct device *dev, 408c2ecf20Sopenharmony_ci struct device_attribute *attr, char *buf) 418c2ecf20Sopenharmony_ci{ 428c2ecf20Sopenharmony_ci struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev); 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci return sprintf(buf, "0x%x\n", hba->max_sqes); 458c2ecf20Sopenharmony_ci} 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci/** 498c2ecf20Sopenharmony_ci * bnx2i_set_sq_info - update send queue (SQ) size parameter 508c2ecf20Sopenharmony_ci * @dev: device pointer 518c2ecf20Sopenharmony_ci * @attr: device attribute (unused) 528c2ecf20Sopenharmony_ci * @buf: buffer to return current SQ size parameter 538c2ecf20Sopenharmony_ci * @count: parameter buffer size 548c2ecf20Sopenharmony_ci * 558c2ecf20Sopenharmony_ci * Interface for user to change shared queue size allocated for each conn 568c2ecf20Sopenharmony_ci * Must be within SQ limits and a power of 2. For the latter this is needed 578c2ecf20Sopenharmony_ci * because of how libiscsi preallocates tasks. 588c2ecf20Sopenharmony_ci */ 598c2ecf20Sopenharmony_cistatic ssize_t bnx2i_set_sq_info(struct device *dev, 608c2ecf20Sopenharmony_ci struct device_attribute *attr, 618c2ecf20Sopenharmony_ci const char *buf, size_t count) 628c2ecf20Sopenharmony_ci{ 638c2ecf20Sopenharmony_ci struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev); 648c2ecf20Sopenharmony_ci u32 val; 658c2ecf20Sopenharmony_ci int max_sq_size; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci if (hba->ofld_conns_active) 688c2ecf20Sopenharmony_ci goto skip_config; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) 718c2ecf20Sopenharmony_ci max_sq_size = BNX2I_5770X_SQ_WQES_MAX; 728c2ecf20Sopenharmony_ci else 738c2ecf20Sopenharmony_ci max_sq_size = BNX2I_570X_SQ_WQES_MAX; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci if (sscanf(buf, " 0x%x ", &val) > 0) { 768c2ecf20Sopenharmony_ci if ((val >= BNX2I_SQ_WQES_MIN) && (val <= max_sq_size) && 778c2ecf20Sopenharmony_ci (is_power_of_2(val))) 788c2ecf20Sopenharmony_ci hba->max_sqes = val; 798c2ecf20Sopenharmony_ci } 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci return count; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ciskip_config: 848c2ecf20Sopenharmony_ci printk(KERN_ERR "bnx2i: device busy, cannot change SQ size\n"); 858c2ecf20Sopenharmony_ci return 0; 868c2ecf20Sopenharmony_ci} 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci/** 908c2ecf20Sopenharmony_ci * bnx2i_show_ccell_info - returns command cell (HQ) size 918c2ecf20Sopenharmony_ci * @dev: device pointer 928c2ecf20Sopenharmony_ci * @attr: device attribute (unused) 938c2ecf20Sopenharmony_ci * @buf: buffer to return current SQ size parameter 948c2ecf20Sopenharmony_ci * 958c2ecf20Sopenharmony_ci * returns per-connection TCP history queue size parameter 968c2ecf20Sopenharmony_ci */ 978c2ecf20Sopenharmony_cistatic ssize_t bnx2i_show_ccell_info(struct device *dev, 988c2ecf20Sopenharmony_ci struct device_attribute *attr, char *buf) 998c2ecf20Sopenharmony_ci{ 1008c2ecf20Sopenharmony_ci struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev); 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci return sprintf(buf, "0x%x\n", hba->num_ccell); 1038c2ecf20Sopenharmony_ci} 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci/** 1078c2ecf20Sopenharmony_ci * bnx2i_get_link_state - set command cell (HQ) size 1088c2ecf20Sopenharmony_ci * @dev: device pointer 1098c2ecf20Sopenharmony_ci * @attr: device attribute (unused) 1108c2ecf20Sopenharmony_ci * @buf: buffer to return current SQ size parameter 1118c2ecf20Sopenharmony_ci * @count: parameter buffer size 1128c2ecf20Sopenharmony_ci * 1138c2ecf20Sopenharmony_ci * updates per-connection TCP history queue size parameter 1148c2ecf20Sopenharmony_ci */ 1158c2ecf20Sopenharmony_cistatic ssize_t bnx2i_set_ccell_info(struct device *dev, 1168c2ecf20Sopenharmony_ci struct device_attribute *attr, 1178c2ecf20Sopenharmony_ci const char *buf, size_t count) 1188c2ecf20Sopenharmony_ci{ 1198c2ecf20Sopenharmony_ci u32 val; 1208c2ecf20Sopenharmony_ci struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev); 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci if (hba->ofld_conns_active) 1238c2ecf20Sopenharmony_ci goto skip_config; 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci if (sscanf(buf, " 0x%x ", &val) > 0) { 1268c2ecf20Sopenharmony_ci if ((val >= BNX2I_CCELLS_MIN) && 1278c2ecf20Sopenharmony_ci (val <= BNX2I_CCELLS_MAX)) { 1288c2ecf20Sopenharmony_ci hba->num_ccell = val; 1298c2ecf20Sopenharmony_ci } 1308c2ecf20Sopenharmony_ci } 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci return count; 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ciskip_config: 1358c2ecf20Sopenharmony_ci printk(KERN_ERR "bnx2i: device busy, cannot change CCELL size\n"); 1368c2ecf20Sopenharmony_ci return 0; 1378c2ecf20Sopenharmony_ci} 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_cistatic DEVICE_ATTR(sq_size, S_IRUGO | S_IWUSR, 1418c2ecf20Sopenharmony_ci bnx2i_show_sq_info, bnx2i_set_sq_info); 1428c2ecf20Sopenharmony_cistatic DEVICE_ATTR(num_ccell, S_IRUGO | S_IWUSR, 1438c2ecf20Sopenharmony_ci bnx2i_show_ccell_info, bnx2i_set_ccell_info); 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_cistruct device_attribute *bnx2i_dev_attributes[] = { 1468c2ecf20Sopenharmony_ci &dev_attr_sq_size, 1478c2ecf20Sopenharmony_ci &dev_attr_num_ccell, 1488c2ecf20Sopenharmony_ci NULL 1498c2ecf20Sopenharmony_ci}; 150