1 /* 2 * zfcp device driver 3 * 4 * Registration and callback for the s390 common I/O layer. 5 * 6 * Copyright IBM Corporation 2002, 2009 7 */ 8 9 #define KMSG_COMPONENT "zfcp" 10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 11 12 #include "zfcp_ext.h" 13 14 /** 15 * zfcp_ccw_probe - probe function of zfcp driver 16 * @ccw_device: pointer to belonging ccw device 17 * 18 * This function gets called by the common i/o layer and sets up the initial 19 * data structures for each fcp adapter, which was detected by the system. 20 * Also the sysfs files for this adapter will be created by this function. 21 * In addition the nameserver port will be added to the ports of the adapter 22 * and its sysfs representation will be created too. 23 */ 24 static int zfcp_ccw_probe(struct ccw_device *ccw_device) 25 { 26 int retval = 0; 27 28 down(&zfcp_data.config_sema); 29 if (zfcp_adapter_enqueue(ccw_device)) { 30 dev_err(&ccw_device->dev, 31 "Setting up data structures for the " 32 "FCP adapter failed\n"); 33 retval = -EINVAL; 34 } 35 up(&zfcp_data.config_sema); 36 return retval; 37 } 38 39 /** 40 * zfcp_ccw_remove - remove function of zfcp driver 41 * @ccw_device: pointer to belonging ccw device 42 * 43 * This function gets called by the common i/o layer and removes an adapter 44 * from the system. Task of this function is to get rid of all units and 45 * ports that belong to this adapter. And in addition all resources of this 46 * adapter will be freed too. 47 */ 48 static void zfcp_ccw_remove(struct ccw_device *ccw_device) 49 { 50 struct zfcp_adapter *adapter; 51 struct zfcp_port *port, *p; 52 struct zfcp_unit *unit, *u; 53 LIST_HEAD(unit_remove_lh); 54 LIST_HEAD(port_remove_lh); 55 56 ccw_device_set_offline(ccw_device); 57 down(&zfcp_data.config_sema); 58 adapter = dev_get_drvdata(&ccw_device->dev); 59 60 write_lock_irq(&zfcp_data.config_lock); 61 list_for_each_entry_safe(port, p, &adapter->port_list_head, list) { 62 list_for_each_entry_safe(unit, u, &port->unit_list_head, list) { 63 list_move(&unit->list, &unit_remove_lh); 64 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, 65 &unit->status); 66 } 67 list_move(&port->list, &port_remove_lh); 68 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status); 69 } 70 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status); 71 write_unlock_irq(&zfcp_data.config_lock); 72 73 list_for_each_entry_safe(port, p, &port_remove_lh, list) { 74 list_for_each_entry_safe(unit, u, &unit_remove_lh, list) { 75 if (unit->device) 76 scsi_remove_device(unit->device); 77 zfcp_unit_dequeue(unit); 78 } 79 zfcp_port_dequeue(port); 80 } 81 wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0); 82 zfcp_adapter_dequeue(adapter); 83 84 up(&zfcp_data.config_sema); 85 } 86 87 /** 88 * zfcp_ccw_set_online - set_online function of zfcp driver 89 * @ccw_device: pointer to belonging ccw device 90 * 91 * This function gets called by the common i/o layer and sets an adapter 92 * into state online. Setting an fcp device online means that it will be 93 * registered with the SCSI stack, that the QDIO queues will be set up 94 * and that the adapter will be opened (asynchronously). 95 */ 96 static int zfcp_ccw_set_online(struct ccw_device *ccw_device) 97 { 98 struct zfcp_adapter *adapter; 99 int retval; 100 101 down(&zfcp_data.config_sema); 102 adapter = dev_get_drvdata(&ccw_device->dev); 103 104 retval = zfcp_erp_thread_setup(adapter); 105 if (retval) 106 goto out; 107 108 /* initialize request counter */ 109 BUG_ON(!zfcp_reqlist_isempty(adapter)); 110 adapter->req_no = 0; 111 zfcp_fc_nameserver_init(adapter); 112 113 zfcp_erp_modify_adapter_status(adapter, "ccsonl1", NULL, 114 ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET); 115 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 116 "ccsonl2", NULL); 117 zfcp_erp_wait(adapter); 118 up(&zfcp_data.config_sema); 119 flush_work(&adapter->scan_work); 120 return 0; 121 122 out: 123 up(&zfcp_data.config_sema); 124 return retval; 125 } 126 127 /** 128 * zfcp_ccw_set_offline - set_offline function of zfcp driver 129 * @ccw_device: pointer to belonging ccw device 130 * 131 * This function gets called by the common i/o layer and sets an adapter 132 * into state offline. 133 */ 134 static int zfcp_ccw_set_offline(struct ccw_device *ccw_device) 135 { 136 struct zfcp_adapter *adapter; 137 138 down(&zfcp_data.config_sema); 139 adapter = dev_get_drvdata(&ccw_device->dev); 140 zfcp_erp_adapter_shutdown(adapter, 0, "ccsoff1", NULL); 141 zfcp_erp_wait(adapter); 142 zfcp_erp_thread_kill(adapter); 143 up(&zfcp_data.config_sema); 144 return 0; 145 } 146 147 /** 148 * zfcp_ccw_notify - ccw notify function 149 * @ccw_device: pointer to belonging ccw device 150 * @event: indicates if adapter was detached or attached 151 * 152 * This function gets called by the common i/o layer if an adapter has gone 153 * or reappeared. 154 */ 155 static int zfcp_ccw_notify(struct ccw_device *ccw_device, int event) 156 { 157 struct zfcp_adapter *adapter = dev_get_drvdata(&ccw_device->dev); 158 159 switch (event) { 160 case CIO_GONE: 161 dev_warn(&adapter->ccw_device->dev, 162 "The FCP device has been detached\n"); 163 zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti1", NULL); 164 break; 165 case CIO_NO_PATH: 166 dev_warn(&adapter->ccw_device->dev, 167 "The CHPID for the FCP device is offline\n"); 168 zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti2", NULL); 169 break; 170 case CIO_OPER: 171 dev_info(&adapter->ccw_device->dev, 172 "The FCP device is operational again\n"); 173 zfcp_erp_modify_adapter_status(adapter, "ccnoti3", NULL, 174 ZFCP_STATUS_COMMON_RUNNING, 175 ZFCP_SET); 176 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 177 "ccnoti4", NULL); 178 break; 179 case CIO_BOXED: 180 dev_warn(&adapter->ccw_device->dev, 181 "The ccw device did not respond in time.\n"); 182 zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti5", NULL); 183 break; 184 } 185 return 1; 186 } 187 188 /** 189 * zfcp_ccw_shutdown - handle shutdown from cio 190 * @cdev: device for adapter to shutdown. 191 */ 192 static void zfcp_ccw_shutdown(struct ccw_device *cdev) 193 { 194 struct zfcp_adapter *adapter; 195 196 down(&zfcp_data.config_sema); 197 adapter = dev_get_drvdata(&cdev->dev); 198 zfcp_erp_adapter_shutdown(adapter, 0, "ccshut1", NULL); 199 zfcp_erp_wait(adapter); 200 up(&zfcp_data.config_sema); 201 } 202 203 static struct ccw_device_id zfcp_ccw_device_id[] = { 204 { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, 0x3) }, 205 { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, 0x4) }, /* priv. */ 206 {}, 207 }; 208 209 MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id); 210 211 static struct ccw_driver zfcp_ccw_driver = { 212 .owner = THIS_MODULE, 213 .name = "zfcp", 214 .ids = zfcp_ccw_device_id, 215 .probe = zfcp_ccw_probe, 216 .remove = zfcp_ccw_remove, 217 .set_online = zfcp_ccw_set_online, 218 .set_offline = zfcp_ccw_set_offline, 219 .notify = zfcp_ccw_notify, 220 .shutdown = zfcp_ccw_shutdown, 221 }; 222 223 /** 224 * zfcp_ccw_register - ccw register function 225 * 226 * Registers the driver at the common i/o layer. This function will be called 227 * at module load time/system start. 228 */ 229 int __init zfcp_ccw_register(void) 230 { 231 return ccw_driver_register(&zfcp_ccw_driver); 232 } 233 234 /** 235 * zfcp_get_adapter_by_busid - find zfcp_adapter struct 236 * @busid: bus id string of zfcp adapter to find 237 */ 238 struct zfcp_adapter *zfcp_get_adapter_by_busid(char *busid) 239 { 240 struct ccw_device *ccw_device; 241 struct zfcp_adapter *adapter = NULL; 242 243 ccw_device = get_ccwdev_by_busid(&zfcp_ccw_driver, busid); 244 if (ccw_device) { 245 adapter = dev_get_drvdata(&ccw_device->dev); 246 put_device(&ccw_device->dev); 247 } 248 return adapter; 249 } 250