Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Parallel SCSI (SPI) transport specific attributes exported to sysfs. |
| 3 | * |
| 4 | * Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved. |
| 5 | * Copyright (c) 2004, 2005 James Bottomley <James.Bottomley@SteelEye.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | */ |
| 21 | #include <linux/ctype.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/workqueue.h> |
James Bottomley | 949bf79 | 2005-05-01 18:58:15 -0500 | [diff] [blame] | 25 | #include <linux/blkdev.h> |
Jes Sorensen | d158d26 | 2006-01-13 16:05:44 -0800 | [diff] [blame] | 26 | #include <linux/mutex.h> |
Randy Dunlap | 9f9a73b | 2008-04-23 09:56:14 -0700 | [diff] [blame] | 27 | #include <linux/sysfs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <scsi/scsi.h> |
| 30 | #include "scsi_priv.h" |
| 31 | #include <scsi/scsi_device.h> |
| 32 | #include <scsi/scsi_host.h> |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 33 | #include <scsi/scsi_cmnd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <scsi/scsi_eh.h> |
Christoph Hellwig | 5066863 | 2014-10-30 14:30:06 +0100 | [diff] [blame] | 35 | #include <scsi/scsi_tcq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <scsi/scsi_transport.h> |
| 37 | #include <scsi/scsi_transport_spi.h> |
| 38 | |
James Bottomley | d872ebe | 2005-08-03 15:43:52 -0500 | [diff] [blame] | 39 | #define SPI_NUM_ATTRS 14 /* increase this if you add attributes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #define SPI_OTHER_ATTRS 1 /* Increase this if you add "always |
| 41 | * on" attributes */ |
| 42 | #define SPI_HOST_ATTRS 1 |
| 43 | |
| 44 | #define SPI_MAX_ECHO_BUFFER_SIZE 4096 |
| 45 | |
James Bottomley | 949bf79 | 2005-05-01 18:58:15 -0500 | [diff] [blame] | 46 | #define DV_LOOPS 3 |
| 47 | #define DV_TIMEOUT (10*HZ) |
| 48 | #define DV_RETRIES 3 /* should only need at most |
| 49 | * two cc/ua clears */ |
| 50 | |
James Bottomley | a9e0edb | 2009-06-17 19:05:05 +0000 | [diff] [blame] | 51 | /* Our blacklist flags */ |
| 52 | enum { |
Bart Van Assche | 093b888 | 2017-12-12 10:23:28 -0800 | [diff] [blame^] | 53 | SPI_BLIST_NOIUS = (__force blist_flags_t)0x1, |
James Bottomley | a9e0edb | 2009-06-17 19:05:05 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | /* blacklist table, modelled on scsi_devinfo.c */ |
| 57 | static struct { |
| 58 | char *vendor; |
| 59 | char *model; |
Bart Van Assche | 093b888 | 2017-12-12 10:23:28 -0800 | [diff] [blame^] | 60 | blist_flags_t flags; |
James Bottomley | a9e0edb | 2009-06-17 19:05:05 +0000 | [diff] [blame] | 61 | } spi_static_device_list[] __initdata = { |
| 62 | {"HP", "Ultrium 3-SCSI", SPI_BLIST_NOIUS }, |
| 63 | {"IBM", "ULTRIUM-TD3", SPI_BLIST_NOIUS }, |
| 64 | {NULL, NULL, 0} |
| 65 | }; |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | /* Private data accessors (keep these out of the header file) */ |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 68 | #define spi_dv_in_progress(x) (((struct spi_transport_attrs *)&(x)->starget_data)->dv_in_progress) |
Jes Sorensen | d158d26 | 2006-01-13 16:05:44 -0800 | [diff] [blame] | 69 | #define spi_dv_mutex(x) (((struct spi_transport_attrs *)&(x)->starget_data)->dv_mutex) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
| 71 | struct spi_internal { |
| 72 | struct scsi_transport_template t; |
| 73 | struct spi_function_template *f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | #define to_spi_internal(tmpl) container_of(tmpl, struct spi_internal, t) |
| 77 | |
| 78 | static const int ppr_to_ps[] = { |
| 79 | /* The PPR values 0-6 are reserved, fill them in when |
| 80 | * the committee defines them */ |
| 81 | -1, /* 0x00 */ |
| 82 | -1, /* 0x01 */ |
| 83 | -1, /* 0x02 */ |
| 84 | -1, /* 0x03 */ |
| 85 | -1, /* 0x04 */ |
| 86 | -1, /* 0x05 */ |
| 87 | -1, /* 0x06 */ |
| 88 | 3125, /* 0x07 */ |
| 89 | 6250, /* 0x08 */ |
| 90 | 12500, /* 0x09 */ |
| 91 | 25000, /* 0x0a */ |
| 92 | 30300, /* 0x0b */ |
| 93 | 50000, /* 0x0c */ |
| 94 | }; |
| 95 | /* The PPR values at which you calculate the period in ns by multiplying |
| 96 | * by 4 */ |
| 97 | #define SPI_STATIC_PPR 0x0c |
| 98 | |
| 99 | static int sprint_frac(char *dest, int value, int denom) |
| 100 | { |
| 101 | int frac = value % denom; |
| 102 | int result = sprintf(dest, "%d", value / denom); |
| 103 | |
| 104 | if (frac == 0) |
| 105 | return result; |
| 106 | dest[result++] = '.'; |
| 107 | |
| 108 | do { |
| 109 | denom /= 10; |
| 110 | sprintf(dest + result, "%d", frac / denom); |
| 111 | result++; |
| 112 | frac %= denom; |
| 113 | } while (frac); |
| 114 | |
| 115 | dest[result++] = '\0'; |
| 116 | return result; |
| 117 | } |
| 118 | |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 119 | static int spi_execute(struct scsi_device *sdev, const void *cmd, |
| 120 | enum dma_data_direction dir, |
| 121 | void *buffer, unsigned bufflen, |
| 122 | struct scsi_sense_hdr *sshdr) |
James Bottomley | 949bf79 | 2005-05-01 18:58:15 -0500 | [diff] [blame] | 123 | { |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 124 | int i, result; |
| 125 | unsigned char sense[SCSI_SENSE_BUFFERSIZE]; |
Christoph Hellwig | 76aaf87 | 2017-02-23 16:02:36 +0100 | [diff] [blame] | 126 | struct scsi_sense_hdr sshdr_tmp; |
| 127 | |
| 128 | if (!sshdr) |
| 129 | sshdr = &sshdr_tmp; |
James Bottomley | 949bf79 | 2005-05-01 18:58:15 -0500 | [diff] [blame] | 130 | |
| 131 | for(i = 0; i < DV_RETRIES; i++) { |
Christoph Hellwig | 76aaf87 | 2017-02-23 16:02:36 +0100 | [diff] [blame] | 132 | result = scsi_execute(sdev, cmd, dir, buffer, bufflen, sense, |
| 133 | sshdr, DV_TIMEOUT, /* retries */ 1, |
Mike Christie | 6000a36 | 2008-08-19 18:45:30 -0500 | [diff] [blame] | 134 | REQ_FAILFAST_DEV | |
| 135 | REQ_FAILFAST_TRANSPORT | |
FUJITA Tomonori | f4f4e47 | 2008-12-04 14:24:39 +0900 | [diff] [blame] | 136 | REQ_FAILFAST_DRIVER, |
Christoph Hellwig | 76aaf87 | 2017-02-23 16:02:36 +0100 | [diff] [blame] | 137 | 0, NULL); |
| 138 | if (!(driver_byte(result) & DRIVER_SENSE) || |
| 139 | sshdr->sense_key != UNIT_ATTENTION) |
| 140 | break; |
James Bottomley | 949bf79 | 2005-05-01 18:58:15 -0500 | [diff] [blame] | 141 | } |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 142 | return result; |
James Bottomley | 949bf79 | 2005-05-01 18:58:15 -0500 | [diff] [blame] | 143 | } |
| 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | static struct { |
| 146 | enum spi_signal_type value; |
| 147 | char *name; |
| 148 | } signal_types[] = { |
| 149 | { SPI_SIGNAL_UNKNOWN, "unknown" }, |
| 150 | { SPI_SIGNAL_SE, "SE" }, |
| 151 | { SPI_SIGNAL_LVD, "LVD" }, |
| 152 | { SPI_SIGNAL_HVD, "HVD" }, |
| 153 | }; |
| 154 | |
| 155 | static inline const char *spi_signal_to_string(enum spi_signal_type type) |
| 156 | { |
| 157 | int i; |
| 158 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 159 | for (i = 0; i < ARRAY_SIZE(signal_types); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | if (type == signal_types[i].value) |
| 161 | return signal_types[i].name; |
| 162 | } |
| 163 | return NULL; |
| 164 | } |
| 165 | static inline enum spi_signal_type spi_signal_to_value(const char *name) |
| 166 | { |
| 167 | int i, len; |
| 168 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 169 | for (i = 0; i < ARRAY_SIZE(signal_types); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | len = strlen(signal_types[i].name); |
| 171 | if (strncmp(name, signal_types[i].name, len) == 0 && |
| 172 | (name[len] == '\n' || name[len] == '\0')) |
| 173 | return signal_types[i].value; |
| 174 | } |
| 175 | return SPI_SIGNAL_UNKNOWN; |
| 176 | } |
| 177 | |
James Bottomley | d0a7e57 | 2005-08-14 17:09:01 -0500 | [diff] [blame] | 178 | static int spi_host_setup(struct transport_container *tc, struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 179 | struct device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | { |
| 181 | struct Scsi_Host *shost = dev_to_shost(dev); |
| 182 | |
| 183 | spi_signalling(shost) = SPI_SIGNAL_UNKNOWN; |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 188 | static int spi_host_configure(struct transport_container *tc, |
| 189 | struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 190 | struct device *cdev); |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | static DECLARE_TRANSPORT_CLASS(spi_host_class, |
| 193 | "spi_host", |
| 194 | spi_host_setup, |
| 195 | NULL, |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 196 | spi_host_configure); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | static int spi_host_match(struct attribute_container *cont, |
| 199 | struct device *dev) |
| 200 | { |
| 201 | struct Scsi_Host *shost; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | if (!scsi_is_host_device(dev)) |
| 204 | return 0; |
| 205 | |
| 206 | shost = dev_to_shost(dev); |
| 207 | if (!shost->transportt || shost->transportt->host_attrs.ac.class |
| 208 | != &spi_host_class.class) |
| 209 | return 0; |
| 210 | |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 211 | return &shost->transportt->host_attrs.ac == cont; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 214 | static int spi_target_configure(struct transport_container *tc, |
| 215 | struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 216 | struct device *cdev); |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 217 | |
James Bottomley | d0a7e57 | 2005-08-14 17:09:01 -0500 | [diff] [blame] | 218 | static int spi_device_configure(struct transport_container *tc, |
| 219 | struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 220 | struct device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | { |
| 222 | struct scsi_device *sdev = to_scsi_device(dev); |
| 223 | struct scsi_target *starget = sdev->sdev_target; |
Bart Van Assche | 093b888 | 2017-12-12 10:23:28 -0800 | [diff] [blame^] | 224 | blist_flags_t bflags; |
| 225 | |
| 226 | bflags = scsi_get_device_flags_keyed(sdev, &sdev->inquiry[8], |
| 227 | &sdev->inquiry[16], |
| 228 | SCSI_DEVINFO_SPI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
| 230 | /* Populate the target capability fields with the values |
| 231 | * gleaned from the device inquiry */ |
| 232 | |
| 233 | spi_support_sync(starget) = scsi_device_sync(sdev); |
| 234 | spi_support_wide(starget) = scsi_device_wide(sdev); |
| 235 | spi_support_dt(starget) = scsi_device_dt(sdev); |
| 236 | spi_support_dt_only(starget) = scsi_device_dt_only(sdev); |
| 237 | spi_support_ius(starget) = scsi_device_ius(sdev); |
James Bottomley | a9e0edb | 2009-06-17 19:05:05 +0000 | [diff] [blame] | 238 | if (bflags & SPI_BLIST_NOIUS) { |
| 239 | dev_info(dev, "Information Units disabled by blacklist\n"); |
| 240 | spi_support_ius(starget) = 0; |
| 241 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | spi_support_qas(starget) = scsi_device_qas(sdev); |
| 243 | |
| 244 | return 0; |
| 245 | } |
| 246 | |
James Bottomley | d0a7e57 | 2005-08-14 17:09:01 -0500 | [diff] [blame] | 247 | static int spi_setup_transport_attrs(struct transport_container *tc, |
| 248 | struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 249 | struct device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | { |
| 251 | struct scsi_target *starget = to_scsi_target(dev); |
| 252 | |
| 253 | spi_period(starget) = -1; /* illegal value */ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 254 | spi_min_period(starget) = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | spi_offset(starget) = 0; /* async */ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 256 | spi_max_offset(starget) = 255; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | spi_width(starget) = 0; /* narrow */ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 258 | spi_max_width(starget) = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | spi_iu(starget) = 0; /* no IU */ |
James Bottomley | ea44319 | 2009-06-13 12:19:05 -0500 | [diff] [blame] | 260 | spi_max_iu(starget) = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | spi_dt(starget) = 0; /* ST */ |
| 262 | spi_qas(starget) = 0; |
James Bottomley | ea44319 | 2009-06-13 12:19:05 -0500 | [diff] [blame] | 263 | spi_max_qas(starget) = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | spi_wr_flow(starget) = 0; |
| 265 | spi_rd_strm(starget) = 0; |
| 266 | spi_rti(starget) = 0; |
| 267 | spi_pcomp_en(starget) = 0; |
James Bottomley | d872ebe | 2005-08-03 15:43:52 -0500 | [diff] [blame] | 268 | spi_hold_mcs(starget) = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | spi_dv_pending(starget) = 0; |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 270 | spi_dv_in_progress(starget) = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | spi_initial_dv(starget) = 0; |
Jes Sorensen | d158d26 | 2006-01-13 16:05:44 -0800 | [diff] [blame] | 272 | mutex_init(&spi_dv_mutex(starget)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
| 274 | return 0; |
| 275 | } |
| 276 | |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 277 | #define spi_transport_show_simple(field, format_string) \ |
| 278 | \ |
| 279 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 280 | show_spi_transport_##field(struct device *dev, \ |
| 281 | struct device_attribute *attr, char *buf) \ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 282 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 283 | struct scsi_target *starget = transport_class_to_starget(dev); \ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 284 | struct spi_transport_attrs *tp; \ |
| 285 | \ |
| 286 | tp = (struct spi_transport_attrs *)&starget->starget_data; \ |
| 287 | return snprintf(buf, 20, format_string, tp->field); \ |
| 288 | } |
| 289 | |
| 290 | #define spi_transport_store_simple(field, format_string) \ |
| 291 | \ |
| 292 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 293 | store_spi_transport_##field(struct device *dev, \ |
| 294 | struct device_attribute *attr, \ |
| 295 | const char *buf, size_t count) \ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 296 | { \ |
| 297 | int val; \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 298 | struct scsi_target *starget = transport_class_to_starget(dev); \ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 299 | struct spi_transport_attrs *tp; \ |
| 300 | \ |
| 301 | tp = (struct spi_transport_attrs *)&starget->starget_data; \ |
| 302 | val = simple_strtoul(buf, NULL, 0); \ |
| 303 | tp->field = val; \ |
| 304 | return count; \ |
| 305 | } |
| 306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | #define spi_transport_show_function(field, format_string) \ |
| 308 | \ |
| 309 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 310 | show_spi_transport_##field(struct device *dev, \ |
| 311 | struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 313 | struct scsi_target *starget = transport_class_to_starget(dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \ |
| 315 | struct spi_transport_attrs *tp; \ |
| 316 | struct spi_internal *i = to_spi_internal(shost->transportt); \ |
| 317 | tp = (struct spi_transport_attrs *)&starget->starget_data; \ |
| 318 | if (i->f->get_##field) \ |
| 319 | i->f->get_##field(starget); \ |
| 320 | return snprintf(buf, 20, format_string, tp->field); \ |
| 321 | } |
| 322 | |
| 323 | #define spi_transport_store_function(field, format_string) \ |
| 324 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 325 | store_spi_transport_##field(struct device *dev, \ |
| 326 | struct device_attribute *attr, \ |
| 327 | const char *buf, size_t count) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | { \ |
| 329 | int val; \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 330 | struct scsi_target *starget = transport_class_to_starget(dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \ |
| 332 | struct spi_internal *i = to_spi_internal(shost->transportt); \ |
| 333 | \ |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 334 | if (!i->f->set_##field) \ |
| 335 | return -EINVAL; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | val = simple_strtoul(buf, NULL, 0); \ |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 337 | i->f->set_##field(starget, val); \ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 338 | return count; \ |
| 339 | } |
| 340 | |
| 341 | #define spi_transport_store_max(field, format_string) \ |
| 342 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 343 | store_spi_transport_##field(struct device *dev, \ |
| 344 | struct device_attribute *attr, \ |
| 345 | const char *buf, size_t count) \ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 346 | { \ |
| 347 | int val; \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 348 | struct scsi_target *starget = transport_class_to_starget(dev); \ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 349 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \ |
| 350 | struct spi_internal *i = to_spi_internal(shost->transportt); \ |
| 351 | struct spi_transport_attrs *tp \ |
| 352 | = (struct spi_transport_attrs *)&starget->starget_data; \ |
| 353 | \ |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 354 | if (i->f->set_##field) \ |
| 355 | return -EINVAL; \ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 356 | val = simple_strtoul(buf, NULL, 0); \ |
| 357 | if (val > tp->max_##field) \ |
| 358 | val = tp->max_##field; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | i->f->set_##field(starget, val); \ |
| 360 | return count; \ |
| 361 | } |
| 362 | |
| 363 | #define spi_transport_rd_attr(field, format_string) \ |
| 364 | spi_transport_show_function(field, format_string) \ |
| 365 | spi_transport_store_function(field, format_string) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 366 | static DEVICE_ATTR(field, S_IRUGO, \ |
| 367 | show_spi_transport_##field, \ |
| 368 | store_spi_transport_##field); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 370 | #define spi_transport_simple_attr(field, format_string) \ |
| 371 | spi_transport_show_simple(field, format_string) \ |
| 372 | spi_transport_store_simple(field, format_string) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 373 | static DEVICE_ATTR(field, S_IRUGO, \ |
| 374 | show_spi_transport_##field, \ |
| 375 | store_spi_transport_##field); |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 376 | |
| 377 | #define spi_transport_max_attr(field, format_string) \ |
| 378 | spi_transport_show_function(field, format_string) \ |
| 379 | spi_transport_store_max(field, format_string) \ |
| 380 | spi_transport_simple_attr(max_##field, format_string) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 381 | static DEVICE_ATTR(field, S_IRUGO, \ |
| 382 | show_spi_transport_##field, \ |
| 383 | store_spi_transport_##field); |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | /* The Parallel SCSI Tranport Attributes: */ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 386 | spi_transport_max_attr(offset, "%d\n"); |
| 387 | spi_transport_max_attr(width, "%d\n"); |
James Bottomley | ea44319 | 2009-06-13 12:19:05 -0500 | [diff] [blame] | 388 | spi_transport_max_attr(iu, "%d\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | spi_transport_rd_attr(dt, "%d\n"); |
James Bottomley | ea44319 | 2009-06-13 12:19:05 -0500 | [diff] [blame] | 390 | spi_transport_max_attr(qas, "%d\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | spi_transport_rd_attr(wr_flow, "%d\n"); |
| 392 | spi_transport_rd_attr(rd_strm, "%d\n"); |
| 393 | spi_transport_rd_attr(rti, "%d\n"); |
| 394 | spi_transport_rd_attr(pcomp_en, "%d\n"); |
James Bottomley | d872ebe | 2005-08-03 15:43:52 -0500 | [diff] [blame] | 395 | spi_transport_rd_attr(hold_mcs, "%d\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
James Bottomley | e8bac9e | 2008-07-29 12:52:20 -0500 | [diff] [blame] | 397 | /* we only care about the first child device that's a real SCSI device |
| 398 | * so we return 1 to terminate the iteration when we find it */ |
gregkh@suse.de | 9a881f1 | 2005-03-25 15:52:00 -0800 | [diff] [blame] | 399 | static int child_iter(struct device *dev, void *data) |
| 400 | { |
James Bottomley | e8bac9e | 2008-07-29 12:52:20 -0500 | [diff] [blame] | 401 | if (!scsi_is_sdev_device(dev)) |
| 402 | return 0; |
gregkh@suse.de | 9a881f1 | 2005-03-25 15:52:00 -0800 | [diff] [blame] | 403 | |
James Bottomley | e8bac9e | 2008-07-29 12:52:20 -0500 | [diff] [blame] | 404 | spi_dv_device(to_scsi_device(dev)); |
gregkh@suse.de | 9a881f1 | 2005-03-25 15:52:00 -0800 | [diff] [blame] | 405 | return 1; |
| 406 | } |
| 407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 409 | store_spi_revalidate(struct device *dev, struct device_attribute *attr, |
| 410 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 412 | struct scsi_target *starget = transport_class_to_starget(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
gregkh@suse.de | 9a881f1 | 2005-03-25 15:52:00 -0800 | [diff] [blame] | 414 | device_for_each_child(&starget->dev, NULL, child_iter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | return count; |
| 416 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 417 | static DEVICE_ATTR(revalidate, S_IWUSR, NULL, store_spi_revalidate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
| 419 | /* Translate the period into ns according to the current spec |
| 420 | * for SDTR/PPR messages */ |
Matthew Wilcox | ef72582 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 421 | static int period_to_str(char *buf, int period) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | int len, picosec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 425 | if (period < 0 || period > 0xff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | picosec = -1; |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 427 | } else if (period <= SPI_STATIC_PPR) { |
| 428 | picosec = ppr_to_ps[period]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | } else { |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 430 | picosec = period * 4000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | if (picosec == -1) { |
| 434 | len = sprintf(buf, "reserved"); |
| 435 | } else { |
| 436 | len = sprint_frac(buf, picosec, 1000); |
| 437 | } |
| 438 | |
Matthew Wilcox | ef72582 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 439 | return len; |
| 440 | } |
| 441 | |
| 442 | static ssize_t |
Matthew Wilcox | ea697e4 | 2006-02-07 08:01:02 -0700 | [diff] [blame] | 443 | show_spi_transport_period_helper(char *buf, int period) |
Matthew Wilcox | ef72582 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 444 | { |
| 445 | int len = period_to_str(buf, period); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | buf[len++] = '\n'; |
| 447 | buf[len] = '\0'; |
| 448 | return len; |
| 449 | } |
| 450 | |
| 451 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 452 | store_spi_transport_period_helper(struct device *dev, const char *buf, |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 453 | size_t count, int *periodp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | int j, picosec, period = -1; |
| 456 | char *endp; |
| 457 | |
| 458 | picosec = simple_strtoul(buf, &endp, 10) * 1000; |
| 459 | if (*endp == '.') { |
| 460 | int mult = 100; |
| 461 | do { |
| 462 | endp++; |
| 463 | if (!isdigit(*endp)) |
| 464 | break; |
| 465 | picosec += (*endp - '0') * mult; |
| 466 | mult /= 10; |
| 467 | } while (mult > 0); |
| 468 | } |
| 469 | |
| 470 | for (j = 0; j <= SPI_STATIC_PPR; j++) { |
| 471 | if (ppr_to_ps[j] < picosec) |
| 472 | continue; |
| 473 | period = j; |
| 474 | break; |
| 475 | } |
| 476 | |
| 477 | if (period == -1) |
| 478 | period = picosec / 4000; |
| 479 | |
| 480 | if (period > 0xff) |
| 481 | period = 0xff; |
| 482 | |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 483 | *periodp = period; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
| 485 | return count; |
| 486 | } |
| 487 | |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 488 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 489 | show_spi_transport_period(struct device *dev, |
| 490 | struct device_attribute *attr, char *buf) |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 491 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 492 | struct scsi_target *starget = transport_class_to_starget(dev); |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 493 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
| 494 | struct spi_internal *i = to_spi_internal(shost->transportt); |
| 495 | struct spi_transport_attrs *tp = |
| 496 | (struct spi_transport_attrs *)&starget->starget_data; |
| 497 | |
| 498 | if (i->f->get_period) |
| 499 | i->f->get_period(starget); |
| 500 | |
Matthew Wilcox | ea697e4 | 2006-02-07 08:01:02 -0700 | [diff] [blame] | 501 | return show_spi_transport_period_helper(buf, tp->period); |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 505 | store_spi_transport_period(struct device *cdev, struct device_attribute *attr, |
| 506 | const char *buf, size_t count) |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 507 | { |
| 508 | struct scsi_target *starget = transport_class_to_starget(cdev); |
| 509 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
| 510 | struct spi_internal *i = to_spi_internal(shost->transportt); |
| 511 | struct spi_transport_attrs *tp = |
| 512 | (struct spi_transport_attrs *)&starget->starget_data; |
| 513 | int period, retval; |
| 514 | |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 515 | if (!i->f->set_period) |
| 516 | return -EINVAL; |
| 517 | |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 518 | retval = store_spi_transport_period_helper(cdev, buf, count, &period); |
| 519 | |
| 520 | if (period < tp->min_period) |
| 521 | period = tp->min_period; |
| 522 | |
| 523 | i->f->set_period(starget, period); |
| 524 | |
| 525 | return retval; |
| 526 | } |
| 527 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 528 | static DEVICE_ATTR(period, S_IRUGO, |
| 529 | show_spi_transport_period, |
| 530 | store_spi_transport_period); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 532 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 533 | show_spi_transport_min_period(struct device *cdev, |
| 534 | struct device_attribute *attr, char *buf) |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 535 | { |
| 536 | struct scsi_target *starget = transport_class_to_starget(cdev); |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 537 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
| 538 | struct spi_internal *i = to_spi_internal(shost->transportt); |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 539 | struct spi_transport_attrs *tp = |
| 540 | (struct spi_transport_attrs *)&starget->starget_data; |
| 541 | |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 542 | if (!i->f->set_period) |
| 543 | return -EINVAL; |
| 544 | |
Matthew Wilcox | ea697e4 | 2006-02-07 08:01:02 -0700 | [diff] [blame] | 545 | return show_spi_transport_period_helper(buf, tp->min_period); |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 549 | store_spi_transport_min_period(struct device *cdev, |
| 550 | struct device_attribute *attr, |
| 551 | const char *buf, size_t count) |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 552 | { |
| 553 | struct scsi_target *starget = transport_class_to_starget(cdev); |
| 554 | struct spi_transport_attrs *tp = |
| 555 | (struct spi_transport_attrs *)&starget->starget_data; |
| 556 | |
| 557 | return store_spi_transport_period_helper(cdev, buf, count, |
| 558 | &tp->min_period); |
| 559 | } |
| 560 | |
| 561 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 562 | static DEVICE_ATTR(min_period, S_IRUGO, |
| 563 | show_spi_transport_min_period, |
| 564 | store_spi_transport_min_period); |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 565 | |
| 566 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 567 | static ssize_t show_spi_host_signalling(struct device *cdev, |
| 568 | struct device_attribute *attr, |
| 569 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | { |
| 571 | struct Scsi_Host *shost = transport_class_to_shost(cdev); |
| 572 | struct spi_internal *i = to_spi_internal(shost->transportt); |
| 573 | |
| 574 | if (i->f->get_signalling) |
| 575 | i->f->get_signalling(shost); |
| 576 | |
| 577 | return sprintf(buf, "%s\n", spi_signal_to_string(spi_signalling(shost))); |
| 578 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 579 | static ssize_t store_spi_host_signalling(struct device *dev, |
| 580 | struct device_attribute *attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | const char *buf, size_t count) |
| 582 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 583 | struct Scsi_Host *shost = transport_class_to_shost(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | struct spi_internal *i = to_spi_internal(shost->transportt); |
| 585 | enum spi_signal_type type = spi_signal_to_value(buf); |
| 586 | |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 587 | if (!i->f->set_signalling) |
| 588 | return -EINVAL; |
| 589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | if (type != SPI_SIGNAL_UNKNOWN) |
| 591 | i->f->set_signalling(shost, type); |
| 592 | |
| 593 | return count; |
| 594 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 595 | static DEVICE_ATTR(signalling, S_IRUGO, |
| 596 | show_spi_host_signalling, |
| 597 | store_spi_host_signalling); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | |
Hannes Reinecke | 0ac2377 | 2011-06-30 02:19:57 +0530 | [diff] [blame] | 599 | static ssize_t show_spi_host_width(struct device *cdev, |
| 600 | struct device_attribute *attr, |
| 601 | char *buf) |
| 602 | { |
| 603 | struct Scsi_Host *shost = transport_class_to_shost(cdev); |
| 604 | |
| 605 | return sprintf(buf, "%s\n", shost->max_id == 16 ? "wide" : "narrow"); |
| 606 | } |
| 607 | static DEVICE_ATTR(host_width, S_IRUGO, |
| 608 | show_spi_host_width, NULL); |
| 609 | |
| 610 | static ssize_t show_spi_host_hba_id(struct device *cdev, |
| 611 | struct device_attribute *attr, |
| 612 | char *buf) |
| 613 | { |
| 614 | struct Scsi_Host *shost = transport_class_to_shost(cdev); |
| 615 | |
| 616 | return sprintf(buf, "%d\n", shost->this_id); |
| 617 | } |
| 618 | static DEVICE_ATTR(hba_id, S_IRUGO, |
| 619 | show_spi_host_hba_id, NULL); |
| 620 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | #define DV_SET(x, y) \ |
| 622 | if(i->f->set_##x) \ |
| 623 | i->f->set_##x(sdev->sdev_target, y) |
| 624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | enum spi_compare_returns { |
| 626 | SPI_COMPARE_SUCCESS, |
| 627 | SPI_COMPARE_FAILURE, |
| 628 | SPI_COMPARE_SKIP_TEST, |
| 629 | }; |
| 630 | |
| 631 | |
| 632 | /* This is for read/write Domain Validation: If the device supports |
| 633 | * an echo buffer, we do read/write tests to it */ |
| 634 | static enum spi_compare_returns |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 635 | spi_dv_device_echo_buffer(struct scsi_device *sdev, u8 *buffer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | u8 *ptr, const int retries) |
| 637 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | int len = ptr - buffer; |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 639 | int j, k, r, result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | unsigned int pattern = 0x0000ffff; |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 641 | struct scsi_sense_hdr sshdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
| 643 | const char spi_write_buffer[] = { |
| 644 | WRITE_BUFFER, 0x0a, 0, 0, 0, 0, 0, len >> 8, len & 0xff, 0 |
| 645 | }; |
| 646 | const char spi_read_buffer[] = { |
| 647 | READ_BUFFER, 0x0a, 0, 0, 0, 0, 0, len >> 8, len & 0xff, 0 |
| 648 | }; |
| 649 | |
| 650 | /* set up the pattern buffer. Doesn't matter if we spill |
| 651 | * slightly beyond since that's where the read buffer is */ |
| 652 | for (j = 0; j < len; ) { |
| 653 | |
| 654 | /* fill the buffer with counting (test a) */ |
| 655 | for ( ; j < min(len, 32); j++) |
| 656 | buffer[j] = j; |
| 657 | k = j; |
| 658 | /* fill the buffer with alternating words of 0x0 and |
| 659 | * 0xffff (test b) */ |
| 660 | for ( ; j < min(len, k + 32); j += 2) { |
| 661 | u16 *word = (u16 *)&buffer[j]; |
| 662 | |
| 663 | *word = (j & 0x02) ? 0x0000 : 0xffff; |
| 664 | } |
| 665 | k = j; |
| 666 | /* fill with crosstalk (alternating 0x5555 0xaaa) |
| 667 | * (test c) */ |
| 668 | for ( ; j < min(len, k + 32); j += 2) { |
| 669 | u16 *word = (u16 *)&buffer[j]; |
| 670 | |
| 671 | *word = (j & 0x02) ? 0x5555 : 0xaaaa; |
| 672 | } |
| 673 | k = j; |
| 674 | /* fill with shifting bits (test d) */ |
| 675 | for ( ; j < min(len, k + 32); j += 4) { |
| 676 | u32 *word = (unsigned int *)&buffer[j]; |
| 677 | u32 roll = (pattern & 0x80000000) ? 1 : 0; |
| 678 | |
| 679 | *word = pattern; |
| 680 | pattern = (pattern << 1) | roll; |
| 681 | } |
| 682 | /* don't bother with random data (test e) */ |
| 683 | } |
| 684 | |
| 685 | for (r = 0; r < retries; r++) { |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 686 | result = spi_execute(sdev, spi_write_buffer, DMA_TO_DEVICE, |
| 687 | buffer, len, &sshdr); |
| 688 | if(result || !scsi_device_online(sdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
| 690 | scsi_device_set_state(sdev, SDEV_QUIESCE); |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 691 | if (scsi_sense_valid(&sshdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | && sshdr.sense_key == ILLEGAL_REQUEST |
| 693 | /* INVALID FIELD IN CDB */ |
| 694 | && sshdr.asc == 0x24 && sshdr.ascq == 0x00) |
| 695 | /* This would mean that the drive lied |
| 696 | * to us about supporting an echo |
| 697 | * buffer (unfortunately some Western |
| 698 | * Digital drives do precisely this) |
| 699 | */ |
| 700 | return SPI_COMPARE_SKIP_TEST; |
| 701 | |
| 702 | |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 703 | sdev_printk(KERN_ERR, sdev, "Write Buffer failure %x\n", result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | return SPI_COMPARE_FAILURE; |
| 705 | } |
| 706 | |
| 707 | memset(ptr, 0, len); |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 708 | spi_execute(sdev, spi_read_buffer, DMA_FROM_DEVICE, |
| 709 | ptr, len, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | scsi_device_set_state(sdev, SDEV_QUIESCE); |
| 711 | |
| 712 | if (memcmp(buffer, ptr, len) != 0) |
| 713 | return SPI_COMPARE_FAILURE; |
| 714 | } |
| 715 | return SPI_COMPARE_SUCCESS; |
| 716 | } |
| 717 | |
| 718 | /* This is for the simplest form of Domain Validation: a read test |
| 719 | * on the inquiry data from the device */ |
| 720 | static enum spi_compare_returns |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 721 | spi_dv_device_compare_inquiry(struct scsi_device *sdev, u8 *buffer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | u8 *ptr, const int retries) |
| 723 | { |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 724 | int r, result; |
| 725 | const int len = sdev->inquiry_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | const char spi_inquiry[] = { |
| 727 | INQUIRY, 0, 0, 0, len, 0 |
| 728 | }; |
| 729 | |
| 730 | for (r = 0; r < retries; r++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | memset(ptr, 0, len); |
| 732 | |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 733 | result = spi_execute(sdev, spi_inquiry, DMA_FROM_DEVICE, |
| 734 | ptr, len, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 736 | if(result || !scsi_device_online(sdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | scsi_device_set_state(sdev, SDEV_QUIESCE); |
| 738 | return SPI_COMPARE_FAILURE; |
| 739 | } |
| 740 | |
| 741 | /* If we don't have the inquiry data already, the |
| 742 | * first read gets it */ |
| 743 | if (ptr == buffer) { |
| 744 | ptr += len; |
| 745 | --r; |
| 746 | continue; |
| 747 | } |
| 748 | |
| 749 | if (memcmp(buffer, ptr, len) != 0) |
| 750 | /* failure */ |
| 751 | return SPI_COMPARE_FAILURE; |
| 752 | } |
| 753 | return SPI_COMPARE_SUCCESS; |
| 754 | } |
| 755 | |
| 756 | static enum spi_compare_returns |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 757 | spi_dv_retrain(struct scsi_device *sdev, u8 *buffer, u8 *ptr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | enum spi_compare_returns |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 759 | (*compare_fn)(struct scsi_device *, u8 *, u8 *, int)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | { |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 761 | struct spi_internal *i = to_spi_internal(sdev->host->transportt); |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 762 | struct scsi_target *starget = sdev->sdev_target; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | int period = 0, prevperiod = 0; |
| 764 | enum spi_compare_returns retval; |
| 765 | |
| 766 | |
| 767 | for (;;) { |
| 768 | int newperiod; |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 769 | retval = compare_fn(sdev, buffer, ptr, DV_LOOPS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
| 771 | if (retval == SPI_COMPARE_SUCCESS |
| 772 | || retval == SPI_COMPARE_SKIP_TEST) |
| 773 | break; |
| 774 | |
| 775 | /* OK, retrain, fallback */ |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 776 | if (i->f->get_iu) |
| 777 | i->f->get_iu(starget); |
| 778 | if (i->f->get_qas) |
| 779 | i->f->get_qas(starget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | if (i->f->get_period) |
| 781 | i->f->get_period(sdev->sdev_target); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 783 | /* Here's the fallback sequence; first try turning off |
| 784 | * IU, then QAS (if we can control them), then finally |
| 785 | * fall down the periods */ |
| 786 | if (i->f->set_iu && spi_iu(starget)) { |
Masanari Iida | 804ff60 | 2015-05-07 23:21:27 +0900 | [diff] [blame] | 787 | starget_printk(KERN_ERR, starget, "Domain Validation Disabling Information Units\n"); |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 788 | DV_SET(iu, 0); |
| 789 | } else if (i->f->set_qas && spi_qas(starget)) { |
Masanari Iida | 804ff60 | 2015-05-07 23:21:27 +0900 | [diff] [blame] | 790 | starget_printk(KERN_ERR, starget, "Domain Validation Disabling Quick Arbitration and Selection\n"); |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 791 | DV_SET(qas, 0); |
| 792 | } else { |
| 793 | newperiod = spi_period(starget); |
| 794 | period = newperiod > period ? newperiod : period; |
| 795 | if (period < 0x0d) |
| 796 | period++; |
| 797 | else |
| 798 | period += period >> 1; |
| 799 | |
| 800 | if (unlikely(period > 0xff || period == prevperiod)) { |
| 801 | /* Total failure; set to async and return */ |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 802 | starget_printk(KERN_ERR, starget, "Domain Validation Failure, dropping back to Asynchronous\n"); |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 803 | DV_SET(offset, 0); |
| 804 | return SPI_COMPARE_FAILURE; |
| 805 | } |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 806 | starget_printk(KERN_ERR, starget, "Domain Validation detected failure, dropping back\n"); |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 807 | DV_SET(period, period); |
| 808 | prevperiod = period; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | } |
| 811 | return retval; |
| 812 | } |
| 813 | |
| 814 | static int |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 815 | spi_dv_device_get_echo_buffer(struct scsi_device *sdev, u8 *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | { |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 817 | int l, result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | |
| 819 | /* first off do a test unit ready. This can error out |
| 820 | * because of reservations or some other reason. If it |
| 821 | * fails, the device won't let us write to the echo buffer |
| 822 | * so just return failure */ |
| 823 | |
| 824 | const char spi_test_unit_ready[] = { |
| 825 | TEST_UNIT_READY, 0, 0, 0, 0, 0 |
| 826 | }; |
| 827 | |
| 828 | const char spi_read_buffer_descriptor[] = { |
| 829 | READ_BUFFER, 0x0b, 0, 0, 0, 0, 0, 0, 4, 0 |
| 830 | }; |
| 831 | |
| 832 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | /* We send a set of three TURs to clear any outstanding |
| 834 | * unit attention conditions if they exist (Otherwise the |
| 835 | * buffer tests won't be happy). If the TUR still fails |
| 836 | * (reservation conflict, device not ready, etc) just |
| 837 | * skip the write tests */ |
| 838 | for (l = 0; ; l++) { |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 839 | result = spi_execute(sdev, spi_test_unit_ready, DMA_NONE, |
| 840 | NULL, 0, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 842 | if(result) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | if(l >= 3) |
| 844 | return 0; |
| 845 | } else { |
| 846 | /* TUR succeeded */ |
| 847 | break; |
| 848 | } |
| 849 | } |
| 850 | |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 851 | result = spi_execute(sdev, spi_read_buffer_descriptor, |
| 852 | DMA_FROM_DEVICE, buffer, 4, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 854 | if (result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | /* Device has no echo buffer */ |
| 856 | return 0; |
| 857 | |
| 858 | return buffer[3] + ((buffer[2] & 0x1f) << 8); |
| 859 | } |
| 860 | |
| 861 | static void |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 862 | spi_dv_device_internal(struct scsi_device *sdev, u8 *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | { |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 864 | struct spi_internal *i = to_spi_internal(sdev->host->transportt); |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 865 | struct scsi_target *starget = sdev->sdev_target; |
James Bottomley | 60eef25 | 2006-06-10 10:51:23 -0500 | [diff] [blame] | 866 | struct Scsi_Host *shost = sdev->host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | int len = sdev->inquiry_len; |
James Bottomley | 2302827 | 2007-09-22 08:40:09 -0500 | [diff] [blame] | 868 | int min_period = spi_min_period(starget); |
| 869 | int max_width = spi_max_width(starget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | /* first set us up for narrow async */ |
| 871 | DV_SET(offset, 0); |
| 872 | DV_SET(width, 0); |
James Bottomley | 2302827 | 2007-09-22 08:40:09 -0500 | [diff] [blame] | 873 | |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 874 | if (spi_dv_device_compare_inquiry(sdev, buffer, buffer, DV_LOOPS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | != SPI_COMPARE_SUCCESS) { |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 876 | starget_printk(KERN_ERR, starget, "Domain Validation Initial Inquiry Failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | /* FIXME: should probably offline the device here? */ |
| 878 | return; |
| 879 | } |
| 880 | |
James Bottomley | 9872b81 | 2009-06-17 15:03:41 -0400 | [diff] [blame] | 881 | if (!spi_support_wide(starget)) { |
James Bottomley | 2302827 | 2007-09-22 08:40:09 -0500 | [diff] [blame] | 882 | spi_max_width(starget) = 0; |
| 883 | max_width = 0; |
| 884 | } |
| 885 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | /* test width */ |
James Bottomley | 2302827 | 2007-09-22 08:40:09 -0500 | [diff] [blame] | 887 | if (i->f->set_width && max_width) { |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 888 | i->f->set_width(starget, 1); |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 889 | |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 890 | if (spi_dv_device_compare_inquiry(sdev, buffer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | buffer + len, |
| 892 | DV_LOOPS) |
| 893 | != SPI_COMPARE_SUCCESS) { |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 894 | starget_printk(KERN_ERR, starget, "Wide Transfers Fail\n"); |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 895 | i->f->set_width(starget, 0); |
James Bottomley | 2302827 | 2007-09-22 08:40:09 -0500 | [diff] [blame] | 896 | /* Make sure we don't force wide back on by asking |
| 897 | * for a transfer period that requires it */ |
| 898 | max_width = 0; |
| 899 | if (min_period < 10) |
| 900 | min_period = 10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | } |
| 902 | } |
| 903 | |
| 904 | if (!i->f->set_period) |
| 905 | return; |
| 906 | |
| 907 | /* device can't handle synchronous */ |
James Bottomley | 9872b81 | 2009-06-17 15:03:41 -0400 | [diff] [blame] | 908 | if (!spi_support_sync(starget) && !spi_support_dt(starget)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | return; |
| 910 | |
James Bottomley | 349cd7c | 2005-11-28 15:41:58 -0600 | [diff] [blame] | 911 | /* len == -1 is the signal that we need to ascertain the |
| 912 | * presence of an echo buffer before trying to use it. len == |
| 913 | * 0 means we don't have an echo buffer */ |
| 914 | len = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | |
| 916 | retry: |
| 917 | |
| 918 | /* now set up to the maximum */ |
James Bottomley | 62a8612 | 2005-05-06 18:05:20 -0500 | [diff] [blame] | 919 | DV_SET(offset, spi_max_offset(starget)); |
James Bottomley | 2302827 | 2007-09-22 08:40:09 -0500 | [diff] [blame] | 920 | DV_SET(period, min_period); |
| 921 | |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 922 | /* try QAS requests; this should be harmless to set if the |
| 923 | * target supports it */ |
James Bottomley | 9872b81 | 2009-06-17 15:03:41 -0400 | [diff] [blame] | 924 | if (spi_support_qas(starget) && spi_max_qas(starget)) { |
James Bottomley | eb1dd68 | 2005-07-02 12:22:01 -0400 | [diff] [blame] | 925 | DV_SET(qas, 1); |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 926 | } else { |
| 927 | DV_SET(qas, 0); |
| 928 | } |
| 929 | |
James Bottomley | 9872b81 | 2009-06-17 15:03:41 -0400 | [diff] [blame] | 930 | if (spi_support_ius(starget) && spi_max_iu(starget) && |
| 931 | min_period < 9) { |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 932 | /* This u320 (or u640). Set IU transfers */ |
James Bottomley | eb1dd68 | 2005-07-02 12:22:01 -0400 | [diff] [blame] | 933 | DV_SET(iu, 1); |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 934 | /* Then set the optional parameters */ |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 935 | DV_SET(rd_strm, 1); |
| 936 | DV_SET(wr_flow, 1); |
| 937 | DV_SET(rti, 1); |
James Bottomley | 2302827 | 2007-09-22 08:40:09 -0500 | [diff] [blame] | 938 | if (min_period == 8) |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 939 | DV_SET(pcomp_en, 1); |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 940 | } else { |
| 941 | DV_SET(iu, 0); |
James Bottomley | 9a8bc9b | 2005-05-31 18:35:39 -0500 | [diff] [blame] | 942 | } |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 943 | |
James Bottomley | 60eef25 | 2006-06-10 10:51:23 -0500 | [diff] [blame] | 944 | /* now that we've done all this, actually check the bus |
| 945 | * signal type (if known). Some devices are stupid on |
| 946 | * a SE bus and still claim they can try LVD only settings */ |
| 947 | if (i->f->get_signalling) |
| 948 | i->f->get_signalling(shost); |
| 949 | if (spi_signalling(shost) == SPI_SIGNAL_SE || |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 950 | spi_signalling(shost) == SPI_SIGNAL_HVD || |
James Bottomley | 9872b81 | 2009-06-17 15:03:41 -0400 | [diff] [blame] | 951 | !spi_support_dt(starget)) { |
James Bottomley | 60eef25 | 2006-06-10 10:51:23 -0500 | [diff] [blame] | 952 | DV_SET(dt, 0); |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 953 | } else { |
| 954 | DV_SET(dt, 1); |
| 955 | } |
James Bottomley | 2302827 | 2007-09-22 08:40:09 -0500 | [diff] [blame] | 956 | /* set width last because it will pull all the other |
| 957 | * parameters down to required values */ |
| 958 | DV_SET(width, max_width); |
| 959 | |
James Bottomley | 349cd7c | 2005-11-28 15:41:58 -0600 | [diff] [blame] | 960 | /* Do the read only INQUIRY tests */ |
| 961 | spi_dv_retrain(sdev, buffer, buffer + sdev->inquiry_len, |
| 962 | spi_dv_device_compare_inquiry); |
| 963 | /* See if we actually managed to negotiate and sustain DT */ |
| 964 | if (i->f->get_dt) |
| 965 | i->f->get_dt(starget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | |
James Bottomley | 349cd7c | 2005-11-28 15:41:58 -0600 | [diff] [blame] | 967 | /* see if the device has an echo buffer. If it does we can do |
| 968 | * the SPI pattern write tests. Because of some broken |
| 969 | * devices, we *only* try this on a device that has actually |
| 970 | * negotiated DT */ |
| 971 | |
| 972 | if (len == -1 && spi_dt(starget)) |
| 973 | len = spi_dv_device_get_echo_buffer(sdev, buffer); |
| 974 | |
| 975 | if (len <= 0) { |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 976 | starget_printk(KERN_INFO, starget, "Domain Validation skipping write tests\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | return; |
| 978 | } |
| 979 | |
| 980 | if (len > SPI_MAX_ECHO_BUFFER_SIZE) { |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 981 | starget_printk(KERN_WARNING, starget, "Echo buffer size %d is too big, trimming to %d\n", len, SPI_MAX_ECHO_BUFFER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | len = SPI_MAX_ECHO_BUFFER_SIZE; |
| 983 | } |
| 984 | |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 985 | if (spi_dv_retrain(sdev, buffer, buffer + len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | spi_dv_device_echo_buffer) |
| 987 | == SPI_COMPARE_SKIP_TEST) { |
| 988 | /* OK, the stupid drive can't do a write echo buffer |
| 989 | * test after all, fall back to the read tests */ |
| 990 | len = 0; |
| 991 | goto retry; |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | |
| 996 | /** spi_dv_device - Do Domain Validation on the device |
| 997 | * @sdev: scsi device to validate |
| 998 | * |
| 999 | * Performs the domain validation on the given device in the |
| 1000 | * current execution thread. Since DV operations may sleep, |
| 1001 | * the current thread must have user context. Also no SCSI |
| 1002 | * related locks that would deadlock I/O issued by the DV may |
| 1003 | * be held. |
| 1004 | */ |
| 1005 | void |
| 1006 | spi_dv_device(struct scsi_device *sdev) |
| 1007 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | struct scsi_target *starget = sdev->sdev_target; |
| 1009 | u8 *buffer; |
| 1010 | const int len = SPI_MAX_ECHO_BUFFER_SIZE*2; |
| 1011 | |
Mike Maslenkin | 89a342c | 2012-04-28 05:32:14 +0400 | [diff] [blame] | 1012 | if (unlikely(spi_dv_in_progress(starget))) |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 1013 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | |
Mike Maslenkin | 89a342c | 2012-04-28 05:32:14 +0400 | [diff] [blame] | 1015 | if (unlikely(scsi_device_get(sdev))) |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 1016 | return; |
| 1017 | spi_dv_in_progress(starget) = 1; |
| 1018 | |
Jes Sorensen | 24669f75 | 2006-01-16 10:31:18 -0500 | [diff] [blame] | 1019 | buffer = kzalloc(len, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | |
| 1021 | if (unlikely(!buffer)) |
| 1022 | goto out_put; |
| 1023 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | /* We need to verify that the actual device will quiesce; the |
| 1025 | * later target quiesce is just a nice to have */ |
| 1026 | if (unlikely(scsi_device_quiesce(sdev))) |
| 1027 | goto out_free; |
| 1028 | |
| 1029 | scsi_target_quiesce(starget); |
| 1030 | |
| 1031 | spi_dv_pending(starget) = 1; |
Jes Sorensen | d158d26 | 2006-01-13 16:05:44 -0800 | [diff] [blame] | 1032 | mutex_lock(&spi_dv_mutex(starget)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 1034 | starget_printk(KERN_INFO, starget, "Beginning Domain Validation\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | |
James Bottomley | 33aa687 | 2005-08-28 11:31:14 -0500 | [diff] [blame] | 1036 | spi_dv_device_internal(sdev, buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 1038 | starget_printk(KERN_INFO, starget, "Ending Domain Validation\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | |
Jes Sorensen | d158d26 | 2006-01-13 16:05:44 -0800 | [diff] [blame] | 1040 | mutex_unlock(&spi_dv_mutex(starget)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | spi_dv_pending(starget) = 0; |
| 1042 | |
| 1043 | scsi_target_resume(starget); |
| 1044 | |
| 1045 | spi_initial_dv(starget) = 1; |
| 1046 | |
| 1047 | out_free: |
| 1048 | kfree(buffer); |
| 1049 | out_put: |
James Bottomley | dfdc58b | 2006-09-20 12:00:18 -0400 | [diff] [blame] | 1050 | spi_dv_in_progress(starget) = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | scsi_device_put(sdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | } |
| 1053 | EXPORT_SYMBOL(spi_dv_device); |
| 1054 | |
| 1055 | struct work_queue_wrapper { |
| 1056 | struct work_struct work; |
| 1057 | struct scsi_device *sdev; |
| 1058 | }; |
| 1059 | |
| 1060 | static void |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1061 | spi_dv_device_work_wrapper(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1063 | struct work_queue_wrapper *wqw = |
| 1064 | container_of(work, struct work_queue_wrapper, work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | struct scsi_device *sdev = wqw->sdev; |
| 1066 | |
| 1067 | kfree(wqw); |
| 1068 | spi_dv_device(sdev); |
| 1069 | spi_dv_pending(sdev->sdev_target) = 0; |
| 1070 | scsi_device_put(sdev); |
| 1071 | } |
| 1072 | |
| 1073 | |
| 1074 | /** |
| 1075 | * spi_schedule_dv_device - schedule domain validation to occur on the device |
| 1076 | * @sdev: The device to validate |
| 1077 | * |
| 1078 | * Identical to spi_dv_device() above, except that the DV will be |
| 1079 | * scheduled to occur in a workqueue later. All memory allocations |
| 1080 | * are atomic, so may be called from any context including those holding |
| 1081 | * SCSI locks. |
| 1082 | */ |
| 1083 | void |
| 1084 | spi_schedule_dv_device(struct scsi_device *sdev) |
| 1085 | { |
| 1086 | struct work_queue_wrapper *wqw = |
| 1087 | kmalloc(sizeof(struct work_queue_wrapper), GFP_ATOMIC); |
| 1088 | |
| 1089 | if (unlikely(!wqw)) |
| 1090 | return; |
| 1091 | |
| 1092 | if (unlikely(spi_dv_pending(sdev->sdev_target))) { |
| 1093 | kfree(wqw); |
| 1094 | return; |
| 1095 | } |
| 1096 | /* Set pending early (dv_device doesn't check it, only sets it) */ |
| 1097 | spi_dv_pending(sdev->sdev_target) = 1; |
| 1098 | if (unlikely(scsi_device_get(sdev))) { |
| 1099 | kfree(wqw); |
| 1100 | spi_dv_pending(sdev->sdev_target) = 0; |
| 1101 | return; |
| 1102 | } |
| 1103 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1104 | INIT_WORK(&wqw->work, spi_dv_device_work_wrapper); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | wqw->sdev = sdev; |
| 1106 | |
| 1107 | schedule_work(&wqw->work); |
| 1108 | } |
| 1109 | EXPORT_SYMBOL(spi_schedule_dv_device); |
| 1110 | |
| 1111 | /** |
| 1112 | * spi_display_xfer_agreement - Print the current target transfer agreement |
| 1113 | * @starget: The target for which to display the agreement |
| 1114 | * |
| 1115 | * Each SPI port is required to maintain a transfer agreement for each |
| 1116 | * other port on the bus. This function prints a one-line summary of |
| 1117 | * the current agreement; more detailed information is available in sysfs. |
| 1118 | */ |
| 1119 | void spi_display_xfer_agreement(struct scsi_target *starget) |
| 1120 | { |
| 1121 | struct spi_transport_attrs *tp; |
| 1122 | tp = (struct spi_transport_attrs *)&starget->starget_data; |
| 1123 | |
| 1124 | if (tp->offset > 0 && tp->period > 0) { |
| 1125 | unsigned int picosec, kb100; |
| 1126 | char *scsi = "FAST-?"; |
| 1127 | char tmp[8]; |
| 1128 | |
| 1129 | if (tp->period <= SPI_STATIC_PPR) { |
| 1130 | picosec = ppr_to_ps[tp->period]; |
| 1131 | switch (tp->period) { |
| 1132 | case 7: scsi = "FAST-320"; break; |
| 1133 | case 8: scsi = "FAST-160"; break; |
| 1134 | case 9: scsi = "FAST-80"; break; |
| 1135 | case 10: |
| 1136 | case 11: scsi = "FAST-40"; break; |
| 1137 | case 12: scsi = "FAST-20"; break; |
| 1138 | } |
| 1139 | } else { |
| 1140 | picosec = tp->period * 4000; |
| 1141 | if (tp->period < 25) |
| 1142 | scsi = "FAST-20"; |
| 1143 | else if (tp->period < 50) |
| 1144 | scsi = "FAST-10"; |
| 1145 | else |
| 1146 | scsi = "FAST-5"; |
| 1147 | } |
| 1148 | |
| 1149 | kb100 = (10000000 + picosec / 2) / picosec; |
| 1150 | if (tp->width) |
| 1151 | kb100 *= 2; |
| 1152 | sprint_frac(tmp, picosec, 1000); |
| 1153 | |
| 1154 | dev_info(&starget->dev, |
James Bottomley | d872ebe | 2005-08-03 15:43:52 -0500 | [diff] [blame] | 1155 | "%s %sSCSI %d.%d MB/s %s%s%s%s%s%s%s%s (%s ns, offset %d)\n", |
| 1156 | scsi, tp->width ? "WIDE " : "", kb100/10, kb100 % 10, |
| 1157 | tp->dt ? "DT" : "ST", |
| 1158 | tp->iu ? " IU" : "", |
| 1159 | tp->qas ? " QAS" : "", |
| 1160 | tp->rd_strm ? " RDSTRM" : "", |
| 1161 | tp->rti ? " RTI" : "", |
| 1162 | tp->wr_flow ? " WRFLOW" : "", |
| 1163 | tp->pcomp_en ? " PCOMP" : "", |
| 1164 | tp->hold_mcs ? " HMCS" : "", |
| 1165 | tmp, tp->offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | } else { |
Matthew Wilcox | 493ff4e | 2005-11-17 11:13:43 -0700 | [diff] [blame] | 1167 | dev_info(&starget->dev, "%sasynchronous\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | tp->width ? "wide " : ""); |
| 1169 | } |
| 1170 | } |
| 1171 | EXPORT_SYMBOL(spi_display_xfer_agreement); |
| 1172 | |
Matthew Wilcox | 6ea3c0b | 2006-02-07 07:54:46 -0700 | [diff] [blame] | 1173 | int spi_populate_width_msg(unsigned char *msg, int width) |
| 1174 | { |
| 1175 | msg[0] = EXTENDED_MESSAGE; |
| 1176 | msg[1] = 2; |
| 1177 | msg[2] = EXTENDED_WDTR; |
| 1178 | msg[3] = width; |
| 1179 | return 4; |
| 1180 | } |
James Bottomley | 38e14f8 | 2006-02-17 14:58:47 -0800 | [diff] [blame] | 1181 | EXPORT_SYMBOL_GPL(spi_populate_width_msg); |
Matthew Wilcox | 6ea3c0b | 2006-02-07 07:54:46 -0700 | [diff] [blame] | 1182 | |
| 1183 | int spi_populate_sync_msg(unsigned char *msg, int period, int offset) |
| 1184 | { |
| 1185 | msg[0] = EXTENDED_MESSAGE; |
| 1186 | msg[1] = 3; |
| 1187 | msg[2] = EXTENDED_SDTR; |
| 1188 | msg[3] = period; |
| 1189 | msg[4] = offset; |
| 1190 | return 5; |
| 1191 | } |
James Bottomley | 38e14f8 | 2006-02-17 14:58:47 -0800 | [diff] [blame] | 1192 | EXPORT_SYMBOL_GPL(spi_populate_sync_msg); |
Matthew Wilcox | 6ea3c0b | 2006-02-07 07:54:46 -0700 | [diff] [blame] | 1193 | |
| 1194 | int spi_populate_ppr_msg(unsigned char *msg, int period, int offset, |
| 1195 | int width, int options) |
| 1196 | { |
| 1197 | msg[0] = EXTENDED_MESSAGE; |
| 1198 | msg[1] = 6; |
| 1199 | msg[2] = EXTENDED_PPR; |
| 1200 | msg[3] = period; |
| 1201 | msg[4] = 0; |
| 1202 | msg[5] = offset; |
| 1203 | msg[6] = width; |
| 1204 | msg[7] = options; |
| 1205 | return 8; |
| 1206 | } |
James Bottomley | 38e14f8 | 2006-02-17 14:58:47 -0800 | [diff] [blame] | 1207 | EXPORT_SYMBOL_GPL(spi_populate_ppr_msg); |
Matthew Wilcox | 6ea3c0b | 2006-02-07 07:54:46 -0700 | [diff] [blame] | 1208 | |
Christoph Hellwig | 5066863 | 2014-10-30 14:30:06 +0100 | [diff] [blame] | 1209 | /** |
| 1210 | * spi_populate_tag_msg - place a tag message in a buffer |
| 1211 | * @msg: pointer to the area to place the tag |
| 1212 | * @cmd: pointer to the scsi command for the tag |
| 1213 | * |
| 1214 | * Notes: |
| 1215 | * designed to create the correct type of tag message for the |
| 1216 | * particular request. Returns the size of the tag message. |
| 1217 | * May return 0 if TCQ is disabled for this device. |
| 1218 | **/ |
| 1219 | int spi_populate_tag_msg(unsigned char *msg, struct scsi_cmnd *cmd) |
| 1220 | { |
| 1221 | if (cmd->flags & SCMD_TAGGED) { |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 1222 | *msg++ = SIMPLE_QUEUE_TAG; |
Christoph Hellwig | 5066863 | 2014-10-30 14:30:06 +0100 | [diff] [blame] | 1223 | *msg++ = cmd->request->tag; |
| 1224 | return 2; |
| 1225 | } |
| 1226 | |
| 1227 | return 0; |
| 1228 | } |
| 1229 | EXPORT_SYMBOL_GPL(spi_populate_tag_msg); |
| 1230 | |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1231 | #ifdef CONFIG_SCSI_CONSTANTS |
| 1232 | static const char * const one_byte_msgs[] = { |
Matthew Wilcox | 72df0eb | 2006-03-10 07:18:22 -0700 | [diff] [blame] | 1233 | /* 0x00 */ "Task Complete", NULL /* Extended Message */, "Save Pointers", |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1234 | /* 0x03 */ "Restore Pointers", "Disconnect", "Initiator Error", |
Matthew Wilcox | 72df0eb | 2006-03-10 07:18:22 -0700 | [diff] [blame] | 1235 | /* 0x06 */ "Abort Task Set", "Message Reject", "Nop", "Message Parity Error", |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1236 | /* 0x0a */ "Linked Command Complete", "Linked Command Complete w/flag", |
Matthew Wilcox | 72df0eb | 2006-03-10 07:18:22 -0700 | [diff] [blame] | 1237 | /* 0x0c */ "Target Reset", "Abort Task", "Clear Task Set", |
| 1238 | /* 0x0f */ "Initiate Recovery", "Release Recovery", |
| 1239 | /* 0x11 */ "Terminate Process", "Continue Task", "Target Transfer Disable", |
| 1240 | /* 0x14 */ NULL, NULL, "Clear ACA", "LUN Reset" |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1241 | }; |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1242 | |
| 1243 | static const char * const two_byte_msgs[] = { |
Matthew Wilcox | 4797215 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1244 | /* 0x20 */ "Simple Queue Tag", "Head of Queue Tag", "Ordered Queue Tag", |
Matthew Wilcox | 72df0eb | 2006-03-10 07:18:22 -0700 | [diff] [blame] | 1245 | /* 0x23 */ "Ignore Wide Residue", "ACA" |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1246 | }; |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1247 | |
| 1248 | static const char * const extended_msgs[] = { |
| 1249 | /* 0x00 */ "Modify Data Pointer", "Synchronous Data Transfer Request", |
Matthew Wilcox | ef72582 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1250 | /* 0x02 */ "SCSI-I Extended Identify", "Wide Data Transfer Request", |
Matthew Wilcox | fc25307 | 2006-02-18 20:52:31 -0700 | [diff] [blame] | 1251 | /* 0x04 */ "Parallel Protocol Request", "Modify Bidirectional Data Pointer" |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1252 | }; |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1253 | |
Adrian Bunk | bdd70f2 | 2006-01-05 23:39:18 +0100 | [diff] [blame] | 1254 | static void print_nego(const unsigned char *msg, int per, int off, int width) |
Matthew Wilcox | ef72582 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1255 | { |
| 1256 | if (per) { |
| 1257 | char buf[20]; |
| 1258 | period_to_str(buf, msg[per]); |
| 1259 | printk("period = %s ns ", buf); |
| 1260 | } |
| 1261 | |
| 1262 | if (off) |
| 1263 | printk("offset = %d ", msg[off]); |
| 1264 | if (width) |
| 1265 | printk("width = %d ", 8 << msg[width]); |
| 1266 | } |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1267 | |
Matthew Wilcox | fc25307 | 2006-02-18 20:52:31 -0700 | [diff] [blame] | 1268 | static void print_ptr(const unsigned char *msg, int msb, const char *desc) |
| 1269 | { |
| 1270 | int ptr = (msg[msb] << 24) | (msg[msb+1] << 16) | (msg[msb+2] << 8) | |
| 1271 | msg[msb+3]; |
| 1272 | printk("%s = %d ", desc, ptr); |
| 1273 | } |
| 1274 | |
Matthew Wilcox | 1abfd37 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1275 | int spi_print_msg(const unsigned char *msg) |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1276 | { |
Matthew Wilcox | 72df0eb | 2006-03-10 07:18:22 -0700 | [diff] [blame] | 1277 | int len = 1, i; |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1278 | if (msg[0] == EXTENDED_MESSAGE) { |
Matthew Wilcox | fc25307 | 2006-02-18 20:52:31 -0700 | [diff] [blame] | 1279 | len = 2 + msg[1]; |
| 1280 | if (len == 2) |
| 1281 | len += 256; |
Matthew Wilcox | b32aaff | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1282 | if (msg[2] < ARRAY_SIZE(extended_msgs)) |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1283 | printk ("%s ", extended_msgs[msg[2]]); |
| 1284 | else |
| 1285 | printk ("Extended Message, reserved code (0x%02x) ", |
| 1286 | (int) msg[2]); |
| 1287 | switch (msg[2]) { |
| 1288 | case EXTENDED_MODIFY_DATA_POINTER: |
Matthew Wilcox | fc25307 | 2006-02-18 20:52:31 -0700 | [diff] [blame] | 1289 | print_ptr(msg, 3, "pointer"); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1290 | break; |
| 1291 | case EXTENDED_SDTR: |
Matthew Wilcox | ef72582 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1292 | print_nego(msg, 3, 4, 0); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1293 | break; |
| 1294 | case EXTENDED_WDTR: |
Matthew Wilcox | ef72582 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1295 | print_nego(msg, 0, 0, 3); |
| 1296 | break; |
| 1297 | case EXTENDED_PPR: |
| 1298 | print_nego(msg, 3, 5, 6); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1299 | break; |
Matthew Wilcox | fc25307 | 2006-02-18 20:52:31 -0700 | [diff] [blame] | 1300 | case EXTENDED_MODIFY_BIDI_DATA_PTR: |
| 1301 | print_ptr(msg, 3, "out"); |
| 1302 | print_ptr(msg, 7, "in"); |
| 1303 | break; |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1304 | default: |
| 1305 | for (i = 2; i < len; ++i) |
| 1306 | printk("%02x ", msg[i]); |
| 1307 | } |
| 1308 | /* Identify */ |
| 1309 | } else if (msg[0] & 0x80) { |
| 1310 | printk("Identify disconnect %sallowed %s %d ", |
| 1311 | (msg[0] & 0x40) ? "" : "not ", |
| 1312 | (msg[0] & 0x20) ? "target routine" : "lun", |
| 1313 | msg[0] & 0x7); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1314 | /* Normal One byte */ |
| 1315 | } else if (msg[0] < 0x1f) { |
Matthew Wilcox | 72df0eb | 2006-03-10 07:18:22 -0700 | [diff] [blame] | 1316 | if (msg[0] < ARRAY_SIZE(one_byte_msgs) && one_byte_msgs[msg[0]]) |
Matthew Wilcox | e24d873 | 2006-02-07 08:05:26 -0700 | [diff] [blame] | 1317 | printk("%s ", one_byte_msgs[msg[0]]); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1318 | else |
| 1319 | printk("reserved (%02x) ", msg[0]); |
Matthew Wilcox | 72df0eb | 2006-03-10 07:18:22 -0700 | [diff] [blame] | 1320 | } else if (msg[0] == 0x55) { |
| 1321 | printk("QAS Request "); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1322 | /* Two byte */ |
| 1323 | } else if (msg[0] <= 0x2f) { |
Matthew Wilcox | b32aaff | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1324 | if ((msg[0] - 0x20) < ARRAY_SIZE(two_byte_msgs)) |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1325 | printk("%s %02x ", two_byte_msgs[msg[0] - 0x20], |
| 1326 | msg[1]); |
| 1327 | else |
| 1328 | printk("reserved two byte (%02x %02x) ", |
| 1329 | msg[0], msg[1]); |
| 1330 | len = 2; |
| 1331 | } else |
Matthew Wilcox | e24d873 | 2006-02-07 08:05:26 -0700 | [diff] [blame] | 1332 | printk("reserved "); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1333 | return len; |
| 1334 | } |
Matthew Wilcox | 1abfd37 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1335 | EXPORT_SYMBOL(spi_print_msg); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1336 | |
| 1337 | #else /* ifndef CONFIG_SCSI_CONSTANTS */ |
| 1338 | |
Matthew Wilcox | 1abfd37 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1339 | int spi_print_msg(const unsigned char *msg) |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1340 | { |
Matthew Wilcox | 72df0eb | 2006-03-10 07:18:22 -0700 | [diff] [blame] | 1341 | int len = 1, i; |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1342 | |
| 1343 | if (msg[0] == EXTENDED_MESSAGE) { |
Matthew Wilcox | fc25307 | 2006-02-18 20:52:31 -0700 | [diff] [blame] | 1344 | len = 2 + msg[1]; |
| 1345 | if (len == 2) |
| 1346 | len += 256; |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1347 | for (i = 0; i < len; ++i) |
| 1348 | printk("%02x ", msg[i]); |
| 1349 | /* Identify */ |
| 1350 | } else if (msg[0] & 0x80) { |
| 1351 | printk("%02x ", msg[0]); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1352 | /* Normal One byte */ |
James Bottomley | 597705a | 2006-03-12 09:54:19 -0600 | [diff] [blame] | 1353 | } else if ((msg[0] < 0x1f) || (msg[0] == 0x55)) { |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1354 | printk("%02x ", msg[0]); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1355 | /* Two byte */ |
| 1356 | } else if (msg[0] <= 0x2f) { |
| 1357 | printk("%02x %02x", msg[0], msg[1]); |
| 1358 | len = 2; |
| 1359 | } else |
| 1360 | printk("%02x ", msg[0]); |
| 1361 | return len; |
| 1362 | } |
Matthew Wilcox | 1abfd37 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1363 | EXPORT_SYMBOL(spi_print_msg); |
Matthew Wilcox | 410ca5c | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 1364 | #endif /* ! CONFIG_SCSI_CONSTANTS */ |
| 1365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | static int spi_device_match(struct attribute_container *cont, |
| 1367 | struct device *dev) |
| 1368 | { |
| 1369 | struct scsi_device *sdev; |
| 1370 | struct Scsi_Host *shost; |
James Bottomley | 10c1b88 | 2005-08-14 14:34:06 -0500 | [diff] [blame] | 1371 | struct spi_internal *i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | |
| 1373 | if (!scsi_is_sdev_device(dev)) |
| 1374 | return 0; |
| 1375 | |
| 1376 | sdev = to_scsi_device(dev); |
| 1377 | shost = sdev->host; |
| 1378 | if (!shost->transportt || shost->transportt->host_attrs.ac.class |
| 1379 | != &spi_host_class.class) |
| 1380 | return 0; |
| 1381 | /* Note: this class has no device attributes, so it has |
| 1382 | * no per-HBA allocation and thus we don't need to distinguish |
| 1383 | * the attribute containers for the device */ |
James Bottomley | 10c1b88 | 2005-08-14 14:34:06 -0500 | [diff] [blame] | 1384 | i = to_spi_internal(shost->transportt); |
| 1385 | if (i->f->deny_binding && i->f->deny_binding(sdev->sdev_target)) |
| 1386 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | return 1; |
| 1388 | } |
| 1389 | |
| 1390 | static int spi_target_match(struct attribute_container *cont, |
| 1391 | struct device *dev) |
| 1392 | { |
| 1393 | struct Scsi_Host *shost; |
James Bottomley | 10c1b88 | 2005-08-14 14:34:06 -0500 | [diff] [blame] | 1394 | struct scsi_target *starget; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | struct spi_internal *i; |
| 1396 | |
| 1397 | if (!scsi_is_target_device(dev)) |
| 1398 | return 0; |
| 1399 | |
| 1400 | shost = dev_to_shost(dev->parent); |
| 1401 | if (!shost->transportt || shost->transportt->host_attrs.ac.class |
| 1402 | != &spi_host_class.class) |
| 1403 | return 0; |
| 1404 | |
| 1405 | i = to_spi_internal(shost->transportt); |
James Bottomley | 10c1b88 | 2005-08-14 14:34:06 -0500 | [diff] [blame] | 1406 | starget = to_scsi_target(dev); |
| 1407 | |
| 1408 | if (i->f->deny_binding && i->f->deny_binding(starget)) |
| 1409 | return 0; |
| 1410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | return &i->t.target_attrs.ac == cont; |
| 1412 | } |
| 1413 | |
| 1414 | static DECLARE_TRANSPORT_CLASS(spi_transport_class, |
| 1415 | "spi_transport", |
| 1416 | spi_setup_transport_attrs, |
| 1417 | NULL, |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1418 | spi_target_configure); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | |
| 1420 | static DECLARE_ANON_TRANSPORT_CLASS(spi_device_class, |
| 1421 | spi_device_match, |
| 1422 | spi_device_configure); |
| 1423 | |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1424 | static struct attribute *host_attributes[] = { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1425 | &dev_attr_signalling.attr, |
Hannes Reinecke | 0ac2377 | 2011-06-30 02:19:57 +0530 | [diff] [blame] | 1426 | &dev_attr_host_width.attr, |
| 1427 | &dev_attr_hba_id.attr, |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1428 | NULL |
| 1429 | }; |
| 1430 | |
| 1431 | static struct attribute_group host_attribute_group = { |
| 1432 | .attrs = host_attributes, |
| 1433 | }; |
| 1434 | |
| 1435 | static int spi_host_configure(struct transport_container *tc, |
| 1436 | struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1437 | struct device *cdev) |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1438 | { |
| 1439 | struct kobject *kobj = &cdev->kobj; |
| 1440 | struct Scsi_Host *shost = transport_class_to_shost(cdev); |
| 1441 | struct spi_internal *si = to_spi_internal(shost->transportt); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1442 | struct attribute *attr = &dev_attr_signalling.attr; |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1443 | int rc = 0; |
| 1444 | |
| 1445 | if (si->f->set_signalling) |
| 1446 | rc = sysfs_chmod_file(kobj, attr, attr->mode | S_IWUSR); |
| 1447 | |
| 1448 | return rc; |
| 1449 | } |
| 1450 | |
| 1451 | /* returns true if we should be showing the variable. Also |
| 1452 | * overloads the return by setting 1<<1 if the attribute should |
| 1453 | * be writeable */ |
| 1454 | #define TARGET_ATTRIBUTE_HELPER(name) \ |
James Bottomley | 352f6bb | 2008-03-20 20:57:02 -0500 | [diff] [blame] | 1455 | (si->f->show_##name ? S_IRUGO : 0) | \ |
| 1456 | (si->f->set_##name ? S_IWUSR : 0) |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1457 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 1458 | static umode_t target_attribute_is_visible(struct kobject *kobj, |
James Bottomley | 352f6bb | 2008-03-20 20:57:02 -0500 | [diff] [blame] | 1459 | struct attribute *attr, int i) |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1460 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1461 | struct device *cdev = container_of(kobj, struct device, kobj); |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1462 | struct scsi_target *starget = transport_class_to_starget(cdev); |
| 1463 | struct Scsi_Host *shost = transport_class_to_shost(cdev); |
| 1464 | struct spi_internal *si = to_spi_internal(shost->transportt); |
| 1465 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1466 | if (attr == &dev_attr_period.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1467 | spi_support_sync(starget)) |
| 1468 | return TARGET_ATTRIBUTE_HELPER(period); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1469 | else if (attr == &dev_attr_min_period.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1470 | spi_support_sync(starget)) |
| 1471 | return TARGET_ATTRIBUTE_HELPER(period); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1472 | else if (attr == &dev_attr_offset.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1473 | spi_support_sync(starget)) |
| 1474 | return TARGET_ATTRIBUTE_HELPER(offset); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1475 | else if (attr == &dev_attr_max_offset.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1476 | spi_support_sync(starget)) |
| 1477 | return TARGET_ATTRIBUTE_HELPER(offset); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1478 | else if (attr == &dev_attr_width.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1479 | spi_support_wide(starget)) |
| 1480 | return TARGET_ATTRIBUTE_HELPER(width); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1481 | else if (attr == &dev_attr_max_width.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1482 | spi_support_wide(starget)) |
| 1483 | return TARGET_ATTRIBUTE_HELPER(width); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1484 | else if (attr == &dev_attr_iu.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1485 | spi_support_ius(starget)) |
| 1486 | return TARGET_ATTRIBUTE_HELPER(iu); |
James Bottomley | ea44319 | 2009-06-13 12:19:05 -0500 | [diff] [blame] | 1487 | else if (attr == &dev_attr_max_iu.attr && |
| 1488 | spi_support_ius(starget)) |
| 1489 | return TARGET_ATTRIBUTE_HELPER(iu); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1490 | else if (attr == &dev_attr_dt.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1491 | spi_support_dt(starget)) |
| 1492 | return TARGET_ATTRIBUTE_HELPER(dt); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1493 | else if (attr == &dev_attr_qas.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1494 | spi_support_qas(starget)) |
| 1495 | return TARGET_ATTRIBUTE_HELPER(qas); |
James Bottomley | ea44319 | 2009-06-13 12:19:05 -0500 | [diff] [blame] | 1496 | else if (attr == &dev_attr_max_qas.attr && |
| 1497 | spi_support_qas(starget)) |
| 1498 | return TARGET_ATTRIBUTE_HELPER(qas); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1499 | else if (attr == &dev_attr_wr_flow.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1500 | spi_support_ius(starget)) |
| 1501 | return TARGET_ATTRIBUTE_HELPER(wr_flow); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1502 | else if (attr == &dev_attr_rd_strm.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1503 | spi_support_ius(starget)) |
| 1504 | return TARGET_ATTRIBUTE_HELPER(rd_strm); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1505 | else if (attr == &dev_attr_rti.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1506 | spi_support_ius(starget)) |
| 1507 | return TARGET_ATTRIBUTE_HELPER(rti); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1508 | else if (attr == &dev_attr_pcomp_en.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1509 | spi_support_ius(starget)) |
| 1510 | return TARGET_ATTRIBUTE_HELPER(pcomp_en); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1511 | else if (attr == &dev_attr_hold_mcs.attr && |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1512 | spi_support_ius(starget)) |
| 1513 | return TARGET_ATTRIBUTE_HELPER(hold_mcs); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1514 | else if (attr == &dev_attr_revalidate.attr) |
James Bottomley | 352f6bb | 2008-03-20 20:57:02 -0500 | [diff] [blame] | 1515 | return S_IWUSR; |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1516 | |
| 1517 | return 0; |
| 1518 | } |
| 1519 | |
| 1520 | static struct attribute *target_attributes[] = { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1521 | &dev_attr_period.attr, |
| 1522 | &dev_attr_min_period.attr, |
| 1523 | &dev_attr_offset.attr, |
| 1524 | &dev_attr_max_offset.attr, |
| 1525 | &dev_attr_width.attr, |
| 1526 | &dev_attr_max_width.attr, |
| 1527 | &dev_attr_iu.attr, |
James Bottomley | ea44319 | 2009-06-13 12:19:05 -0500 | [diff] [blame] | 1528 | &dev_attr_max_iu.attr, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1529 | &dev_attr_dt.attr, |
| 1530 | &dev_attr_qas.attr, |
James Bottomley | ea44319 | 2009-06-13 12:19:05 -0500 | [diff] [blame] | 1531 | &dev_attr_max_qas.attr, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1532 | &dev_attr_wr_flow.attr, |
| 1533 | &dev_attr_rd_strm.attr, |
| 1534 | &dev_attr_rti.attr, |
| 1535 | &dev_attr_pcomp_en.attr, |
| 1536 | &dev_attr_hold_mcs.attr, |
| 1537 | &dev_attr_revalidate.attr, |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1538 | NULL |
| 1539 | }; |
| 1540 | |
| 1541 | static struct attribute_group target_attribute_group = { |
| 1542 | .attrs = target_attributes, |
| 1543 | .is_visible = target_attribute_is_visible, |
| 1544 | }; |
| 1545 | |
| 1546 | static int spi_target_configure(struct transport_container *tc, |
| 1547 | struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1548 | struct device *cdev) |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1549 | { |
| 1550 | struct kobject *kobj = &cdev->kobj; |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1551 | |
James Bottomley | 352f6bb | 2008-03-20 20:57:02 -0500 | [diff] [blame] | 1552 | /* force an update based on parameters read from the device */ |
| 1553 | sysfs_update_group(kobj, &target_attribute_group); |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1554 | |
| 1555 | return 0; |
| 1556 | } |
| 1557 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | struct scsi_transport_template * |
| 1559 | spi_attach_transport(struct spi_function_template *ft) |
| 1560 | { |
Jes Sorensen | 24669f75 | 2006-01-16 10:31:18 -0500 | [diff] [blame] | 1561 | struct spi_internal *i = kzalloc(sizeof(struct spi_internal), |
| 1562 | GFP_KERNEL); |
| 1563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | if (unlikely(!i)) |
| 1565 | return NULL; |
| 1566 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | i->t.target_attrs.ac.class = &spi_transport_class.class; |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1568 | i->t.target_attrs.ac.grp = &target_attribute_group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | i->t.target_attrs.ac.match = spi_target_match; |
| 1570 | transport_container_register(&i->t.target_attrs); |
| 1571 | i->t.target_size = sizeof(struct spi_transport_attrs); |
| 1572 | i->t.host_attrs.ac.class = &spi_host_class.class; |
James Bottomley | 9b161a4 | 2008-01-05 10:18:27 -0600 | [diff] [blame] | 1573 | i->t.host_attrs.ac.grp = &host_attribute_group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | i->t.host_attrs.ac.match = spi_host_match; |
| 1575 | transport_container_register(&i->t.host_attrs); |
| 1576 | i->t.host_size = sizeof(struct spi_host_attrs); |
| 1577 | i->f = ft; |
| 1578 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | return &i->t; |
| 1580 | } |
| 1581 | EXPORT_SYMBOL(spi_attach_transport); |
| 1582 | |
| 1583 | void spi_release_transport(struct scsi_transport_template *t) |
| 1584 | { |
| 1585 | struct spi_internal *i = to_spi_internal(t); |
| 1586 | |
| 1587 | transport_container_unregister(&i->t.target_attrs); |
| 1588 | transport_container_unregister(&i->t.host_attrs); |
| 1589 | |
| 1590 | kfree(i); |
| 1591 | } |
| 1592 | EXPORT_SYMBOL(spi_release_transport); |
| 1593 | |
| 1594 | static __init int spi_transport_init(void) |
| 1595 | { |
James Bottomley | a9e0edb | 2009-06-17 19:05:05 +0000 | [diff] [blame] | 1596 | int error = scsi_dev_info_add_list(SCSI_DEVINFO_SPI, |
| 1597 | "SCSI Parallel Transport Class"); |
| 1598 | if (!error) { |
| 1599 | int i; |
| 1600 | |
| 1601 | for (i = 0; spi_static_device_list[i].vendor; i++) |
| 1602 | scsi_dev_info_list_add_keyed(1, /* compatible */ |
| 1603 | spi_static_device_list[i].vendor, |
| 1604 | spi_static_device_list[i].model, |
| 1605 | NULL, |
| 1606 | spi_static_device_list[i].flags, |
| 1607 | SCSI_DEVINFO_SPI); |
| 1608 | } |
| 1609 | |
| 1610 | error = transport_class_register(&spi_transport_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | if (error) |
| 1612 | return error; |
| 1613 | error = anon_transport_class_register(&spi_device_class); |
| 1614 | return transport_class_register(&spi_host_class); |
| 1615 | } |
| 1616 | |
| 1617 | static void __exit spi_transport_exit(void) |
| 1618 | { |
| 1619 | transport_class_unregister(&spi_transport_class); |
| 1620 | anon_transport_class_unregister(&spi_device_class); |
| 1621 | transport_class_unregister(&spi_host_class); |
James Bottomley | a9e0edb | 2009-06-17 19:05:05 +0000 | [diff] [blame] | 1622 | scsi_dev_info_remove_list(SCSI_DEVINFO_SPI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | MODULE_AUTHOR("Martin Hicks"); |
| 1626 | MODULE_DESCRIPTION("SPI Transport Attributes"); |
| 1627 | MODULE_LICENSE("GPL"); |
| 1628 | |
| 1629 | module_init(spi_transport_init); |
| 1630 | module_exit(spi_transport_exit); |