zfcp_scsi.c 19 KB

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