zfcp_scsi.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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;
  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. fc_block_scsi_eh(scpnt);
  176. if (!(atomic_read(&adapter->status) &
  177. ZFCP_STATUS_COMMON_RUNNING)) {
  178. zfcp_dbf_scsi_abort("nres", adapter->dbf, scpnt, NULL,
  179. old_reqid);
  180. return SUCCESS;
  181. }
  182. }
  183. if (!abrt_req)
  184. return FAILED;
  185. wait_for_completion(&abrt_req->completion);
  186. if (abrt_req->status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED)
  187. dbf_tag = "okay";
  188. else if (abrt_req->status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED)
  189. dbf_tag = "lte2";
  190. else {
  191. dbf_tag = "fail";
  192. retval = FAILED;
  193. }
  194. zfcp_dbf_scsi_abort(dbf_tag, adapter->dbf, scpnt, abrt_req, old_reqid);
  195. zfcp_fsf_req_free(abrt_req);
  196. return retval;
  197. }
  198. static int zfcp_task_mgmt_function(struct scsi_cmnd *scpnt, u8 tm_flags)
  199. {
  200. struct zfcp_unit *unit = scpnt->device->hostdata;
  201. struct zfcp_adapter *adapter = unit->port->adapter;
  202. struct zfcp_fsf_req *fsf_req = NULL;
  203. int retval = SUCCESS;
  204. int retry = 3;
  205. while (retry--) {
  206. fsf_req = zfcp_fsf_send_fcp_ctm(unit, tm_flags);
  207. if (fsf_req)
  208. break;
  209. zfcp_erp_wait(adapter);
  210. fc_block_scsi_eh(scpnt);
  211. if (!(atomic_read(&adapter->status) &
  212. ZFCP_STATUS_COMMON_RUNNING)) {
  213. zfcp_dbf_scsi_devreset("nres", tm_flags, unit, scpnt);
  214. return SUCCESS;
  215. }
  216. }
  217. if (!fsf_req)
  218. return FAILED;
  219. wait_for_completion(&fsf_req->completion);
  220. if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED) {
  221. zfcp_dbf_scsi_devreset("fail", tm_flags, unit, scpnt);
  222. retval = FAILED;
  223. } else
  224. zfcp_dbf_scsi_devreset("okay", tm_flags, unit, scpnt);
  225. zfcp_fsf_req_free(fsf_req);
  226. return retval;
  227. }
  228. static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt)
  229. {
  230. return zfcp_task_mgmt_function(scpnt, FCP_TMF_LUN_RESET);
  231. }
  232. static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd *scpnt)
  233. {
  234. return zfcp_task_mgmt_function(scpnt, FCP_TMF_TGT_RESET);
  235. }
  236. static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt)
  237. {
  238. struct zfcp_unit *unit = scpnt->device->hostdata;
  239. struct zfcp_adapter *adapter = unit->port->adapter;
  240. zfcp_erp_adapter_reopen(adapter, 0, "schrh_1", scpnt);
  241. zfcp_erp_wait(adapter);
  242. fc_block_scsi_eh(scpnt);
  243. return SUCCESS;
  244. }
  245. int zfcp_adapter_scsi_register(struct zfcp_adapter *adapter)
  246. {
  247. struct ccw_dev_id dev_id;
  248. if (adapter->scsi_host)
  249. return 0;
  250. ccw_device_get_id(adapter->ccw_device, &dev_id);
  251. /* register adapter as SCSI host with mid layer of SCSI stack */
  252. adapter->scsi_host = scsi_host_alloc(&zfcp_data.scsi_host_template,
  253. sizeof (struct zfcp_adapter *));
  254. if (!adapter->scsi_host) {
  255. dev_err(&adapter->ccw_device->dev,
  256. "Registering the FCP device with the "
  257. "SCSI stack failed\n");
  258. return -EIO;
  259. }
  260. /* tell the SCSI stack some characteristics of this adapter */
  261. adapter->scsi_host->max_id = 1;
  262. adapter->scsi_host->max_lun = 1;
  263. adapter->scsi_host->max_channel = 0;
  264. adapter->scsi_host->unique_id = dev_id.devno;
  265. adapter->scsi_host->max_cmd_len = 16; /* in struct fcp_cmnd */
  266. adapter->scsi_host->transportt = zfcp_data.scsi_transport_template;
  267. adapter->scsi_host->hostdata[0] = (unsigned long) adapter;
  268. if (scsi_add_host(adapter->scsi_host, &adapter->ccw_device->dev)) {
  269. scsi_host_put(adapter->scsi_host);
  270. return -EIO;
  271. }
  272. return 0;
  273. }
  274. void zfcp_adapter_scsi_unregister(struct zfcp_adapter *adapter)
  275. {
  276. struct Scsi_Host *shost;
  277. struct zfcp_port *port;
  278. shost = adapter->scsi_host;
  279. if (!shost)
  280. return;
  281. read_lock_irq(&adapter->port_list_lock);
  282. list_for_each_entry(port, &adapter->port_list, list)
  283. port->rport = NULL;
  284. read_unlock_irq(&adapter->port_list_lock);
  285. fc_remove_host(shost);
  286. scsi_remove_host(shost);
  287. scsi_host_put(shost);
  288. adapter->scsi_host = NULL;
  289. return;
  290. }
  291. static struct fc_host_statistics*
  292. zfcp_init_fc_host_stats(struct zfcp_adapter *adapter)
  293. {
  294. struct fc_host_statistics *fc_stats;
  295. if (!adapter->fc_stats) {
  296. fc_stats = kmalloc(sizeof(*fc_stats), GFP_KERNEL);
  297. if (!fc_stats)
  298. return NULL;
  299. adapter->fc_stats = fc_stats; /* freed in adapter_release */
  300. }
  301. memset(adapter->fc_stats, 0, sizeof(*adapter->fc_stats));
  302. return adapter->fc_stats;
  303. }
  304. static void zfcp_adjust_fc_host_stats(struct fc_host_statistics *fc_stats,
  305. struct fsf_qtcb_bottom_port *data,
  306. struct fsf_qtcb_bottom_port *old)
  307. {
  308. fc_stats->seconds_since_last_reset =
  309. data->seconds_since_last_reset - old->seconds_since_last_reset;
  310. fc_stats->tx_frames = data->tx_frames - old->tx_frames;
  311. fc_stats->tx_words = data->tx_words - old->tx_words;
  312. fc_stats->rx_frames = data->rx_frames - old->rx_frames;
  313. fc_stats->rx_words = data->rx_words - old->rx_words;
  314. fc_stats->lip_count = data->lip - old->lip;
  315. fc_stats->nos_count = data->nos - old->nos;
  316. fc_stats->error_frames = data->error_frames - old->error_frames;
  317. fc_stats->dumped_frames = data->dumped_frames - old->dumped_frames;
  318. fc_stats->link_failure_count = data->link_failure - old->link_failure;
  319. fc_stats->loss_of_sync_count = data->loss_of_sync - old->loss_of_sync;
  320. fc_stats->loss_of_signal_count =
  321. data->loss_of_signal - old->loss_of_signal;
  322. fc_stats->prim_seq_protocol_err_count =
  323. data->psp_error_counts - old->psp_error_counts;
  324. fc_stats->invalid_tx_word_count =
  325. data->invalid_tx_words - old->invalid_tx_words;
  326. fc_stats->invalid_crc_count = data->invalid_crcs - old->invalid_crcs;
  327. fc_stats->fcp_input_requests =
  328. data->input_requests - old->input_requests;
  329. fc_stats->fcp_output_requests =
  330. data->output_requests - old->output_requests;
  331. fc_stats->fcp_control_requests =
  332. data->control_requests - old->control_requests;
  333. fc_stats->fcp_input_megabytes = data->input_mb - old->input_mb;
  334. fc_stats->fcp_output_megabytes = data->output_mb - old->output_mb;
  335. }
  336. static void zfcp_set_fc_host_stats(struct fc_host_statistics *fc_stats,
  337. struct fsf_qtcb_bottom_port *data)
  338. {
  339. fc_stats->seconds_since_last_reset = data->seconds_since_last_reset;
  340. fc_stats->tx_frames = data->tx_frames;
  341. fc_stats->tx_words = data->tx_words;
  342. fc_stats->rx_frames = data->rx_frames;
  343. fc_stats->rx_words = data->rx_words;
  344. fc_stats->lip_count = data->lip;
  345. fc_stats->nos_count = data->nos;
  346. fc_stats->error_frames = data->error_frames;
  347. fc_stats->dumped_frames = data->dumped_frames;
  348. fc_stats->link_failure_count = data->link_failure;
  349. fc_stats->loss_of_sync_count = data->loss_of_sync;
  350. fc_stats->loss_of_signal_count = data->loss_of_signal;
  351. fc_stats->prim_seq_protocol_err_count = data->psp_error_counts;
  352. fc_stats->invalid_tx_word_count = data->invalid_tx_words;
  353. fc_stats->invalid_crc_count = data->invalid_crcs;
  354. fc_stats->fcp_input_requests = data->input_requests;
  355. fc_stats->fcp_output_requests = data->output_requests;
  356. fc_stats->fcp_control_requests = data->control_requests;
  357. fc_stats->fcp_input_megabytes = data->input_mb;
  358. fc_stats->fcp_output_megabytes = data->output_mb;
  359. }
  360. static struct fc_host_statistics *zfcp_get_fc_host_stats(struct Scsi_Host *host)
  361. {
  362. struct zfcp_adapter *adapter;
  363. struct fc_host_statistics *fc_stats;
  364. struct fsf_qtcb_bottom_port *data;
  365. int ret;
  366. adapter = (struct zfcp_adapter *)host->hostdata[0];
  367. fc_stats = zfcp_init_fc_host_stats(adapter);
  368. if (!fc_stats)
  369. return NULL;
  370. data = kzalloc(sizeof(*data), GFP_KERNEL);
  371. if (!data)
  372. return NULL;
  373. ret = zfcp_fsf_exchange_port_data_sync(adapter->qdio, data);
  374. if (ret) {
  375. kfree(data);
  376. return NULL;
  377. }
  378. if (adapter->stats_reset &&
  379. ((jiffies/HZ - adapter->stats_reset) <
  380. data->seconds_since_last_reset))
  381. zfcp_adjust_fc_host_stats(fc_stats, data,
  382. adapter->stats_reset_data);
  383. else
  384. zfcp_set_fc_host_stats(fc_stats, data);
  385. kfree(data);
  386. return fc_stats;
  387. }
  388. static void zfcp_reset_fc_host_stats(struct Scsi_Host *shost)
  389. {
  390. struct zfcp_adapter *adapter;
  391. struct fsf_qtcb_bottom_port *data;
  392. int ret;
  393. adapter = (struct zfcp_adapter *)shost->hostdata[0];
  394. data = kzalloc(sizeof(*data), GFP_KERNEL);
  395. if (!data)
  396. return;
  397. ret = zfcp_fsf_exchange_port_data_sync(adapter->qdio, data);
  398. if (ret)
  399. kfree(data);
  400. else {
  401. adapter->stats_reset = jiffies/HZ;
  402. kfree(adapter->stats_reset_data);
  403. adapter->stats_reset_data = data; /* finally freed in
  404. adapter_release */
  405. }
  406. }
  407. static void zfcp_get_host_port_state(struct Scsi_Host *shost)
  408. {
  409. struct zfcp_adapter *adapter =
  410. (struct zfcp_adapter *)shost->hostdata[0];
  411. int status = atomic_read(&adapter->status);
  412. if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
  413. !(status & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED))
  414. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  415. else if (status & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  416. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  417. else if (status & ZFCP_STATUS_COMMON_ERP_FAILED)
  418. fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
  419. else
  420. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  421. }
  422. static void zfcp_set_rport_dev_loss_tmo(struct fc_rport *rport, u32 timeout)
  423. {
  424. rport->dev_loss_tmo = timeout;
  425. }
  426. /**
  427. * zfcp_scsi_terminate_rport_io - Terminate all I/O on a rport
  428. * @rport: The FC rport where to teminate I/O
  429. *
  430. * Abort all pending SCSI commands for a port by closing the
  431. * port. Using a reopen avoiding a conflict with a shutdown
  432. * overwriting a reopen.
  433. */
  434. static void zfcp_scsi_terminate_rport_io(struct fc_rport *rport)
  435. {
  436. struct zfcp_port *port;
  437. struct Scsi_Host *shost = rport_to_shost(rport);
  438. struct zfcp_adapter *adapter =
  439. (struct zfcp_adapter *)shost->hostdata[0];
  440. port = zfcp_get_port_by_wwpn(adapter, rport->port_name);
  441. if (port) {
  442. zfcp_erp_port_reopen(port, 0, "sctrpi1", NULL);
  443. put_device(&port->dev);
  444. }
  445. }
  446. static void zfcp_scsi_rport_register(struct zfcp_port *port)
  447. {
  448. struct fc_rport_identifiers ids;
  449. struct fc_rport *rport;
  450. if (port->rport)
  451. return;
  452. ids.node_name = port->wwnn;
  453. ids.port_name = port->wwpn;
  454. ids.port_id = port->d_id;
  455. ids.roles = FC_RPORT_ROLE_FCP_TARGET;
  456. rport = fc_remote_port_add(port->adapter->scsi_host, 0, &ids);
  457. if (!rport) {
  458. dev_err(&port->adapter->ccw_device->dev,
  459. "Registering port 0x%016Lx failed\n",
  460. (unsigned long long)port->wwpn);
  461. return;
  462. }
  463. rport->maxframe_size = port->maxframe_size;
  464. rport->supported_classes = port->supported_classes;
  465. port->rport = rport;
  466. }
  467. static void zfcp_scsi_rport_block(struct zfcp_port *port)
  468. {
  469. struct fc_rport *rport = port->rport;
  470. if (rport) {
  471. fc_remote_port_delete(rport);
  472. port->rport = NULL;
  473. }
  474. }
  475. void zfcp_scsi_schedule_rport_register(struct zfcp_port *port)
  476. {
  477. get_device(&port->dev);
  478. port->rport_task = RPORT_ADD;
  479. if (!queue_work(port->adapter->work_queue, &port->rport_work))
  480. put_device(&port->dev);
  481. }
  482. void zfcp_scsi_schedule_rport_block(struct zfcp_port *port)
  483. {
  484. get_device(&port->dev);
  485. port->rport_task = RPORT_DEL;
  486. if (port->rport && queue_work(port->adapter->work_queue,
  487. &port->rport_work))
  488. return;
  489. put_device(&port->dev);
  490. }
  491. void zfcp_scsi_schedule_rports_block(struct zfcp_adapter *adapter)
  492. {
  493. unsigned long flags;
  494. struct zfcp_port *port;
  495. read_lock_irqsave(&adapter->port_list_lock, flags);
  496. list_for_each_entry(port, &adapter->port_list, list)
  497. zfcp_scsi_schedule_rport_block(port);
  498. read_unlock_irqrestore(&adapter->port_list_lock, flags);
  499. }
  500. void zfcp_scsi_rport_work(struct work_struct *work)
  501. {
  502. struct zfcp_port *port = container_of(work, struct zfcp_port,
  503. rport_work);
  504. while (port->rport_task) {
  505. if (port->rport_task == RPORT_ADD) {
  506. port->rport_task = RPORT_NONE;
  507. zfcp_scsi_rport_register(port);
  508. } else {
  509. port->rport_task = RPORT_NONE;
  510. zfcp_scsi_rport_block(port);
  511. }
  512. }
  513. put_device(&port->dev);
  514. }
  515. void zfcp_scsi_scan(struct work_struct *work)
  516. {
  517. struct zfcp_unit *unit = container_of(work, struct zfcp_unit,
  518. scsi_work);
  519. struct fc_rport *rport;
  520. flush_work(&unit->port->rport_work);
  521. rport = unit->port->rport;
  522. if (rport && rport->port_state == FC_PORTSTATE_ONLINE)
  523. scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
  524. scsilun_to_int((struct scsi_lun *)
  525. &unit->fcp_lun), 0);
  526. put_device(&unit->dev);
  527. }
  528. struct fc_function_template zfcp_transport_functions = {
  529. .show_starget_port_id = 1,
  530. .show_starget_port_name = 1,
  531. .show_starget_node_name = 1,
  532. .show_rport_supported_classes = 1,
  533. .show_rport_maxframe_size = 1,
  534. .show_rport_dev_loss_tmo = 1,
  535. .show_host_node_name = 1,
  536. .show_host_port_name = 1,
  537. .show_host_permanent_port_name = 1,
  538. .show_host_supported_classes = 1,
  539. .show_host_supported_fc4s = 1,
  540. .show_host_supported_speeds = 1,
  541. .show_host_maxframe_size = 1,
  542. .show_host_serial_number = 1,
  543. .get_fc_host_stats = zfcp_get_fc_host_stats,
  544. .reset_fc_host_stats = zfcp_reset_fc_host_stats,
  545. .set_rport_dev_loss_tmo = zfcp_set_rport_dev_loss_tmo,
  546. .get_host_port_state = zfcp_get_host_port_state,
  547. .terminate_rport_io = zfcp_scsi_terminate_rport_io,
  548. .show_host_port_state = 1,
  549. .show_host_active_fc4s = 1,
  550. .bsg_request = zfcp_fc_exec_bsg_job,
  551. .bsg_timeout = zfcp_fc_timeout_bsg_job,
  552. /* no functions registered for following dynamic attributes but
  553. directly set by LLDD */
  554. .show_host_port_type = 1,
  555. .show_host_speed = 1,
  556. .show_host_port_id = 1,
  557. .disable_target_scan = 1,
  558. .dd_bsg_size = sizeof(struct zfcp_fsf_ct_els),
  559. };
  560. struct zfcp_data zfcp_data = {
  561. .scsi_host_template = {
  562. .name = "zfcp",
  563. .module = THIS_MODULE,
  564. .proc_name = "zfcp",
  565. .change_queue_depth = zfcp_scsi_change_queue_depth,
  566. .slave_alloc = zfcp_scsi_slave_alloc,
  567. .slave_configure = zfcp_scsi_slave_configure,
  568. .slave_destroy = zfcp_scsi_slave_destroy,
  569. .queuecommand = zfcp_scsi_queuecommand,
  570. .eh_abort_handler = zfcp_scsi_eh_abort_handler,
  571. .eh_device_reset_handler = zfcp_scsi_eh_device_reset_handler,
  572. .eh_target_reset_handler = zfcp_scsi_eh_target_reset_handler,
  573. .eh_host_reset_handler = zfcp_scsi_eh_host_reset_handler,
  574. .can_queue = 4096,
  575. .this_id = -1,
  576. .sg_tablesize = ZFCP_MAX_SBALES_PER_REQ,
  577. .cmd_per_lun = 1,
  578. .use_clustering = 1,
  579. .sdev_attrs = zfcp_sysfs_sdev_attrs,
  580. .max_sectors = (ZFCP_MAX_SBALES_PER_REQ * 8),
  581. .shost_attrs = zfcp_sysfs_shost_attrs,
  582. },
  583. };