zfcp_scsi.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /*
  2. * zfcp device driver
  3. *
  4. * Interface to Linux SCSI midlayer.
  5. *
  6. * Copyright IBM Corporation 2002, 2009
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/types.h>
  11. #include <scsi/fc/fc_fcp.h>
  12. #include <asm/atomic.h>
  13. #include "zfcp_ext.h"
  14. #include "zfcp_dbf.h"
  15. #include "zfcp_fc.h"
  16. static unsigned int default_depth = 32;
  17. module_param_named(queue_depth, default_depth, uint, 0600);
  18. MODULE_PARM_DESC(queue_depth, "Default queue depth for new SCSI devices");
  19. static int zfcp_scsi_change_queue_depth(struct scsi_device *sdev, int depth,
  20. int reason)
  21. {
  22. switch (reason) {
  23. case SCSI_QDEPTH_DEFAULT:
  24. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
  25. break;
  26. case SCSI_QDEPTH_QFULL:
  27. scsi_track_queue_full(sdev, depth);
  28. break;
  29. case SCSI_QDEPTH_RAMP_UP:
  30. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
  31. break;
  32. default:
  33. return -EOPNOTSUPP;
  34. }
  35. return sdev->queue_depth;
  36. }
  37. static void zfcp_scsi_slave_destroy(struct scsi_device *sdpnt)
  38. {
  39. struct zfcp_unit *unit = (struct zfcp_unit *) sdpnt->hostdata;
  40. unit->device = NULL;
  41. put_device(&unit->sysfs_device);
  42. }
  43. static int zfcp_scsi_slave_configure(struct scsi_device *sdp)
  44. {
  45. if (sdp->tagged_supported)
  46. scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, default_depth);
  47. else
  48. scsi_adjust_queue_depth(sdp, 0, 1);
  49. return 0;
  50. }
  51. static void zfcp_scsi_command_fail(struct scsi_cmnd *scpnt, int result)
  52. {
  53. struct zfcp_adapter *adapter =
  54. (struct zfcp_adapter *) scpnt->device->host->hostdata[0];
  55. set_host_byte(scpnt, result);
  56. if ((scpnt->device != NULL) && (scpnt->device->host != NULL))
  57. zfcp_dbf_scsi_result("fail", 4, adapter->dbf, scpnt, NULL);
  58. /* return directly */
  59. scpnt->scsi_done(scpnt);
  60. }
  61. static int zfcp_scsi_queuecommand(struct scsi_cmnd *scpnt,
  62. void (*done) (struct scsi_cmnd *))
  63. {
  64. struct zfcp_unit *unit;
  65. struct zfcp_adapter *adapter;
  66. int status, scsi_result, ret;
  67. struct fc_rport *rport = starget_to_rport(scsi_target(scpnt->device));
  68. /* reset the status for this request */
  69. scpnt->result = 0;
  70. scpnt->host_scribble = NULL;
  71. scpnt->scsi_done = done;
  72. /*
  73. * figure out adapter and target device
  74. * (stored there by zfcp_scsi_slave_alloc)
  75. */
  76. adapter = (struct zfcp_adapter *) scpnt->device->host->hostdata[0];
  77. unit = scpnt->device->hostdata;
  78. BUG_ON(!adapter || (adapter != unit->port->adapter));
  79. BUG_ON(!scpnt->scsi_done);
  80. if (unlikely(!unit)) {
  81. zfcp_scsi_command_fail(scpnt, DID_NO_CONNECT);
  82. return 0;
  83. }
  84. scsi_result = fc_remote_port_chkready(rport);
  85. if (unlikely(scsi_result)) {
  86. scpnt->result = scsi_result;
  87. zfcp_dbf_scsi_result("fail", 4, adapter->dbf, scpnt, NULL);
  88. scpnt->scsi_done(scpnt);
  89. return 0;
  90. }
  91. status = atomic_read(&unit->status);
  92. if (unlikely(status & ZFCP_STATUS_COMMON_ERP_FAILED) &&
  93. !(atomic_read(&unit->port->status) &
  94. ZFCP_STATUS_COMMON_ERP_FAILED)) {
  95. /* only unit access denied, but port is good
  96. * not covered by FC transport, have to fail here */
  97. zfcp_scsi_command_fail(scpnt, DID_ERROR);
  98. return 0;
  99. }
  100. if (unlikely(!(status & ZFCP_STATUS_COMMON_UNBLOCKED))) {
  101. /* This could be either
  102. * open unit pending: this is temporary, will result in
  103. * open unit or ERP_FAILED, so retry command
  104. * call to rport_delete pending: mimic retry from
  105. * fc_remote_port_chkready until rport is BLOCKED
  106. */
  107. zfcp_scsi_command_fail(scpnt, DID_IMM_RETRY);
  108. return 0;
  109. }
  110. ret = zfcp_fsf_send_fcp_command_task(unit, scpnt);
  111. if (unlikely(ret == -EBUSY))
  112. return SCSI_MLQUEUE_DEVICE_BUSY;
  113. else if (unlikely(ret < 0))
  114. return SCSI_MLQUEUE_HOST_BUSY;
  115. return ret;
  116. }
  117. static struct zfcp_unit *zfcp_unit_lookup(struct zfcp_adapter *adapter,
  118. unsigned int id, u64 lun)
  119. {
  120. unsigned long flags;
  121. struct zfcp_port *port;
  122. struct zfcp_unit *unit = NULL;
  123. read_lock_irqsave(&adapter->port_list_lock, flags);
  124. list_for_each_entry(port, &adapter->port_list, list) {
  125. if (!port->rport || (id != port->rport->scsi_target_id))
  126. continue;
  127. unit = zfcp_get_unit_by_lun(port, lun);
  128. if (unit)
  129. break;
  130. }
  131. read_unlock_irqrestore(&adapter->port_list_lock, flags);
  132. return unit;
  133. }
  134. static int zfcp_scsi_slave_alloc(struct scsi_device *sdp)
  135. {
  136. struct zfcp_adapter *adapter;
  137. struct zfcp_unit *unit;
  138. u64 lun;
  139. adapter = (struct zfcp_adapter *) sdp->host->hostdata[0];
  140. if (!adapter)
  141. goto out;
  142. int_to_scsilun(sdp->lun, (struct scsi_lun *)&lun);
  143. unit = zfcp_unit_lookup(adapter, sdp->id, lun);
  144. if (unit) {
  145. sdp->hostdata = unit;
  146. unit->device = sdp;
  147. return 0;
  148. }
  149. out:
  150. return -ENXIO;
  151. }
  152. static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt)
  153. {
  154. struct Scsi_Host *scsi_host = scpnt->device->host;
  155. struct zfcp_adapter *adapter =
  156. (struct zfcp_adapter *) scsi_host->hostdata[0];
  157. struct zfcp_unit *unit = scpnt->device->hostdata;
  158. struct zfcp_fsf_req *old_req, *abrt_req;
  159. unsigned long flags;
  160. unsigned long old_reqid = (unsigned long) scpnt->host_scribble;
  161. int retval = SUCCESS;
  162. int retry = 3;
  163. char *dbf_tag;
  164. /* avoid race condition between late normal completion and abort */
  165. write_lock_irqsave(&adapter->abort_lock, flags);
  166. spin_lock(&adapter->req_list_lock);
  167. old_req = zfcp_reqlist_find(adapter, old_reqid);
  168. spin_unlock(&adapter->req_list_lock);
  169. if (!old_req) {
  170. write_unlock_irqrestore(&adapter->abort_lock, flags);
  171. zfcp_dbf_scsi_abort("lte1", adapter->dbf, scpnt, NULL,
  172. old_reqid);
  173. return FAILED; /* completion could be in progress */
  174. }
  175. old_req->data = NULL;
  176. /* don't access old fsf_req after releasing the abort_lock */
  177. write_unlock_irqrestore(&adapter->abort_lock, flags);
  178. while (retry--) {
  179. abrt_req = zfcp_fsf_abort_fcp_command(old_reqid, unit);
  180. if (abrt_req)
  181. break;
  182. zfcp_erp_wait(adapter);
  183. fc_block_scsi_eh(scpnt);
  184. if (!(atomic_read(&adapter->status) &
  185. ZFCP_STATUS_COMMON_RUNNING)) {
  186. zfcp_dbf_scsi_abort("nres", adapter->dbf, scpnt, NULL,
  187. old_reqid);
  188. return SUCCESS;
  189. }
  190. }
  191. if (!abrt_req)
  192. return FAILED;
  193. wait_for_completion(&abrt_req->completion);
  194. if (abrt_req->status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED)
  195. dbf_tag = "okay";
  196. else if (abrt_req->status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED)
  197. dbf_tag = "lte2";
  198. else {
  199. dbf_tag = "fail";
  200. retval = FAILED;
  201. }
  202. zfcp_dbf_scsi_abort(dbf_tag, adapter->dbf, scpnt, abrt_req, old_reqid);
  203. zfcp_fsf_req_free(abrt_req);
  204. return retval;
  205. }
  206. static int zfcp_task_mgmt_function(struct scsi_cmnd *scpnt, u8 tm_flags)
  207. {
  208. struct zfcp_unit *unit = scpnt->device->hostdata;
  209. struct zfcp_adapter *adapter = unit->port->adapter;
  210. struct zfcp_fsf_req *fsf_req = NULL;
  211. int retval = SUCCESS;
  212. int retry = 3;
  213. while (retry--) {
  214. fsf_req = zfcp_fsf_send_fcp_ctm(unit, tm_flags);
  215. if (fsf_req)
  216. break;
  217. zfcp_erp_wait(adapter);
  218. fc_block_scsi_eh(scpnt);
  219. if (!(atomic_read(&adapter->status) &
  220. ZFCP_STATUS_COMMON_RUNNING)) {
  221. zfcp_dbf_scsi_devreset("nres", tm_flags, unit, scpnt);
  222. return SUCCESS;
  223. }
  224. }
  225. if (!fsf_req)
  226. return FAILED;
  227. wait_for_completion(&fsf_req->completion);
  228. if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED) {
  229. zfcp_dbf_scsi_devreset("fail", tm_flags, unit, scpnt);
  230. retval = FAILED;
  231. } else
  232. zfcp_dbf_scsi_devreset("okay", tm_flags, unit, scpnt);
  233. zfcp_fsf_req_free(fsf_req);
  234. return retval;
  235. }
  236. static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt)
  237. {
  238. return zfcp_task_mgmt_function(scpnt, FCP_TMF_LUN_RESET);
  239. }
  240. static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd *scpnt)
  241. {
  242. return zfcp_task_mgmt_function(scpnt, FCP_TMF_TGT_RESET);
  243. }
  244. static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt)
  245. {
  246. struct zfcp_unit *unit = scpnt->device->hostdata;
  247. struct zfcp_adapter *adapter = unit->port->adapter;
  248. zfcp_erp_adapter_reopen(adapter, 0, "schrh_1", scpnt);
  249. zfcp_erp_wait(adapter);
  250. fc_block_scsi_eh(scpnt);
  251. return SUCCESS;
  252. }
  253. int zfcp_adapter_scsi_register(struct zfcp_adapter *adapter)
  254. {
  255. struct ccw_dev_id dev_id;
  256. if (adapter->scsi_host)
  257. return 0;
  258. ccw_device_get_id(adapter->ccw_device, &dev_id);
  259. /* register adapter as SCSI host with mid layer of SCSI stack */
  260. adapter->scsi_host = scsi_host_alloc(&zfcp_data.scsi_host_template,
  261. sizeof (struct zfcp_adapter *));
  262. if (!adapter->scsi_host) {
  263. dev_err(&adapter->ccw_device->dev,
  264. "Registering the FCP device with the "
  265. "SCSI stack failed\n");
  266. return -EIO;
  267. }
  268. /* tell the SCSI stack some characteristics of this adapter */
  269. adapter->scsi_host->max_id = 1;
  270. adapter->scsi_host->max_lun = 1;
  271. adapter->scsi_host->max_channel = 0;
  272. adapter->scsi_host->unique_id = dev_id.devno;
  273. adapter->scsi_host->max_cmd_len = 16; /* in struct fcp_cmnd */
  274. adapter->scsi_host->transportt = zfcp_data.scsi_transport_template;
  275. adapter->scsi_host->hostdata[0] = (unsigned long) adapter;
  276. if (scsi_add_host(adapter->scsi_host, &adapter->ccw_device->dev)) {
  277. scsi_host_put(adapter->scsi_host);
  278. return -EIO;
  279. }
  280. return 0;
  281. }
  282. void zfcp_adapter_scsi_unregister(struct zfcp_adapter *adapter)
  283. {
  284. struct Scsi_Host *shost;
  285. struct zfcp_port *port;
  286. shost = adapter->scsi_host;
  287. if (!shost)
  288. return;
  289. read_lock_irq(&adapter->port_list_lock);
  290. list_for_each_entry(port, &adapter->port_list, list)
  291. port->rport = NULL;
  292. read_unlock_irq(&adapter->port_list_lock);
  293. fc_remove_host(shost);
  294. scsi_remove_host(shost);
  295. scsi_host_put(shost);
  296. adapter->scsi_host = NULL;
  297. return;
  298. }
  299. static struct fc_host_statistics*
  300. zfcp_init_fc_host_stats(struct zfcp_adapter *adapter)
  301. {
  302. struct fc_host_statistics *fc_stats;
  303. if (!adapter->fc_stats) {
  304. fc_stats = kmalloc(sizeof(*fc_stats), GFP_KERNEL);
  305. if (!fc_stats)
  306. return NULL;
  307. adapter->fc_stats = fc_stats; /* freed in adapter_release */
  308. }
  309. memset(adapter->fc_stats, 0, sizeof(*adapter->fc_stats));
  310. return adapter->fc_stats;
  311. }
  312. static void zfcp_adjust_fc_host_stats(struct fc_host_statistics *fc_stats,
  313. struct fsf_qtcb_bottom_port *data,
  314. struct fsf_qtcb_bottom_port *old)
  315. {
  316. fc_stats->seconds_since_last_reset =
  317. data->seconds_since_last_reset - old->seconds_since_last_reset;
  318. fc_stats->tx_frames = data->tx_frames - old->tx_frames;
  319. fc_stats->tx_words = data->tx_words - old->tx_words;
  320. fc_stats->rx_frames = data->rx_frames - old->rx_frames;
  321. fc_stats->rx_words = data->rx_words - old->rx_words;
  322. fc_stats->lip_count = data->lip - old->lip;
  323. fc_stats->nos_count = data->nos - old->nos;
  324. fc_stats->error_frames = data->error_frames - old->error_frames;
  325. fc_stats->dumped_frames = data->dumped_frames - old->dumped_frames;
  326. fc_stats->link_failure_count = data->link_failure - old->link_failure;
  327. fc_stats->loss_of_sync_count = data->loss_of_sync - old->loss_of_sync;
  328. fc_stats->loss_of_signal_count =
  329. data->loss_of_signal - old->loss_of_signal;
  330. fc_stats->prim_seq_protocol_err_count =
  331. data->psp_error_counts - old->psp_error_counts;
  332. fc_stats->invalid_tx_word_count =
  333. data->invalid_tx_words - old->invalid_tx_words;
  334. fc_stats->invalid_crc_count = data->invalid_crcs - old->invalid_crcs;
  335. fc_stats->fcp_input_requests =
  336. data->input_requests - old->input_requests;
  337. fc_stats->fcp_output_requests =
  338. data->output_requests - old->output_requests;
  339. fc_stats->fcp_control_requests =
  340. data->control_requests - old->control_requests;
  341. fc_stats->fcp_input_megabytes = data->input_mb - old->input_mb;
  342. fc_stats->fcp_output_megabytes = data->output_mb - old->output_mb;
  343. }
  344. static void zfcp_set_fc_host_stats(struct fc_host_statistics *fc_stats,
  345. struct fsf_qtcb_bottom_port *data)
  346. {
  347. fc_stats->seconds_since_last_reset = data->seconds_since_last_reset;
  348. fc_stats->tx_frames = data->tx_frames;
  349. fc_stats->tx_words = data->tx_words;
  350. fc_stats->rx_frames = data->rx_frames;
  351. fc_stats->rx_words = data->rx_words;
  352. fc_stats->lip_count = data->lip;
  353. fc_stats->nos_count = data->nos;
  354. fc_stats->error_frames = data->error_frames;
  355. fc_stats->dumped_frames = data->dumped_frames;
  356. fc_stats->link_failure_count = data->link_failure;
  357. fc_stats->loss_of_sync_count = data->loss_of_sync;
  358. fc_stats->loss_of_signal_count = data->loss_of_signal;
  359. fc_stats->prim_seq_protocol_err_count = data->psp_error_counts;
  360. fc_stats->invalid_tx_word_count = data->invalid_tx_words;
  361. fc_stats->invalid_crc_count = data->invalid_crcs;
  362. fc_stats->fcp_input_requests = data->input_requests;
  363. fc_stats->fcp_output_requests = data->output_requests;
  364. fc_stats->fcp_control_requests = data->control_requests;
  365. fc_stats->fcp_input_megabytes = data->input_mb;
  366. fc_stats->fcp_output_megabytes = data->output_mb;
  367. }
  368. static struct fc_host_statistics *zfcp_get_fc_host_stats(struct Scsi_Host *host)
  369. {
  370. struct zfcp_adapter *adapter;
  371. struct fc_host_statistics *fc_stats;
  372. struct fsf_qtcb_bottom_port *data;
  373. int ret;
  374. adapter = (struct zfcp_adapter *)host->hostdata[0];
  375. fc_stats = zfcp_init_fc_host_stats(adapter);
  376. if (!fc_stats)
  377. return NULL;
  378. data = kzalloc(sizeof(*data), GFP_KERNEL);
  379. if (!data)
  380. return NULL;
  381. ret = zfcp_fsf_exchange_port_data_sync(adapter->qdio, data);
  382. if (ret) {
  383. kfree(data);
  384. return NULL;
  385. }
  386. if (adapter->stats_reset &&
  387. ((jiffies/HZ - adapter->stats_reset) <
  388. data->seconds_since_last_reset))
  389. zfcp_adjust_fc_host_stats(fc_stats, data,
  390. adapter->stats_reset_data);
  391. else
  392. zfcp_set_fc_host_stats(fc_stats, data);
  393. kfree(data);
  394. return fc_stats;
  395. }
  396. static void zfcp_reset_fc_host_stats(struct Scsi_Host *shost)
  397. {
  398. struct zfcp_adapter *adapter;
  399. struct fsf_qtcb_bottom_port *data;
  400. int ret;
  401. adapter = (struct zfcp_adapter *)shost->hostdata[0];
  402. data = kzalloc(sizeof(*data), GFP_KERNEL);
  403. if (!data)
  404. return;
  405. ret = zfcp_fsf_exchange_port_data_sync(adapter->qdio, data);
  406. if (ret)
  407. kfree(data);
  408. else {
  409. adapter->stats_reset = jiffies/HZ;
  410. kfree(adapter->stats_reset_data);
  411. adapter->stats_reset_data = data; /* finally freed in
  412. adapter_release */
  413. }
  414. }
  415. static void zfcp_get_host_port_state(struct Scsi_Host *shost)
  416. {
  417. struct zfcp_adapter *adapter =
  418. (struct zfcp_adapter *)shost->hostdata[0];
  419. int status = atomic_read(&adapter->status);
  420. if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
  421. !(status & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED))
  422. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  423. else if (status & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  424. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  425. else if (status & ZFCP_STATUS_COMMON_ERP_FAILED)
  426. fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
  427. else
  428. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  429. }
  430. static void zfcp_set_rport_dev_loss_tmo(struct fc_rport *rport, u32 timeout)
  431. {
  432. rport->dev_loss_tmo = timeout;
  433. }
  434. /**
  435. * zfcp_scsi_terminate_rport_io - Terminate all I/O on a rport
  436. * @rport: The FC rport where to teminate I/O
  437. *
  438. * Abort all pending SCSI commands for a port by closing the
  439. * port. Using a reopen avoiding a conflict with a shutdown
  440. * overwriting a reopen.
  441. */
  442. static void zfcp_scsi_terminate_rport_io(struct fc_rport *rport)
  443. {
  444. struct zfcp_port *port;
  445. struct Scsi_Host *shost = rport_to_shost(rport);
  446. struct zfcp_adapter *adapter =
  447. (struct zfcp_adapter *)shost->hostdata[0];
  448. port = zfcp_get_port_by_wwpn(adapter, rport->port_name);
  449. if (port) {
  450. zfcp_erp_port_reopen(port, 0, "sctrpi1", NULL);
  451. put_device(&port->sysfs_device);
  452. }
  453. }
  454. static void zfcp_scsi_rport_register(struct zfcp_port *port)
  455. {
  456. struct fc_rport_identifiers ids;
  457. struct fc_rport *rport;
  458. if (port->rport)
  459. return;
  460. ids.node_name = port->wwnn;
  461. ids.port_name = port->wwpn;
  462. ids.port_id = port->d_id;
  463. ids.roles = FC_RPORT_ROLE_FCP_TARGET;
  464. rport = fc_remote_port_add(port->adapter->scsi_host, 0, &ids);
  465. if (!rport) {
  466. dev_err(&port->adapter->ccw_device->dev,
  467. "Registering port 0x%016Lx failed\n",
  468. (unsigned long long)port->wwpn);
  469. return;
  470. }
  471. rport->maxframe_size = port->maxframe_size;
  472. rport->supported_classes = port->supported_classes;
  473. port->rport = rport;
  474. }
  475. static void zfcp_scsi_rport_block(struct zfcp_port *port)
  476. {
  477. struct fc_rport *rport = port->rport;
  478. if (rport) {
  479. fc_remote_port_delete(rport);
  480. port->rport = NULL;
  481. }
  482. }
  483. void zfcp_scsi_schedule_rport_register(struct zfcp_port *port)
  484. {
  485. get_device(&port->sysfs_device);
  486. port->rport_task = RPORT_ADD;
  487. if (!queue_work(port->adapter->work_queue, &port->rport_work))
  488. put_device(&port->sysfs_device);
  489. }
  490. void zfcp_scsi_schedule_rport_block(struct zfcp_port *port)
  491. {
  492. get_device(&port->sysfs_device);
  493. port->rport_task = RPORT_DEL;
  494. if (port->rport && queue_work(port->adapter->work_queue,
  495. &port->rport_work))
  496. return;
  497. put_device(&port->sysfs_device);
  498. }
  499. void zfcp_scsi_schedule_rports_block(struct zfcp_adapter *adapter)
  500. {
  501. unsigned long flags;
  502. struct zfcp_port *port;
  503. read_lock_irqsave(&adapter->port_list_lock, flags);
  504. list_for_each_entry(port, &adapter->port_list, list)
  505. zfcp_scsi_schedule_rport_block(port);
  506. read_unlock_irqrestore(&adapter->port_list_lock, flags);
  507. }
  508. void zfcp_scsi_rport_work(struct work_struct *work)
  509. {
  510. struct zfcp_port *port = container_of(work, struct zfcp_port,
  511. rport_work);
  512. while (port->rport_task) {
  513. if (port->rport_task == RPORT_ADD) {
  514. port->rport_task = RPORT_NONE;
  515. zfcp_scsi_rport_register(port);
  516. } else {
  517. port->rport_task = RPORT_NONE;
  518. zfcp_scsi_rport_block(port);
  519. }
  520. }
  521. put_device(&port->sysfs_device);
  522. }
  523. void zfcp_scsi_scan(struct work_struct *work)
  524. {
  525. struct zfcp_unit *unit = container_of(work, struct zfcp_unit,
  526. scsi_work);
  527. struct fc_rport *rport;
  528. flush_work(&unit->port->rport_work);
  529. rport = unit->port->rport;
  530. if (rport && rport->port_state == FC_PORTSTATE_ONLINE)
  531. scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
  532. scsilun_to_int((struct scsi_lun *)
  533. &unit->fcp_lun), 0);
  534. put_device(&unit->sysfs_device);
  535. }
  536. struct fc_function_template zfcp_transport_functions = {
  537. .show_starget_port_id = 1,
  538. .show_starget_port_name = 1,
  539. .show_starget_node_name = 1,
  540. .show_rport_supported_classes = 1,
  541. .show_rport_maxframe_size = 1,
  542. .show_rport_dev_loss_tmo = 1,
  543. .show_host_node_name = 1,
  544. .show_host_port_name = 1,
  545. .show_host_permanent_port_name = 1,
  546. .show_host_supported_classes = 1,
  547. .show_host_supported_fc4s = 1,
  548. .show_host_supported_speeds = 1,
  549. .show_host_maxframe_size = 1,
  550. .show_host_serial_number = 1,
  551. .get_fc_host_stats = zfcp_get_fc_host_stats,
  552. .reset_fc_host_stats = zfcp_reset_fc_host_stats,
  553. .set_rport_dev_loss_tmo = zfcp_set_rport_dev_loss_tmo,
  554. .get_host_port_state = zfcp_get_host_port_state,
  555. .terminate_rport_io = zfcp_scsi_terminate_rport_io,
  556. .show_host_port_state = 1,
  557. .show_host_active_fc4s = 1,
  558. .bsg_request = zfcp_fc_exec_bsg_job,
  559. /* no functions registered for following dynamic attributes but
  560. directly set by LLDD */
  561. .show_host_port_type = 1,
  562. .show_host_speed = 1,
  563. .show_host_port_id = 1,
  564. .disable_target_scan = 1,
  565. .dd_bsg_size = sizeof(struct zfcp_fsf_ct_els),
  566. };
  567. struct zfcp_data zfcp_data = {
  568. .scsi_host_template = {
  569. .name = "zfcp",
  570. .module = THIS_MODULE,
  571. .proc_name = "zfcp",
  572. .change_queue_depth = zfcp_scsi_change_queue_depth,
  573. .slave_alloc = zfcp_scsi_slave_alloc,
  574. .slave_configure = zfcp_scsi_slave_configure,
  575. .slave_destroy = zfcp_scsi_slave_destroy,
  576. .queuecommand = zfcp_scsi_queuecommand,
  577. .eh_abort_handler = zfcp_scsi_eh_abort_handler,
  578. .eh_device_reset_handler = zfcp_scsi_eh_device_reset_handler,
  579. .eh_target_reset_handler = zfcp_scsi_eh_target_reset_handler,
  580. .eh_host_reset_handler = zfcp_scsi_eh_host_reset_handler,
  581. .can_queue = 4096,
  582. .this_id = -1,
  583. .sg_tablesize = ZFCP_MAX_SBALES_PER_REQ,
  584. .cmd_per_lun = 1,
  585. .use_clustering = 1,
  586. .sdev_attrs = zfcp_sysfs_sdev_attrs,
  587. .max_sectors = (ZFCP_MAX_SBALES_PER_REQ * 8),
  588. .shost_attrs = zfcp_sysfs_shost_attrs,
  589. },
  590. };