| Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 1 | /* bnx2i_sysfs.c: Broadcom NetXtreme II iSCSI driver. | 
 | 2 |  * | 
| Eddie Wai | 11cec1e | 2010-11-23 15:29:31 -0800 | [diff] [blame] | 3 |  * Copyright (c) 2004 - 2010 Broadcom Corporation | 
| Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 4 |  * | 
 | 5 |  * This program is free software; you can redistribute it and/or modify | 
 | 6 |  * it under the terms of the GNU General Public License as published by | 
 | 7 |  * the Free Software Foundation. | 
 | 8 |  * | 
 | 9 |  * Written by: Anil Veerabhadrappa (anilgv@broadcom.com) | 
| Eddie Wai | 11cec1e | 2010-11-23 15:29:31 -0800 | [diff] [blame] | 10 |  * Maintained by: Eddie Wai (eddie.wai@broadcom.com) | 
| Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 11 |  */ | 
 | 12 |  | 
 | 13 | #include "bnx2i.h" | 
 | 14 |  | 
 | 15 | /** | 
 | 16 |  * bnx2i_dev_to_hba - maps dev pointer to adapter struct | 
 | 17 |  * @dev:	device pointer | 
 | 18 |  * | 
 | 19 |  * Map device to hba structure | 
 | 20 |  */ | 
 | 21 | static inline struct bnx2i_hba *bnx2i_dev_to_hba(struct device *dev) | 
 | 22 | { | 
 | 23 | 	struct Scsi_Host *shost = class_to_shost(dev); | 
 | 24 | 	return iscsi_host_priv(shost); | 
 | 25 | } | 
 | 26 |  | 
 | 27 |  | 
 | 28 | /** | 
 | 29 |  * bnx2i_show_sq_info - return(s currently configured send queue (SQ) size | 
 | 30 |  * @dev:	device pointer | 
 | 31 |  * @buf:	buffer to return current SQ size parameter | 
 | 32 |  * | 
 | 33 |  * Returns current SQ size parameter, this paramater determines the number | 
 | 34 |  * outstanding iSCSI commands supported on a connection | 
 | 35 |  */ | 
 | 36 | static ssize_t bnx2i_show_sq_info(struct device *dev, | 
 | 37 | 				  struct device_attribute *attr, char *buf) | 
 | 38 | { | 
 | 39 | 	struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev); | 
 | 40 |  | 
 | 41 | 	return sprintf(buf, "0x%x\n", hba->max_sqes); | 
 | 42 | } | 
 | 43 |  | 
 | 44 |  | 
 | 45 | /** | 
 | 46 |  * bnx2i_set_sq_info - update send queue (SQ) size parameter | 
 | 47 |  * @dev:	device pointer | 
 | 48 |  * @buf:	buffer to return current SQ size parameter | 
 | 49 |  * @count:	parameter buffer size | 
 | 50 |  * | 
 | 51 |  * Interface for user to change shared queue size allocated for each conn | 
 | 52 |  * Must be within SQ limits and a power of 2. For the latter this is needed | 
 | 53 |  * because of how libiscsi preallocates tasks. | 
 | 54 |  */ | 
 | 55 | static ssize_t bnx2i_set_sq_info(struct device *dev, | 
 | 56 | 				 struct device_attribute *attr, | 
 | 57 | 				 const char *buf, size_t count) | 
 | 58 | { | 
 | 59 | 	struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev); | 
 | 60 | 	u32 val; | 
 | 61 | 	int max_sq_size; | 
 | 62 |  | 
 | 63 | 	if (hba->ofld_conns_active) | 
 | 64 | 		goto skip_config; | 
 | 65 |  | 
 | 66 | 	if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) | 
 | 67 | 		max_sq_size = BNX2I_5770X_SQ_WQES_MAX; | 
 | 68 | 	else | 
 | 69 | 		max_sq_size = BNX2I_570X_SQ_WQES_MAX; | 
 | 70 |  | 
 | 71 | 	if (sscanf(buf, " 0x%x ", &val) > 0) { | 
 | 72 | 		if ((val >= BNX2I_SQ_WQES_MIN) && (val <= max_sq_size) && | 
 | 73 | 		    (is_power_of_2(val))) | 
 | 74 | 			hba->max_sqes = val; | 
 | 75 | 	} | 
 | 76 |  | 
 | 77 | 	return count; | 
 | 78 |  | 
 | 79 | skip_config: | 
 | 80 | 	printk(KERN_ERR "bnx2i: device busy, cannot change SQ size\n"); | 
 | 81 | 	return 0; | 
 | 82 | } | 
 | 83 |  | 
 | 84 |  | 
 | 85 | /** | 
 | 86 |  * bnx2i_show_ccell_info - returns command cell (HQ) size | 
 | 87 |  * @dev:	device pointer | 
 | 88 |  * @buf:	buffer to return current SQ size parameter | 
 | 89 |  * | 
 | 90 |  * returns per-connection TCP history queue size parameter | 
 | 91 |  */ | 
 | 92 | static ssize_t bnx2i_show_ccell_info(struct device *dev, | 
 | 93 | 				     struct device_attribute *attr, char *buf) | 
 | 94 | { | 
 | 95 | 	struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev); | 
 | 96 |  | 
 | 97 | 	return sprintf(buf, "0x%x\n", hba->num_ccell); | 
 | 98 | } | 
 | 99 |  | 
 | 100 |  | 
 | 101 | /** | 
 | 102 |  * bnx2i_get_link_state - set command cell (HQ) size | 
 | 103 |  * @dev:	device pointer | 
 | 104 |  * @buf:	buffer to return current SQ size parameter | 
 | 105 |  * @count:	parameter buffer size | 
 | 106 |  * | 
 | 107 |  * updates per-connection TCP history queue size parameter | 
 | 108 |  */ | 
 | 109 | static ssize_t bnx2i_set_ccell_info(struct device *dev, | 
 | 110 | 				    struct device_attribute *attr, | 
 | 111 | 				    const char *buf, size_t count) | 
 | 112 | { | 
 | 113 | 	u32 val; | 
 | 114 | 	struct bnx2i_hba *hba = bnx2i_dev_to_hba(dev); | 
 | 115 |  | 
 | 116 | 	if (hba->ofld_conns_active) | 
 | 117 | 		goto skip_config; | 
 | 118 |  | 
 | 119 | 	if (sscanf(buf, " 0x%x ", &val) > 0) { | 
 | 120 | 		if ((val >= BNX2I_CCELLS_MIN) && | 
 | 121 | 		    (val <= BNX2I_CCELLS_MAX)) { | 
 | 122 | 			hba->num_ccell = val; | 
 | 123 | 		} | 
 | 124 | 	} | 
 | 125 |  | 
 | 126 | 	return count; | 
 | 127 |  | 
 | 128 | skip_config: | 
 | 129 | 	printk(KERN_ERR "bnx2i: device busy, cannot change CCELL size\n"); | 
 | 130 | 	return 0; | 
 | 131 | } | 
 | 132 |  | 
 | 133 |  | 
 | 134 | static DEVICE_ATTR(sq_size, S_IRUGO | S_IWUSR, | 
 | 135 | 		   bnx2i_show_sq_info, bnx2i_set_sq_info); | 
 | 136 | static DEVICE_ATTR(num_ccell, S_IRUGO | S_IWUSR, | 
 | 137 | 		   bnx2i_show_ccell_info, bnx2i_set_ccell_info); | 
 | 138 |  | 
 | 139 | struct device_attribute *bnx2i_dev_attributes[] = { | 
 | 140 | 	&dev_attr_sq_size, | 
 | 141 | 	&dev_attr_num_ccell, | 
 | 142 | 	NULL | 
 | 143 | }; |