Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: cdc_ncm: allow tuning min_tx_pkt

The min_tx_pkt variable decides the cutoff point where the driver
will stop padding out NTBs to maximum size. The padding is a tradeoff
where we use some USB bus bandwidth to allow the device to receive
fixed size buffers. Different devices will have different optimal
settings, spanning from no padding at all to padding every NTB.
There is no way to automatically figure out which setting is best
for a specific device.

The default value is a reasonable tradeoff, calculated based on the
USB packet size and out NTB max size. This may have to be changed
along with any tx_max changes.

Signed-off-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Bjørn Mork and committed by
David S. Miller
39eb7e0e 871578c9

+24
+24
drivers/net/usb/cdc_ncm.c
··· 185 185 return val; 186 186 } 187 187 188 + static ssize_t cdc_ncm_show_min_tx_pkt(struct device *d, struct device_attribute *attr, char *buf) 189 + { 190 + struct usbnet *dev = netdev_priv(to_net_dev(d)); 191 + struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; 192 + 193 + return sprintf(buf, "%u\n", ctx->min_tx_pkt); 194 + } 195 + 188 196 static ssize_t cdc_ncm_show_rx_max(struct device *d, struct device_attribute *attr, char *buf) 189 197 { 190 198 struct usbnet *dev = netdev_priv(to_net_dev(d)); ··· 215 207 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; 216 208 217 209 return sprintf(buf, "%u\n", ctx->timer_interval / (u32)NSEC_PER_USEC); 210 + } 211 + 212 + static ssize_t cdc_ncm_store_min_tx_pkt(struct device *d, struct device_attribute *attr, const char *buf, size_t len) 213 + { 214 + struct usbnet *dev = netdev_priv(to_net_dev(d)); 215 + struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; 216 + unsigned long val; 217 + 218 + /* no need to restrict values - anything from 0 to infinity is OK */ 219 + if (kstrtoul(buf, 0, &val)) 220 + return -EINVAL; 221 + 222 + ctx->min_tx_pkt = val; 223 + return len; 218 224 } 219 225 220 226 static ssize_t cdc_ncm_store_rx_max(struct device *d, struct device_attribute *attr, const char *buf, size_t len) ··· 278 256 return len; 279 257 } 280 258 259 + static DEVICE_ATTR(min_tx_pkt, S_IRUGO | S_IWUSR, cdc_ncm_show_min_tx_pkt, cdc_ncm_store_min_tx_pkt); 281 260 static DEVICE_ATTR(rx_max, S_IRUGO | S_IWUSR, cdc_ncm_show_rx_max, cdc_ncm_store_rx_max); 282 261 static DEVICE_ATTR(tx_max, S_IRUGO | S_IWUSR, cdc_ncm_show_tx_max, cdc_ncm_store_tx_max); 283 262 static DEVICE_ATTR(tx_timer_usecs, S_IRUGO | S_IWUSR, cdc_ncm_show_tx_timer_usecs, cdc_ncm_store_tx_timer_usecs); ··· 304 281 NCM_PARM_ATTR(wNtbOutMaxDatagrams, "%u", le16_to_cpu); 305 282 306 283 static struct attribute *cdc_ncm_sysfs_attrs[] = { 284 + &dev_attr_min_tx_pkt.attr, 307 285 &dev_attr_rx_max.attr, 308 286 &dev_attr_tx_max.attr, 309 287 &dev_attr_tx_timer_usecs.attr,