zfcp_scsi.c 19 KB

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