18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright 2014 Cisco Systems, Inc. All rights reserved. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * This program is free software; you may redistribute it and/or modify 58c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by 68c2ecf20Sopenharmony_ci * the Free Software Foundation; version 2 of the License. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 98c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 108c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 118c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 128c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 138c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 148c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 158c2ecf20Sopenharmony_ci * SOFTWARE. 168c2ecf20Sopenharmony_ci */ 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#include <linux/string.h> 198c2ecf20Sopenharmony_ci#include <linux/device.h> 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#include "snic.h" 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistatic ssize_t 248c2ecf20Sopenharmony_cisnic_show_sym_name(struct device *dev, 258c2ecf20Sopenharmony_ci struct device_attribute *attr, 268c2ecf20Sopenharmony_ci char *buf) 278c2ecf20Sopenharmony_ci{ 288c2ecf20Sopenharmony_ci struct snic *snic = shost_priv(class_to_shost(dev)); 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci return snprintf(buf, PAGE_SIZE, "%s\n", snic->name); 318c2ecf20Sopenharmony_ci} 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cistatic ssize_t 348c2ecf20Sopenharmony_cisnic_show_state(struct device *dev, 358c2ecf20Sopenharmony_ci struct device_attribute *attr, 368c2ecf20Sopenharmony_ci char *buf) 378c2ecf20Sopenharmony_ci{ 388c2ecf20Sopenharmony_ci struct snic *snic = shost_priv(class_to_shost(dev)); 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci return snprintf(buf, PAGE_SIZE, "%s\n", 418c2ecf20Sopenharmony_ci snic_state_str[snic_get_state(snic)]); 428c2ecf20Sopenharmony_ci} 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistatic ssize_t 458c2ecf20Sopenharmony_cisnic_show_drv_version(struct device *dev, 468c2ecf20Sopenharmony_ci struct device_attribute *attr, 478c2ecf20Sopenharmony_ci char *buf) 488c2ecf20Sopenharmony_ci{ 498c2ecf20Sopenharmony_ci return snprintf(buf, PAGE_SIZE, "%s\n", SNIC_DRV_VERSION); 508c2ecf20Sopenharmony_ci} 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistatic ssize_t 538c2ecf20Sopenharmony_cisnic_show_link_state(struct device *dev, 548c2ecf20Sopenharmony_ci struct device_attribute *attr, 558c2ecf20Sopenharmony_ci char *buf) 568c2ecf20Sopenharmony_ci{ 578c2ecf20Sopenharmony_ci struct snic *snic = shost_priv(class_to_shost(dev)); 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci if (snic->config.xpt_type == SNIC_DAS) 608c2ecf20Sopenharmony_ci snic->link_status = svnic_dev_link_status(snic->vdev); 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci return snprintf(buf, PAGE_SIZE, "%s\n", 638c2ecf20Sopenharmony_ci (snic->link_status) ? "Link Up" : "Link Down"); 648c2ecf20Sopenharmony_ci} 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistatic DEVICE_ATTR(snic_sym_name, S_IRUGO, snic_show_sym_name, NULL); 678c2ecf20Sopenharmony_cistatic DEVICE_ATTR(snic_state, S_IRUGO, snic_show_state, NULL); 688c2ecf20Sopenharmony_cistatic DEVICE_ATTR(drv_version, S_IRUGO, snic_show_drv_version, NULL); 698c2ecf20Sopenharmony_cistatic DEVICE_ATTR(link_state, S_IRUGO, snic_show_link_state, NULL); 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_cistruct device_attribute *snic_attrs[] = { 728c2ecf20Sopenharmony_ci &dev_attr_snic_sym_name, 738c2ecf20Sopenharmony_ci &dev_attr_snic_state, 748c2ecf20Sopenharmony_ci &dev_attr_drv_version, 758c2ecf20Sopenharmony_ci &dev_attr_link_state, 768c2ecf20Sopenharmony_ci NULL, 778c2ecf20Sopenharmony_ci}; 78