^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) *******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) ** O.S : Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) ** FILE NAME : arcmsr_attr.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) ** BY : Nick Cheng
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) ** Description: attributes exported to sysfs and device host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) ** Copyright (C) 2002 - 2005, Areca Technology Corporation All rights reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) ** Web site: www.areca.com.tw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) ** E-mail: support@areca.com.tw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) ** This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) ** it under the terms of the GNU General Public License version 2 as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) ** published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) ** This program is distributed in the hope that it will be useful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) ** but WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) ** GNU General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) ** Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) ** modification, are permitted provided that the following conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) ** are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) ** 1. Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) ** notice, this list of conditions and the following disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) ** 2. Redistributions in binary form must reproduce the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) ** notice, this list of conditions and the following disclaimer in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) ** documentation and/or other materials provided with the distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) ** 3. The name of the author may not be used to endorse or promote products
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) ** derived from this software without specific prior written permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING,BUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION)HOWEVER CAUSED AND ON ANY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) ** (INCLUDING NEGLIGENCE OR OTHERWISE)ARISING IN ANY WAY OUT OF THE USE OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) *******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) ** For history of changes, see Documentation/scsi/ChangeLog.arcmsr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) ** Firmware Specification, see Documentation/scsi/arcmsr_spec.rst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) *******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #include <linux/circ_buf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #include <scsi/scsi_cmnd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #include <scsi/scsi_transport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #include "arcmsr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct device_attribute *arcmsr_host_attrs[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static ssize_t arcmsr_sysfs_iop_message_read(struct file *filp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct bin_attribute *bin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) char *buf, loff_t off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct device *dev = container_of(kobj,struct device,kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct Scsi_Host *host = class_to_shost(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) uint8_t *ptmpQbuffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int32_t allxfer_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /* do message unit read. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) ptmpQbuffer = (uint8_t *)buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) spin_lock_irqsave(&acb->rqbuffer_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (acb->rqbuf_getIndex != acb->rqbuf_putIndex) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) unsigned int tail = acb->rqbuf_getIndex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) unsigned int head = acb->rqbuf_putIndex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) unsigned int cnt_to_end = CIRC_CNT_TO_END(head, tail, ARCMSR_MAX_QBUFFER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) allxfer_len = CIRC_CNT(head, tail, ARCMSR_MAX_QBUFFER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (allxfer_len > ARCMSR_API_DATA_BUFLEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) allxfer_len = ARCMSR_API_DATA_BUFLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (allxfer_len <= cnt_to_end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) memcpy(ptmpQbuffer, acb->rqbuffer + tail, allxfer_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) memcpy(ptmpQbuffer, acb->rqbuffer + tail, cnt_to_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) memcpy(ptmpQbuffer + cnt_to_end, acb->rqbuffer, allxfer_len - cnt_to_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) acb->rqbuf_getIndex = (acb->rqbuf_getIndex + allxfer_len) % ARCMSR_MAX_QBUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct QBUFFER __iomem *prbuffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) prbuffer = arcmsr_get_iop_rqbuffer(acb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if (arcmsr_Read_iop_rqbuffer_data(acb, prbuffer) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) acb->acb_flags |= ACB_F_IOPDATA_OVERFLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) spin_unlock_irqrestore(&acb->rqbuffer_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) return allxfer_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static ssize_t arcmsr_sysfs_iop_message_write(struct file *filp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct bin_attribute *bin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) char *buf, loff_t off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct device *dev = container_of(kobj,struct device,kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct Scsi_Host *host = class_to_shost(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) int32_t user_len, cnt2end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) uint8_t *pQbuffer, *ptmpuserbuffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (count > ARCMSR_API_DATA_BUFLEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* do message unit write. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ptmpuserbuffer = (uint8_t *)buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) user_len = (int32_t)count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) spin_lock_irqsave(&acb->wqbuffer_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (acb->wqbuf_putIndex != acb->wqbuf_getIndex) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) arcmsr_write_ioctldata2iop(acb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) spin_unlock_irqrestore(&acb->wqbuffer_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return 0; /*need retry*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) pQbuffer = &acb->wqbuffer[acb->wqbuf_putIndex];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) cnt2end = ARCMSR_MAX_QBUFFER - acb->wqbuf_putIndex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (user_len > cnt2end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) memcpy(pQbuffer, ptmpuserbuffer, cnt2end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) ptmpuserbuffer += cnt2end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) user_len -= cnt2end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) acb->wqbuf_putIndex = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) pQbuffer = acb->wqbuffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) memcpy(pQbuffer, ptmpuserbuffer, user_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) acb->wqbuf_putIndex += user_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) acb->wqbuf_putIndex %= ARCMSR_MAX_QBUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (acb->acb_flags & ACB_F_MESSAGE_WQBUFFER_CLEARED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) acb->acb_flags &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) ~ACB_F_MESSAGE_WQBUFFER_CLEARED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) arcmsr_write_ioctldata2iop(acb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) spin_unlock_irqrestore(&acb->wqbuffer_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static ssize_t arcmsr_sysfs_iop_message_clear(struct file *filp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) struct bin_attribute *bin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) char *buf, loff_t off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct device *dev = container_of(kobj,struct device,kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct Scsi_Host *host = class_to_shost(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) uint8_t *pQbuffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) arcmsr_clear_iop2drv_rqueue_buffer(acb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) acb->acb_flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) (ACB_F_MESSAGE_WQBUFFER_CLEARED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) | ACB_F_MESSAGE_RQBUFFER_CLEARED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) | ACB_F_MESSAGE_WQBUFFER_READED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) spin_lock_irqsave(&acb->rqbuffer_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) acb->rqbuf_getIndex = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) acb->rqbuf_putIndex = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) spin_unlock_irqrestore(&acb->rqbuffer_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) spin_lock_irqsave(&acb->wqbuffer_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) acb->wqbuf_getIndex = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) acb->wqbuf_putIndex = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) spin_unlock_irqrestore(&acb->wqbuffer_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) pQbuffer = acb->rqbuffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) memset(pQbuffer, 0, sizeof (struct QBUFFER));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) pQbuffer = acb->wqbuffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) memset(pQbuffer, 0, sizeof (struct QBUFFER));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static const struct bin_attribute arcmsr_sysfs_message_read_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) .attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) .name = "mu_read",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) .mode = S_IRUSR ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) .size = ARCMSR_API_DATA_BUFLEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) .read = arcmsr_sysfs_iop_message_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static const struct bin_attribute arcmsr_sysfs_message_write_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) .attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) .name = "mu_write",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) .mode = S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) .size = ARCMSR_API_DATA_BUFLEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) .write = arcmsr_sysfs_iop_message_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static const struct bin_attribute arcmsr_sysfs_message_clear_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) .attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) .name = "mu_clear",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) .mode = S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) .size = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) .write = arcmsr_sysfs_iop_message_clear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) int arcmsr_alloc_sysfs_attr(struct AdapterControlBlock *acb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct Scsi_Host *host = acb->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) error = sysfs_create_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_read_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) printk(KERN_ERR "arcmsr: alloc sysfs mu_read failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) goto error_bin_file_message_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) error = sysfs_create_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_write_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) printk(KERN_ERR "arcmsr: alloc sysfs mu_write failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) goto error_bin_file_message_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) error = sysfs_create_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_clear_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) printk(KERN_ERR "arcmsr: alloc sysfs mu_clear failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) goto error_bin_file_message_clear;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) error_bin_file_message_clear:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) sysfs_remove_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_write_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) error_bin_file_message_write:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) sysfs_remove_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_read_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) error_bin_file_message_read:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) void arcmsr_free_sysfs_attr(struct AdapterControlBlock *acb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct Scsi_Host *host = acb->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) sysfs_remove_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_clear_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) sysfs_remove_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_write_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) sysfs_remove_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_read_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) arcmsr_attr_host_driver_version(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return snprintf(buf, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) "%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) ARCMSR_DRIVER_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) arcmsr_attr_host_driver_posted_cmd(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct Scsi_Host *host = class_to_shost(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct AdapterControlBlock *acb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) (struct AdapterControlBlock *) host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return snprintf(buf, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) "%4d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) atomic_read(&acb->ccboutstandingcount));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) arcmsr_attr_host_driver_reset(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) struct Scsi_Host *host = class_to_shost(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) struct AdapterControlBlock *acb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) (struct AdapterControlBlock *) host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) return snprintf(buf, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) "%4d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) acb->num_resets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) arcmsr_attr_host_driver_abort(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) struct Scsi_Host *host = class_to_shost(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct AdapterControlBlock *acb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) (struct AdapterControlBlock *) host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) return snprintf(buf, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) "%4d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) acb->num_aborts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) arcmsr_attr_host_fw_model(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct Scsi_Host *host = class_to_shost(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) struct AdapterControlBlock *acb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) (struct AdapterControlBlock *) host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) return snprintf(buf, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) "%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) acb->firm_model);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) arcmsr_attr_host_fw_version(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct Scsi_Host *host = class_to_shost(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) struct AdapterControlBlock *acb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) (struct AdapterControlBlock *) host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) return snprintf(buf, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) "%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) acb->firm_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) arcmsr_attr_host_fw_request_len(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) struct Scsi_Host *host = class_to_shost(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) struct AdapterControlBlock *acb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) (struct AdapterControlBlock *) host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return snprintf(buf, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) "%4d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) acb->firm_request_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) arcmsr_attr_host_fw_numbers_queue(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) struct Scsi_Host *host = class_to_shost(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct AdapterControlBlock *acb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) (struct AdapterControlBlock *) host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) return snprintf(buf, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) "%4d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) acb->firm_numbers_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) arcmsr_attr_host_fw_sdram_size(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) struct Scsi_Host *host = class_to_shost(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) struct AdapterControlBlock *acb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) (struct AdapterControlBlock *) host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) return snprintf(buf, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) "%4d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) acb->firm_sdram_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) arcmsr_attr_host_fw_hd_channels(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct Scsi_Host *host = class_to_shost(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) struct AdapterControlBlock *acb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) (struct AdapterControlBlock *) host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) return snprintf(buf, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) "%4d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) acb->firm_hd_channels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) static DEVICE_ATTR(host_driver_version, S_IRUGO, arcmsr_attr_host_driver_version, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) static DEVICE_ATTR(host_driver_posted_cmd, S_IRUGO, arcmsr_attr_host_driver_posted_cmd, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static DEVICE_ATTR(host_driver_reset, S_IRUGO, arcmsr_attr_host_driver_reset, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static DEVICE_ATTR(host_driver_abort, S_IRUGO, arcmsr_attr_host_driver_abort, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) static DEVICE_ATTR(host_fw_model, S_IRUGO, arcmsr_attr_host_fw_model, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static DEVICE_ATTR(host_fw_version, S_IRUGO, arcmsr_attr_host_fw_version, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) static DEVICE_ATTR(host_fw_request_len, S_IRUGO, arcmsr_attr_host_fw_request_len, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) static DEVICE_ATTR(host_fw_numbers_queue, S_IRUGO, arcmsr_attr_host_fw_numbers_queue, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) static DEVICE_ATTR(host_fw_sdram_size, S_IRUGO, arcmsr_attr_host_fw_sdram_size, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) static DEVICE_ATTR(host_fw_hd_channels, S_IRUGO, arcmsr_attr_host_fw_hd_channels, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) struct device_attribute *arcmsr_host_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) &dev_attr_host_driver_version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) &dev_attr_host_driver_posted_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) &dev_attr_host_driver_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) &dev_attr_host_driver_abort,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) &dev_attr_host_fw_model,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) &dev_attr_host_fw_version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) &dev_attr_host_fw_request_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) &dev_attr_host_fw_numbers_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) &dev_attr_host_fw_sdram_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) &dev_attr_host_fw_hd_channels,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) };