22 #include <linux/module.h>
25 #include <linux/slab.h>
26 #include <linux/string.h>
28 #include <scsi/scsi.h>
38 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
40 #define SRP_HOST_ATTRS 0
41 #define SRP_RPORT_ATTRS 2
54 #define to_srp_internal(tmpl) container_of(tmpl, struct srp_internal, t)
56 #define dev_to_rport(d) container_of(d, struct srp_rport, dev)
57 #define transport_class_to_srp_rport(dev) dev_to_rport((dev)->parent)
75 #define SETUP_TEMPLATE(attrb, field, perm, test, ro_test, ro_perm) \
76 i->private_##attrb[count] = dev_attr_##field; \
77 i->private_##attrb[count].attr.mode = perm; \
79 i->private_##attrb[count].attr.mode = ro_perm; \
80 i->private_##attrb[count].store = NULL; \
82 i->attrb[count] = &i->private_##attrb[count]; \
86 #define SETUP_RPORT_ATTRIBUTE_RD(field) \
87 SETUP_TEMPLATE(rport_attrs, field, S_IRUGO, 1, 0, 0)
89 #define SETUP_RPORT_ATTRIBUTE_RW(field) \
90 SETUP_TEMPLATE(rport_attrs, field, S_IRUGO | S_IWUSR, \
94 (p)->port_id[0], (p)->port_id[1], (p)->port_id[2], (p)->port_id[3], \
95 (p)->port_id[4], (p)->port_id[5], (p)->port_id[6], (p)->port_id[7], \
96 (p)->port_id[8], (p)->port_id[9], (p)->port_id[10], (p)->port_id[11], \
97 (p)->port_id[12], (p)->port_id[13], (p)->port_id[14], (p)->port_id[15]
99 #define SRP_PID_FMT "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:" \
100 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x"
112 static const struct {
115 } srp_rport_role_names[] = {
128 for (i = 0; i <
ARRAY_SIZE(srp_rport_role_names); i++)
129 if (srp_rport_role_names[i].
value == rport->
roles) {
130 name = srp_rport_role_names[
i].name;
133 return sprintf(buf,
"%s\n", name ? :
"unknown");
138 static void srp_rport_release(
struct device *dev)
146 static int scsi_is_srp_rport(
const struct device *dev)
148 return dev->
release == srp_rport_release;
157 if (!scsi_is_srp_rport(dev))
160 shost = dev_to_shost(dev->
parent);
163 if (shost->
transportt->host_attrs.ac.class != &srp_host_class.class)
178 shost = dev_to_shost(dev);
181 if (shost->
transportt->host_attrs.ac.class != &srp_host_class.class)
185 return &i->
t.host_attrs.ac ==
cont;
209 rport->
dev.release = srp_rport_release;
228 ret = srp_tgt_it_nexus_create(shost, (
unsigned long)rport,
258 srp_tgt_it_nexus_destroy(shost, (
unsigned long)rport);
267 static int do_srp_rport_del(
struct device *dev,
void *
data)
269 if (scsi_is_srp_rport(dev))
291 return i->
f->tsk_mgmt_response(shost, nexus, tm_id, result);
294 static int srp_it_nexus_response(
struct Scsi_Host *shost,
u64 nexus,
int result)
297 return i->
f->it_nexus_response(shost, nexus, result);
314 i->
t.tsk_mgmt_response = srp_tsk_mgmt_response;
315 i->
t.it_nexus_response = srp_it_nexus_response;
319 i->
t.host_attrs.ac.class = &srp_host_class.class;
320 i->
t.host_attrs.ac.match = srp_host_match;
322 transport_container_register(&i->
t.host_attrs);
348 transport_container_unregister(&i->
t.host_attrs);
355 static __init int srp_transport_init(
void)
364 goto unregister_host_class;
367 unregister_host_class:
372 static void __exit srp_transport_exit(
void)