PageRenderTime 73ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/s390/scsi/zfcp_fsf.c

https://bitbucket.org/wisechild/galaxy-nexus
C | 2429 lines | 1924 code | 336 blank | 169 comment | 191 complexity | 27f5557c5aa7073fe43ea938a48164b7 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corporation 2002, 2010
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/blktrace_api.h>
  11. #include <linux/slab.h>
  12. #include <scsi/fc/fc_els.h>
  13. #include "zfcp_ext.h"
  14. #include "zfcp_fc.h"
  15. #include "zfcp_dbf.h"
  16. #include "zfcp_qdio.h"
  17. #include "zfcp_reqlist.h"
  18. struct kmem_cache *zfcp_fsf_qtcb_cache;
  19. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  20. {
  21. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  22. zfcp_qdio_siosl(adapter);
  23. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  24. "fsrth_1");
  25. }
  26. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  27. unsigned long timeout)
  28. {
  29. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  30. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  31. fsf_req->timer.expires = jiffies + timeout;
  32. add_timer(&fsf_req->timer);
  33. }
  34. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  35. {
  36. BUG_ON(!fsf_req->erp_action);
  37. fsf_req->timer.function = zfcp_erp_timeout_handler;
  38. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  39. fsf_req->timer.expires = jiffies + 30 * HZ;
  40. add_timer(&fsf_req->timer);
  41. }
  42. /* association between FSF command and FSF QTCB type */
  43. static u32 fsf_qtcb_type[] = {
  44. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  45. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  46. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  47. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  48. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  49. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  50. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  51. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  52. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  53. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  54. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  55. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  56. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  57. };
  58. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  59. {
  60. dev_err(&req->adapter->ccw_device->dev, "FCP device not "
  61. "operational because of an unsupported FC class\n");
  62. zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1");
  63. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  64. }
  65. /**
  66. * zfcp_fsf_req_free - free memory used by fsf request
  67. * @fsf_req: pointer to struct zfcp_fsf_req
  68. */
  69. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  70. {
  71. if (likely(req->pool)) {
  72. if (likely(req->qtcb))
  73. mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
  74. mempool_free(req, req->pool);
  75. return;
  76. }
  77. if (likely(req->qtcb))
  78. kmem_cache_free(zfcp_fsf_qtcb_cache, req->qtcb);
  79. kfree(req);
  80. }
  81. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  82. {
  83. unsigned long flags;
  84. struct fsf_status_read_buffer *sr_buf = req->data;
  85. struct zfcp_adapter *adapter = req->adapter;
  86. struct zfcp_port *port;
  87. int d_id = ntoh24(sr_buf->d_id);
  88. read_lock_irqsave(&adapter->port_list_lock, flags);
  89. list_for_each_entry(port, &adapter->port_list, list)
  90. if (port->d_id == d_id) {
  91. zfcp_erp_port_reopen(port, 0, "fssrpc1");
  92. break;
  93. }
  94. read_unlock_irqrestore(&adapter->port_list_lock, flags);
  95. }
  96. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req,
  97. struct fsf_link_down_info *link_down)
  98. {
  99. struct zfcp_adapter *adapter = req->adapter;
  100. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  101. return;
  102. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  103. zfcp_scsi_schedule_rports_block(adapter);
  104. if (!link_down)
  105. goto out;
  106. switch (link_down->error_code) {
  107. case FSF_PSQ_LINK_NO_LIGHT:
  108. dev_warn(&req->adapter->ccw_device->dev,
  109. "There is no light signal from the local "
  110. "fibre channel cable\n");
  111. break;
  112. case FSF_PSQ_LINK_WRAP_PLUG:
  113. dev_warn(&req->adapter->ccw_device->dev,
  114. "There is a wrap plug instead of a fibre "
  115. "channel cable\n");
  116. break;
  117. case FSF_PSQ_LINK_NO_FCP:
  118. dev_warn(&req->adapter->ccw_device->dev,
  119. "The adjacent fibre channel node does not "
  120. "support FCP\n");
  121. break;
  122. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  123. dev_warn(&req->adapter->ccw_device->dev,
  124. "The FCP device is suspended because of a "
  125. "firmware update\n");
  126. break;
  127. case FSF_PSQ_LINK_INVALID_WWPN:
  128. dev_warn(&req->adapter->ccw_device->dev,
  129. "The FCP device detected a WWPN that is "
  130. "duplicate or not valid\n");
  131. break;
  132. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  133. dev_warn(&req->adapter->ccw_device->dev,
  134. "The fibre channel fabric does not support NPIV\n");
  135. break;
  136. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  137. dev_warn(&req->adapter->ccw_device->dev,
  138. "The FCP adapter cannot support more NPIV ports\n");
  139. break;
  140. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  141. dev_warn(&req->adapter->ccw_device->dev,
  142. "The adjacent switch cannot support "
  143. "more NPIV ports\n");
  144. break;
  145. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  146. dev_warn(&req->adapter->ccw_device->dev,
  147. "The FCP adapter could not log in to the "
  148. "fibre channel fabric\n");
  149. break;
  150. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  151. dev_warn(&req->adapter->ccw_device->dev,
  152. "The WWPN assignment file on the FCP adapter "
  153. "has been damaged\n");
  154. break;
  155. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  156. dev_warn(&req->adapter->ccw_device->dev,
  157. "The mode table on the FCP adapter "
  158. "has been damaged\n");
  159. break;
  160. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  161. dev_warn(&req->adapter->ccw_device->dev,
  162. "All NPIV ports on the FCP adapter have "
  163. "been assigned\n");
  164. break;
  165. default:
  166. dev_warn(&req->adapter->ccw_device->dev,
  167. "The link between the FCP adapter and "
  168. "the FC fabric is down\n");
  169. }
  170. out:
  171. zfcp_erp_set_adapter_status(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
  172. }
  173. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  174. {
  175. struct fsf_status_read_buffer *sr_buf = req->data;
  176. struct fsf_link_down_info *ldi =
  177. (struct fsf_link_down_info *) &sr_buf->payload;
  178. switch (sr_buf->status_subtype) {
  179. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  180. zfcp_fsf_link_down_info_eval(req, ldi);
  181. break;
  182. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  183. zfcp_fsf_link_down_info_eval(req, ldi);
  184. break;
  185. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  186. zfcp_fsf_link_down_info_eval(req, NULL);
  187. };
  188. }
  189. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  190. {
  191. struct zfcp_adapter *adapter = req->adapter;
  192. struct fsf_status_read_buffer *sr_buf = req->data;
  193. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  194. zfcp_dbf_hba_fsf_uss("fssrh_1", req);
  195. mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
  196. zfcp_fsf_req_free(req);
  197. return;
  198. }
  199. zfcp_dbf_hba_fsf_uss("fssrh_2", req);
  200. switch (sr_buf->status_type) {
  201. case FSF_STATUS_READ_PORT_CLOSED:
  202. zfcp_fsf_status_read_port_closed(req);
  203. break;
  204. case FSF_STATUS_READ_INCOMING_ELS:
  205. zfcp_fc_incoming_els(req);
  206. break;
  207. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  208. break;
  209. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  210. dev_warn(&adapter->ccw_device->dev,
  211. "The error threshold for checksum statistics "
  212. "has been exceeded\n");
  213. zfcp_dbf_hba_bit_err("fssrh_3", req);
  214. break;
  215. case FSF_STATUS_READ_LINK_DOWN:
  216. zfcp_fsf_status_read_link_down(req);
  217. zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKDOWN, 0);
  218. break;
  219. case FSF_STATUS_READ_LINK_UP:
  220. dev_info(&adapter->ccw_device->dev,
  221. "The local link has been restored\n");
  222. /* All ports should be marked as ready to run again */
  223. zfcp_erp_set_adapter_status(adapter,
  224. ZFCP_STATUS_COMMON_RUNNING);
  225. zfcp_erp_adapter_reopen(adapter,
  226. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  227. ZFCP_STATUS_COMMON_ERP_FAILED,
  228. "fssrh_2");
  229. zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKUP, 0);
  230. break;
  231. case FSF_STATUS_READ_NOTIFICATION_LOST:
  232. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
  233. zfcp_cfdc_adapter_access_changed(adapter);
  234. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  235. queue_work(adapter->work_queue, &adapter->scan_work);
  236. break;
  237. case FSF_STATUS_READ_CFDC_UPDATED:
  238. zfcp_cfdc_adapter_access_changed(adapter);
  239. break;
  240. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  241. adapter->adapter_features = sr_buf->payload.word[0];
  242. break;
  243. }
  244. mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
  245. zfcp_fsf_req_free(req);
  246. atomic_inc(&adapter->stat_miss);
  247. queue_work(adapter->work_queue, &adapter->stat_work);
  248. }
  249. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  250. {
  251. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  252. case FSF_SQ_FCP_RSP_AVAILABLE:
  253. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  254. case FSF_SQ_NO_RETRY_POSSIBLE:
  255. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  256. return;
  257. case FSF_SQ_COMMAND_ABORTED:
  258. break;
  259. case FSF_SQ_NO_RECOM:
  260. dev_err(&req->adapter->ccw_device->dev,
  261. "The FCP adapter reported a problem "
  262. "that cannot be recovered\n");
  263. zfcp_qdio_siosl(req->adapter);
  264. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1");
  265. break;
  266. }
  267. /* all non-return stats set FSFREQ_ERROR*/
  268. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  269. }
  270. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  271. {
  272. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  273. return;
  274. switch (req->qtcb->header.fsf_status) {
  275. case FSF_UNKNOWN_COMMAND:
  276. dev_err(&req->adapter->ccw_device->dev,
  277. "The FCP adapter does not recognize the command 0x%x\n",
  278. req->qtcb->header.fsf_command);
  279. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1");
  280. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  281. break;
  282. case FSF_ADAPTER_STATUS_AVAILABLE:
  283. zfcp_fsf_fsfstatus_qual_eval(req);
  284. break;
  285. }
  286. }
  287. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  288. {
  289. struct zfcp_adapter *adapter = req->adapter;
  290. struct fsf_qtcb *qtcb = req->qtcb;
  291. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  292. zfcp_dbf_hba_fsf_response(req);
  293. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  294. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  295. return;
  296. }
  297. switch (qtcb->prefix.prot_status) {
  298. case FSF_PROT_GOOD:
  299. case FSF_PROT_FSF_STATUS_PRESENTED:
  300. return;
  301. case FSF_PROT_QTCB_VERSION_ERROR:
  302. dev_err(&adapter->ccw_device->dev,
  303. "QTCB version 0x%x not supported by FCP adapter "
  304. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  305. psq->word[0], psq->word[1]);
  306. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1");
  307. break;
  308. case FSF_PROT_ERROR_STATE:
  309. case FSF_PROT_SEQ_NUMB_ERROR:
  310. zfcp_erp_adapter_reopen(adapter, 0, "fspse_2");
  311. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  312. break;
  313. case FSF_PROT_UNSUPP_QTCB_TYPE:
  314. dev_err(&adapter->ccw_device->dev,
  315. "The QTCB type is not supported by the FCP adapter\n");
  316. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3");
  317. break;
  318. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  319. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  320. &adapter->status);
  321. break;
  322. case FSF_PROT_DUPLICATE_REQUEST_ID:
  323. dev_err(&adapter->ccw_device->dev,
  324. "0x%Lx is an ambiguous request identifier\n",
  325. (unsigned long long)qtcb->bottom.support.req_handle);
  326. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4");
  327. break;
  328. case FSF_PROT_LINK_DOWN:
  329. zfcp_fsf_link_down_info_eval(req, &psq->link_down_info);
  330. /* go through reopen to flush pending requests */
  331. zfcp_erp_adapter_reopen(adapter, 0, "fspse_6");
  332. break;
  333. case FSF_PROT_REEST_QUEUE:
  334. /* All ports should be marked as ready to run again */
  335. zfcp_erp_set_adapter_status(adapter,
  336. ZFCP_STATUS_COMMON_RUNNING);
  337. zfcp_erp_adapter_reopen(adapter,
  338. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  339. ZFCP_STATUS_COMMON_ERP_FAILED,
  340. "fspse_8");
  341. break;
  342. default:
  343. dev_err(&adapter->ccw_device->dev,
  344. "0x%x is not a valid transfer protocol status\n",
  345. qtcb->prefix.prot_status);
  346. zfcp_qdio_siosl(adapter);
  347. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9");
  348. }
  349. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  350. }
  351. /**
  352. * zfcp_fsf_req_complete - process completion of a FSF request
  353. * @fsf_req: The FSF request that has been completed.
  354. *
  355. * When a request has been completed either from the FCP adapter,
  356. * or it has been dismissed due to a queue shutdown, this function
  357. * is called to process the completion status and trigger further
  358. * events related to the FSF request.
  359. */
  360. static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  361. {
  362. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  363. zfcp_fsf_status_read_handler(req);
  364. return;
  365. }
  366. del_timer(&req->timer);
  367. zfcp_fsf_protstatus_eval(req);
  368. zfcp_fsf_fsfstatus_eval(req);
  369. req->handler(req);
  370. if (req->erp_action)
  371. zfcp_erp_notify(req->erp_action, 0);
  372. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  373. zfcp_fsf_req_free(req);
  374. else
  375. complete(&req->completion);
  376. }
  377. /**
  378. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  379. * @adapter: pointer to struct zfcp_adapter
  380. *
  381. * Never ever call this without shutting down the adapter first.
  382. * Otherwise the adapter would continue using and corrupting s390 storage.
  383. * Included BUG_ON() call to ensure this is done.
  384. * ERP is supposed to be the only user of this function.
  385. */
  386. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  387. {
  388. struct zfcp_fsf_req *req, *tmp;
  389. LIST_HEAD(remove_queue);
  390. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  391. zfcp_reqlist_move(adapter->req_list, &remove_queue);
  392. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  393. list_del(&req->list);
  394. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  395. zfcp_fsf_req_complete(req);
  396. }
  397. }
  398. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  399. {
  400. struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
  401. struct zfcp_adapter *adapter = req->adapter;
  402. struct Scsi_Host *shost = adapter->scsi_host;
  403. struct fc_els_flogi *nsp, *plogi;
  404. /* adjust pointers for missing command code */
  405. nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
  406. - sizeof(u32));
  407. plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
  408. - sizeof(u32));
  409. if (req->data)
  410. memcpy(req->data, bottom, sizeof(*bottom));
  411. fc_host_port_name(shost) = nsp->fl_wwpn;
  412. fc_host_node_name(shost) = nsp->fl_wwnn;
  413. fc_host_port_id(shost) = ntoh24(bottom->s_id);
  414. fc_host_speed(shost) = bottom->fc_link_speed;
  415. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  416. adapter->hydra_version = bottom->adapter_type;
  417. adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
  418. adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
  419. (u16)FSF_STATUS_READS_RECOM);
  420. if (fc_host_permanent_port_name(shost) == -1)
  421. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  422. switch (bottom->fc_topology) {
  423. case FSF_TOPO_P2P:
  424. adapter->peer_d_id = ntoh24(bottom->peer_d_id);
  425. adapter->peer_wwpn = plogi->fl_wwpn;
  426. adapter->peer_wwnn = plogi->fl_wwnn;
  427. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  428. break;
  429. case FSF_TOPO_FABRIC:
  430. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  431. break;
  432. case FSF_TOPO_AL:
  433. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  434. /* fall through */
  435. default:
  436. dev_err(&adapter->ccw_device->dev,
  437. "Unknown or unsupported arbitrated loop "
  438. "fibre channel topology detected\n");
  439. zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1");
  440. return -EIO;
  441. }
  442. zfcp_scsi_set_prot(adapter);
  443. return 0;
  444. }
  445. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  446. {
  447. struct zfcp_adapter *adapter = req->adapter;
  448. struct fsf_qtcb *qtcb = req->qtcb;
  449. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  450. struct Scsi_Host *shost = adapter->scsi_host;
  451. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  452. return;
  453. adapter->fsf_lic_version = bottom->lic_version;
  454. adapter->adapter_features = bottom->adapter_features;
  455. adapter->connection_features = bottom->connection_features;
  456. adapter->peer_wwpn = 0;
  457. adapter->peer_wwnn = 0;
  458. adapter->peer_d_id = 0;
  459. switch (qtcb->header.fsf_status) {
  460. case FSF_GOOD:
  461. if (zfcp_fsf_exchange_config_evaluate(req))
  462. return;
  463. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  464. dev_err(&adapter->ccw_device->dev,
  465. "FCP adapter maximum QTCB size (%d bytes) "
  466. "is too small\n",
  467. bottom->max_qtcb_size);
  468. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1");
  469. return;
  470. }
  471. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  472. &adapter->status);
  473. break;
  474. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  475. fc_host_node_name(shost) = 0;
  476. fc_host_port_name(shost) = 0;
  477. fc_host_port_id(shost) = 0;
  478. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  479. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  480. adapter->hydra_version = 0;
  481. zfcp_fsf_link_down_info_eval(req,
  482. &qtcb->header.fsf_status_qual.link_down_info);
  483. break;
  484. default:
  485. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3");
  486. return;
  487. }
  488. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  489. adapter->hardware_version = bottom->hardware_version;
  490. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  491. min(FC_SERIAL_NUMBER_SIZE, 17));
  492. EBCASC(fc_host_serial_number(shost),
  493. min(FC_SERIAL_NUMBER_SIZE, 17));
  494. }
  495. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  496. dev_err(&adapter->ccw_device->dev,
  497. "The FCP adapter only supports newer "
  498. "control block versions\n");
  499. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4");
  500. return;
  501. }
  502. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  503. dev_err(&adapter->ccw_device->dev,
  504. "The FCP adapter only supports older "
  505. "control block versions\n");
  506. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5");
  507. }
  508. }
  509. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  510. {
  511. struct zfcp_adapter *adapter = req->adapter;
  512. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  513. struct Scsi_Host *shost = adapter->scsi_host;
  514. if (req->data)
  515. memcpy(req->data, bottom, sizeof(*bottom));
  516. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
  517. fc_host_permanent_port_name(shost) = bottom->wwpn;
  518. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  519. } else
  520. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  521. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  522. fc_host_supported_speeds(shost) = bottom->supported_speed;
  523. memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
  524. FC_FC4_LIST_SIZE);
  525. memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
  526. FC_FC4_LIST_SIZE);
  527. }
  528. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  529. {
  530. struct fsf_qtcb *qtcb = req->qtcb;
  531. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  532. return;
  533. switch (qtcb->header.fsf_status) {
  534. case FSF_GOOD:
  535. zfcp_fsf_exchange_port_evaluate(req);
  536. break;
  537. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  538. zfcp_fsf_exchange_port_evaluate(req);
  539. zfcp_fsf_link_down_info_eval(req,
  540. &qtcb->header.fsf_status_qual.link_down_info);
  541. break;
  542. }
  543. }
  544. static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
  545. {
  546. struct zfcp_fsf_req *req;
  547. if (likely(pool))
  548. req = mempool_alloc(pool, GFP_ATOMIC);
  549. else
  550. req = kmalloc(sizeof(*req), GFP_ATOMIC);
  551. if (unlikely(!req))
  552. return NULL;
  553. memset(req, 0, sizeof(*req));
  554. req->pool = pool;
  555. return req;
  556. }
  557. static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
  558. {
  559. struct fsf_qtcb *qtcb;
  560. if (likely(pool))
  561. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  562. else
  563. qtcb = kmem_cache_alloc(zfcp_fsf_qtcb_cache, GFP_ATOMIC);
  564. if (unlikely(!qtcb))
  565. return NULL;
  566. memset(qtcb, 0, sizeof(*qtcb));
  567. return qtcb;
  568. }
  569. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
  570. u32 fsf_cmd, u8 sbtype,
  571. mempool_t *pool)
  572. {
  573. struct zfcp_adapter *adapter = qdio->adapter;
  574. struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
  575. if (unlikely(!req))
  576. return ERR_PTR(-ENOMEM);
  577. if (adapter->req_no == 0)
  578. adapter->req_no++;
  579. INIT_LIST_HEAD(&req->list);
  580. init_timer(&req->timer);
  581. init_completion(&req->completion);
  582. req->adapter = adapter;
  583. req->fsf_command = fsf_cmd;
  584. req->req_id = adapter->req_no;
  585. if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
  586. if (likely(pool))
  587. req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
  588. else
  589. req->qtcb = zfcp_qtcb_alloc(NULL);
  590. if (unlikely(!req->qtcb)) {
  591. zfcp_fsf_req_free(req);
  592. return ERR_PTR(-ENOMEM);
  593. }
  594. req->seq_no = adapter->fsf_req_seq_no;
  595. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  596. req->qtcb->prefix.req_id = req->req_id;
  597. req->qtcb->prefix.ulp_info = 26;
  598. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  599. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  600. req->qtcb->header.req_handle = req->req_id;
  601. req->qtcb->header.fsf_command = req->fsf_command;
  602. }
  603. zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
  604. req->qtcb, sizeof(struct fsf_qtcb));
  605. return req;
  606. }
  607. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  608. {
  609. struct zfcp_adapter *adapter = req->adapter;
  610. struct zfcp_qdio *qdio = adapter->qdio;
  611. int with_qtcb = (req->qtcb != NULL);
  612. int req_id = req->req_id;
  613. zfcp_reqlist_add(adapter->req_list, req);
  614. req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
  615. req->issued = get_clock();
  616. if (zfcp_qdio_send(qdio, &req->qdio_req)) {
  617. del_timer(&req->timer);
  618. /* lookup request again, list might have changed */
  619. zfcp_reqlist_find_rm(adapter->req_list, req_id);
  620. zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1");
  621. return -EIO;
  622. }
  623. /* Don't increase for unsolicited status */
  624. if (with_qtcb)
  625. adapter->fsf_req_seq_no++;
  626. adapter->req_no++;
  627. return 0;
  628. }
  629. /**
  630. * zfcp_fsf_status_read - send status read request
  631. * @adapter: pointer to struct zfcp_adapter
  632. * @req_flags: request flags
  633. * Returns: 0 on success, ERROR otherwise
  634. */
  635. int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
  636. {
  637. struct zfcp_adapter *adapter = qdio->adapter;
  638. struct zfcp_fsf_req *req;
  639. struct fsf_status_read_buffer *sr_buf;
  640. struct page *page;
  641. int retval = -EIO;
  642. spin_lock_irq(&qdio->req_q_lock);
  643. if (zfcp_qdio_sbal_get(qdio))
  644. goto out;
  645. req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
  646. adapter->pool.status_read_req);
  647. if (IS_ERR(req)) {
  648. retval = PTR_ERR(req);
  649. goto out;
  650. }
  651. page = mempool_alloc(adapter->pool.sr_data, GFP_ATOMIC);
  652. if (!page) {
  653. retval = -ENOMEM;
  654. goto failed_buf;
  655. }
  656. sr_buf = page_address(page);
  657. memset(sr_buf, 0, sizeof(*sr_buf));
  658. req->data = sr_buf;
  659. zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
  660. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  661. retval = zfcp_fsf_req_send(req);
  662. if (retval)
  663. goto failed_req_send;
  664. goto out;
  665. failed_req_send:
  666. req->data = NULL;
  667. mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
  668. failed_buf:
  669. zfcp_dbf_hba_fsf_uss("fssr__1", req);
  670. zfcp_fsf_req_free(req);
  671. out:
  672. spin_unlock_irq(&qdio->req_q_lock);
  673. return retval;
  674. }
  675. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  676. {
  677. struct scsi_device *sdev = req->data;
  678. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  679. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  680. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  681. return;
  682. switch (req->qtcb->header.fsf_status) {
  683. case FSF_PORT_HANDLE_NOT_VALID:
  684. if (fsq->word[0] == fsq->word[1]) {
  685. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0,
  686. "fsafch1");
  687. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  688. }
  689. break;
  690. case FSF_LUN_HANDLE_NOT_VALID:
  691. if (fsq->word[0] == fsq->word[1]) {
  692. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2");
  693. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  694. }
  695. break;
  696. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  697. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  698. break;
  699. case FSF_PORT_BOXED:
  700. zfcp_erp_set_port_status(zfcp_sdev->port,
  701. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  702. zfcp_erp_port_reopen(zfcp_sdev->port,
  703. ZFCP_STATUS_COMMON_ERP_FAILED, "fsafch3");
  704. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  705. break;
  706. case FSF_LUN_BOXED:
  707. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  708. zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
  709. "fsafch4");
  710. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  711. break;
  712. case FSF_ADAPTER_STATUS_AVAILABLE:
  713. switch (fsq->word[0]) {
  714. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  715. zfcp_fc_test_link(zfcp_sdev->port);
  716. /* fall through */
  717. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  718. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  719. break;
  720. }
  721. break;
  722. case FSF_GOOD:
  723. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  724. break;
  725. }
  726. }
  727. /**
  728. * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command
  729. * @scmnd: The SCSI command to abort
  730. * Returns: pointer to struct zfcp_fsf_req
  731. */
  732. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd)
  733. {
  734. struct zfcp_fsf_req *req = NULL;
  735. struct scsi_device *sdev = scmnd->device;
  736. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  737. struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
  738. unsigned long old_req_id = (unsigned long) scmnd->host_scribble;
  739. spin_lock_irq(&qdio->req_q_lock);
  740. if (zfcp_qdio_sbal_get(qdio))
  741. goto out;
  742. req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
  743. SBAL_SFLAGS0_TYPE_READ,
  744. qdio->adapter->pool.scsi_abort);
  745. if (IS_ERR(req)) {
  746. req = NULL;
  747. goto out;
  748. }
  749. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  750. ZFCP_STATUS_COMMON_UNBLOCKED)))
  751. goto out_error_free;
  752. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  753. req->data = sdev;
  754. req->handler = zfcp_fsf_abort_fcp_command_handler;
  755. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  756. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  757. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  758. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  759. if (!zfcp_fsf_req_send(req))
  760. goto out;
  761. out_error_free:
  762. zfcp_fsf_req_free(req);
  763. req = NULL;
  764. out:
  765. spin_unlock_irq(&qdio->req_q_lock);
  766. return req;
  767. }
  768. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  769. {
  770. struct zfcp_adapter *adapter = req->adapter;
  771. struct zfcp_fsf_ct_els *ct = req->data;
  772. struct fsf_qtcb_header *header = &req->qtcb->header;
  773. ct->status = -EINVAL;
  774. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  775. goto skip_fsfstatus;
  776. switch (header->fsf_status) {
  777. case FSF_GOOD:
  778. zfcp_dbf_san_res("fsscth1", req);
  779. ct->status = 0;
  780. break;
  781. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  782. zfcp_fsf_class_not_supp(req);
  783. break;
  784. case FSF_ADAPTER_STATUS_AVAILABLE:
  785. switch (header->fsf_status_qual.word[0]){
  786. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  787. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  788. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  789. break;
  790. }
  791. break;
  792. case FSF_ACCESS_DENIED:
  793. break;
  794. case FSF_PORT_BOXED:
  795. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  796. break;
  797. case FSF_PORT_HANDLE_NOT_VALID:
  798. zfcp_erp_adapter_reopen(adapter, 0, "fsscth1");
  799. /* fall through */
  800. case FSF_GENERIC_COMMAND_REJECTED:
  801. case FSF_PAYLOAD_SIZE_MISMATCH:
  802. case FSF_REQUEST_SIZE_TOO_LARGE:
  803. case FSF_RESPONSE_SIZE_TOO_LARGE:
  804. case FSF_SBAL_MISMATCH:
  805. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  806. break;
  807. }
  808. skip_fsfstatus:
  809. if (ct->handler)
  810. ct->handler(ct->handler_data);
  811. }
  812. static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
  813. struct zfcp_qdio_req *q_req,
  814. struct scatterlist *sg_req,
  815. struct scatterlist *sg_resp)
  816. {
  817. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
  818. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
  819. zfcp_qdio_set_sbale_last(qdio, q_req);
  820. }
  821. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  822. struct scatterlist *sg_req,
  823. struct scatterlist *sg_resp)
  824. {
  825. struct zfcp_adapter *adapter = req->adapter;
  826. u32 feat = adapter->adapter_features;
  827. int bytes;
  828. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
  829. if (!zfcp_qdio_sg_one_sbale(sg_req) ||
  830. !zfcp_qdio_sg_one_sbale(sg_resp))
  831. return -EOPNOTSUPP;
  832. zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
  833. sg_req, sg_resp);
  834. return 0;
  835. }
  836. /* use single, unchained SBAL if it can hold the request */
  837. if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
  838. zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
  839. sg_req, sg_resp);
  840. return 0;
  841. }
  842. bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req, sg_req);
  843. if (bytes <= 0)
  844. return -EIO;
  845. zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
  846. req->qtcb->bottom.support.req_buf_length = bytes;
  847. zfcp_qdio_skip_to_last_sbale(&req->qdio_req);
  848. bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
  849. sg_resp);
  850. req->qtcb->bottom.support.resp_buf_length = bytes;
  851. if (bytes <= 0)
  852. return -EIO;
  853. zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
  854. return 0;
  855. }
  856. static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
  857. struct scatterlist *sg_req,
  858. struct scatterlist *sg_resp,
  859. unsigned int timeout)
  860. {
  861. int ret;
  862. ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
  863. if (ret)
  864. return ret;
  865. /* common settings for ct/gs and els requests */
  866. if (timeout > 255)
  867. timeout = 255; /* max value accepted by hardware */
  868. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  869. req->qtcb->bottom.support.timeout = timeout;
  870. zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
  871. return 0;
  872. }
  873. /**
  874. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  875. * @ct: pointer to struct zfcp_send_ct with data for request
  876. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  877. */
  878. int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
  879. struct zfcp_fsf_ct_els *ct, mempool_t *pool,
  880. unsigned int timeout)
  881. {
  882. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  883. struct zfcp_fsf_req *req;
  884. int ret = -EIO;
  885. spin_lock_irq(&qdio->req_q_lock);
  886. if (zfcp_qdio_sbal_get(qdio))
  887. goto out;
  888. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
  889. SBAL_SFLAGS0_TYPE_WRITE_READ, pool);
  890. if (IS_ERR(req)) {
  891. ret = PTR_ERR(req);
  892. goto out;
  893. }
  894. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  895. ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
  896. if (ret)
  897. goto failed_send;
  898. req->handler = zfcp_fsf_send_ct_handler;
  899. req->qtcb->header.port_handle = wka_port->handle;
  900. req->data = ct;
  901. zfcp_dbf_san_req("fssct_1", req, wka_port->d_id);
  902. ret = zfcp_fsf_req_send(req);
  903. if (ret)
  904. goto failed_send;
  905. goto out;
  906. failed_send:
  907. zfcp_fsf_req_free(req);
  908. out:
  909. spin_unlock_irq(&qdio->req_q_lock);
  910. return ret;
  911. }
  912. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  913. {
  914. struct zfcp_fsf_ct_els *send_els = req->data;
  915. struct zfcp_port *port = send_els->port;
  916. struct fsf_qtcb_header *header = &req->qtcb->header;
  917. send_els->status = -EINVAL;
  918. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  919. goto skip_fsfstatus;
  920. switch (header->fsf_status) {
  921. case FSF_GOOD:
  922. zfcp_dbf_san_res("fsselh1", req);
  923. send_els->status = 0;
  924. break;
  925. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  926. zfcp_fsf_class_not_supp(req);
  927. break;
  928. case FSF_ADAPTER_STATUS_AVAILABLE:
  929. switch (header->fsf_status_qual.word[0]){
  930. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  931. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  932. case FSF_SQ_RETRY_IF_POSSIBLE:
  933. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  934. break;
  935. }
  936. break;
  937. case FSF_ELS_COMMAND_REJECTED:
  938. case FSF_PAYLOAD_SIZE_MISMATCH:
  939. case FSF_REQUEST_SIZE_TOO_LARGE:
  940. case FSF_RESPONSE_SIZE_TOO_LARGE:
  941. break;
  942. case FSF_ACCESS_DENIED:
  943. if (port) {
  944. zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
  945. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  946. }
  947. break;
  948. case FSF_SBAL_MISMATCH:
  949. /* should never occur, avoided in zfcp_fsf_send_els */
  950. /* fall through */
  951. default:
  952. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  953. break;
  954. }
  955. skip_fsfstatus:
  956. if (send_els->handler)
  957. send_els->handler(send_els->handler_data);
  958. }
  959. /**
  960. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  961. * @els: pointer to struct zfcp_send_els with data for the command
  962. */
  963. int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
  964. struct zfcp_fsf_ct_els *els, unsigned int timeout)
  965. {
  966. struct zfcp_fsf_req *req;
  967. struct zfcp_qdio *qdio = adapter->qdio;
  968. int ret = -EIO;
  969. spin_lock_irq(&qdio->req_q_lock);
  970. if (zfcp_qdio_sbal_get(qdio))
  971. goto out;
  972. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
  973. SBAL_SFLAGS0_TYPE_WRITE_READ, NULL);
  974. if (IS_ERR(req)) {
  975. ret = PTR_ERR(req);
  976. goto out;
  977. }
  978. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  979. zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
  980. ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
  981. if (ret)
  982. goto failed_send;
  983. hton24(req->qtcb->bottom.support.d_id, d_id);
  984. req->handler = zfcp_fsf_send_els_handler;
  985. req->data = els;
  986. zfcp_dbf_san_req("fssels1", req, d_id);
  987. ret = zfcp_fsf_req_send(req);
  988. if (ret)
  989. goto failed_send;
  990. goto out;
  991. failed_send:
  992. zfcp_fsf_req_free(req);
  993. out:
  994. spin_unlock_irq(&qdio->req_q_lock);
  995. return ret;
  996. }
  997. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  998. {
  999. struct zfcp_fsf_req *req;
  1000. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1001. int retval = -EIO;
  1002. spin_lock_irq(&qdio->req_q_lock);
  1003. if (zfcp_qdio_sbal_get(qdio))
  1004. goto out;
  1005. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1006. SBAL_SFLAGS0_TYPE_READ,
  1007. qdio->adapter->pool.erp_req);
  1008. if (IS_ERR(req)) {
  1009. retval = PTR_ERR(req);
  1010. goto out;
  1011. }
  1012. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1013. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1014. req->qtcb->bottom.config.feature_selection =
  1015. FSF_FEATURE_CFDC |
  1016. FSF_FEATURE_LUN_SHARING |
  1017. FSF_FEATURE_NOTIFICATION_LOST |
  1018. FSF_FEATURE_UPDATE_ALERT;
  1019. req->erp_action = erp_action;
  1020. req->handler = zfcp_fsf_exchange_config_data_handler;
  1021. erp_action->fsf_req_id = req->req_id;
  1022. zfcp_fsf_start_erp_timer(req);
  1023. retval = zfcp_fsf_req_send(req);
  1024. if (retval) {
  1025. zfcp_fsf_req_free(req);
  1026. erp_action->fsf_req_id = 0;
  1027. }
  1028. out:
  1029. spin_unlock_irq(&qdio->req_q_lock);
  1030. return retval;
  1031. }
  1032. int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
  1033. struct fsf_qtcb_bottom_config *data)
  1034. {
  1035. struct zfcp_fsf_req *req = NULL;
  1036. int retval = -EIO;
  1037. spin_lock_irq(&qdio->req_q_lock);
  1038. if (zfcp_qdio_sbal_get(qdio))
  1039. goto out_unlock;
  1040. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1041. SBAL_SFLAGS0_TYPE_READ, NULL);
  1042. if (IS_ERR(req)) {
  1043. retval = PTR_ERR(req);
  1044. goto out_unlock;
  1045. }
  1046. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1047. req->handler = zfcp_fsf_exchange_config_data_handler;
  1048. req->qtcb->bottom.config.feature_selection =
  1049. FSF_FEATURE_CFDC |
  1050. FSF_FEATURE_LUN_SHARING |
  1051. FSF_FEATURE_NOTIFICATION_LOST |
  1052. FSF_FEATURE_UPDATE_ALERT;
  1053. if (data)
  1054. req->data = data;
  1055. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1056. retval = zfcp_fsf_req_send(req);
  1057. spin_unlock_irq(&qdio->req_q_lock);
  1058. if (!retval)
  1059. wait_for_completion(&req->completion);
  1060. zfcp_fsf_req_free(req);
  1061. return retval;
  1062. out_unlock:
  1063. spin_unlock_irq(&qdio->req_q_lock);
  1064. return retval;
  1065. }
  1066. /**
  1067. * zfcp_fsf_exchange_port_data - request information about local port
  1068. * @erp_action: ERP action for the adapter for which port data is requested
  1069. * Returns: 0 on success, error otherwise
  1070. */
  1071. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1072. {
  1073. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1074. struct zfcp_fsf_req *req;
  1075. int retval = -EIO;
  1076. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1077. return -EOPNOTSUPP;
  1078. spin_lock_irq(&qdio->req_q_lock);
  1079. if (zfcp_qdio_sbal_get(qdio))
  1080. goto out;
  1081. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1082. SBAL_SFLAGS0_TYPE_READ,
  1083. qdio->adapter->pool.erp_req);
  1084. if (IS_ERR(req)) {
  1085. retval = PTR_ERR(req);
  1086. goto out;
  1087. }
  1088. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1089. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1090. req->handler = zfcp_fsf_exchange_port_data_handler;
  1091. req->erp_action = erp_action;
  1092. erp_action->fsf_req_id = req->req_id;
  1093. zfcp_fsf_start_erp_timer(req);
  1094. retval = zfcp_fsf_req_send(req);
  1095. if (retval) {
  1096. zfcp_fsf_req_free(req);
  1097. erp_action->fsf_req_id = 0;
  1098. }
  1099. out:
  1100. spin_unlock_irq(&qdio->req_q_lock);
  1101. return retval;
  1102. }
  1103. /**
  1104. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1105. * @qdio: pointer to struct zfcp_qdio
  1106. * @data: pointer to struct fsf_qtcb_bottom_port
  1107. * Returns: 0 on success, error otherwise
  1108. */
  1109. int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
  1110. struct fsf_qtcb_bottom_port *data)
  1111. {
  1112. struct zfcp_fsf_req *req = NULL;
  1113. int retval = -EIO;
  1114. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1115. return -EOPNOTSUPP;
  1116. spin_lock_irq(&qdio->req_q_lock);
  1117. if (zfcp_qdio_sbal_get(qdio))
  1118. goto out_unlock;
  1119. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1120. SBAL_SFLAGS0_TYPE_READ, NULL);
  1121. if (IS_ERR(req)) {
  1122. retval = PTR_ERR(req);
  1123. goto out_unlock;
  1124. }
  1125. if (data)
  1126. req->data = data;
  1127. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1128. req->handler = zfcp_fsf_exchange_port_data_handler;
  1129. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1130. retval = zfcp_fsf_req_send(req);
  1131. spin_unlock_irq(&qdio->req_q_lock);
  1132. if (!retval)
  1133. wait_for_completion(&req->completion);
  1134. zfcp_fsf_req_free(req);
  1135. return retval;
  1136. out_unlock:
  1137. spin_unlock_irq(&qdio->req_q_lock);
  1138. return retval;
  1139. }
  1140. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1141. {
  1142. struct zfcp_port *port = req->data;
  1143. struct fsf_qtcb_header *header = &req->qtcb->header;
  1144. struct fc_els_flogi *plogi;
  1145. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1146. goto out;
  1147. switch (header->fsf_status) {
  1148. case FSF_PORT_ALREADY_OPEN:
  1149. break;
  1150. case FSF_ACCESS_DENIED:
  1151. zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
  1152. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1153. break;
  1154. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1155. dev_warn(&req->adapter->ccw_device->dev,
  1156. "Not enough FCP adapter resources to open "
  1157. "remote port 0x%016Lx\n",
  1158. (unsigned long long)port->wwpn);
  1159. zfcp_erp_set_port_status(port,
  1160. ZFCP_STATUS_COMMON_ERP_FAILED);
  1161. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1162. break;
  1163. case FSF_ADAPTER_STATUS_AVAILABLE:
  1164. switch (header->fsf_status_qual.word[0]) {
  1165. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1166. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1167. case FSF_SQ_NO_RETRY_POSSIBLE:
  1168. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1169. break;
  1170. }
  1171. break;
  1172. case FSF_GOOD:
  1173. port->handle = header->port_handle;
  1174. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1175. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1176. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1177. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1178. &port->status);
  1179. /* check whether D_ID has changed during open */
  1180. /*
  1181. * FIXME: This check is not airtight, as the FCP channel does
  1182. * not monitor closures of target port connections caused on
  1183. * the remote side. Thus, they might miss out on invalidating
  1184. * locally cached WWPNs (and other N_Port parameters) of gone
  1185. * target ports. So, our heroic attempt to make things safe
  1186. * could be undermined by 'open port' response data tagged with
  1187. * obsolete WWPNs. Another reason to monitor potential
  1188. * connection closures ourself at least (by interpreting
  1189. * incoming ELS' and unsolicited status). It just crosses my
  1190. * mind that one should be able to cross-check by means of
  1191. * another GID_PN straight after a port has been opened.
  1192. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1193. */
  1194. plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
  1195. if (req->qtcb->bottom.support.els1_length >=
  1196. FSF_PLOGI_MIN_LEN)
  1197. zfcp_fc_plogi_evaluate(port, plogi);
  1198. break;
  1199. case FSF_UNKNOWN_OP_SUBTYPE:
  1200. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1201. break;
  1202. }
  1203. out:
  1204. put_device(&port->dev);
  1205. }
  1206. /**
  1207. * zfcp_fsf_open_port - create and send open port request
  1208. * @erp_action: pointer to struct zfcp_erp_action
  1209. * Returns: 0 on success, error otherwise
  1210. */
  1211. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1212. {
  1213. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1214. struct zfcp_port *port = erp_action->port;
  1215. struct zfcp_fsf_req *req;
  1216. int retval = -EIO;
  1217. spin_lock_irq(&qdio->req_q_lock);
  1218. if (zfcp_qdio_sbal_get(qdio))
  1219. goto out;
  1220. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1221. SBAL_SFLAGS0_TYPE_READ,
  1222. qdio->adapter->pool.erp_req);
  1223. if (IS_ERR(req)) {
  1224. retval = PTR_ERR(req);
  1225. goto out;
  1226. }
  1227. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1228. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1229. req->handler = zfcp_fsf_open_port_handler;
  1230. hton24(req->qtcb->bottom.support.d_id, port->d_id);
  1231. req->data = port;
  1232. req->erp_action = erp_action;
  1233. erp_action->fsf_req_id = req->req_id;
  1234. get_device(&port->dev);
  1235. zfcp_fsf_start_erp_timer(req);
  1236. retval = zfcp_fsf_req_send(req);
  1237. if (retval) {
  1238. zfcp_fsf_req_free(req);
  1239. erp_action->fsf_req_id = 0;
  1240. put_device(&port->dev);
  1241. }
  1242. out:
  1243. spin_unlock_irq(&qdio->req_q_lock);
  1244. return retval;
  1245. }
  1246. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1247. {
  1248. struct zfcp_port *port = req->data;
  1249. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1250. return;
  1251. switch (req->qtcb->header.fsf_status) {
  1252. case FSF_PORT_HANDLE_NOT_VALID:
  1253. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1");
  1254. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1255. break;
  1256. case FSF_ADAPTER_STATUS_AVAILABLE:
  1257. break;
  1258. case FSF_GOOD:
  1259. zfcp_erp_clear_port_status(port, ZFCP_STATUS_COMMON_OPEN);
  1260. break;
  1261. }
  1262. }
  1263. /**
  1264. * zfcp_fsf_close_port - create and send close port request
  1265. * @erp_action: pointer to struct zfcp_erp_action
  1266. * Returns: 0 on success, error otherwise
  1267. */
  1268. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1269. {
  1270. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1271. struct zfcp_fsf_req *req;
  1272. int retval = -EIO;
  1273. spin_lock_irq(&qdio->req_q_lock);
  1274. if (zfcp_qdio_sbal_get(qdio))
  1275. goto out;
  1276. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1277. SBAL_SFLAGS0_TYPE_READ,
  1278. qdio->adapter->pool.erp_req);
  1279. if (IS_ERR(req)) {
  1280. retval = PTR_ERR(req);
  1281. goto out;
  1282. }
  1283. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1284. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1285. req->handler = zfcp_fsf_close_port_handler;
  1286. req->data = erp_action->port;
  1287. req->erp_action = erp_action;
  1288. req->qtcb->header.port_handle = erp_action->port->handle;
  1289. erp_action->fsf_req_id = req->req_id;
  1290. zfcp_fsf_start_erp_timer(req);
  1291. retval = zfcp_fsf_req_send(req);
  1292. if (retval) {
  1293. zfcp_fsf_req_free(req);
  1294. erp_action->fsf_req_id = 0;
  1295. }
  1296. out:
  1297. spin_unlock_irq(&qdio->req_q_lock);
  1298. return retval;
  1299. }
  1300. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1301. {
  1302. struct zfcp_fc_wka_port *wka_port = req->data;
  1303. struct fsf_qtcb_header *header = &req->qtcb->header;
  1304. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1305. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1306. goto out;
  1307. }
  1308. switch (header->fsf_status) {
  1309. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1310. dev_warn(&req->adapter->ccw_device->dev,
  1311. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1312. /* fall through */
  1313. case FSF_ADAPTER_STATUS_AVAILABLE:
  1314. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1315. /* fall through */
  1316. case FSF_ACCESS_DENIED:
  1317. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1318. break;
  1319. case FSF_GOOD:
  1320. wka_port->handle = header->port_handle;
  1321. /* fall through */
  1322. case FSF_PORT_ALREADY_OPEN:
  1323. wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
  1324. }
  1325. out:
  1326. wake_up(&wka_port->completion_wq);
  1327. }
  1328. /**
  1329. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1330. * @wka_port: pointer to struct zfcp_fc_wka_port
  1331. * Returns: 0 on success, error otherwise
  1332. */
  1333. int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
  1334. {
  1335. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1336. struct zfcp_fsf_req *req;
  1337. int retval = -EIO;
  1338. spin_lock_irq(&qdio->req_q_lock);
  1339. if (zfcp_qdio_sbal_get(qdio))
  1340. goto out;
  1341. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1342. SBAL_SFLAGS0_TYPE_READ,
  1343. qdio->adapter->pool.erp_req);
  1344. if (IS_ERR(req)) {
  1345. retval = PTR_ERR(req);
  1346. goto out;
  1347. }
  1348. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1349. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1350. req->handler = zfcp_fsf_open_wka_port_handler;
  1351. hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
  1352. req->data = wka_port;
  1353. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1354. retval = zfcp_fsf_req_send(req);
  1355. if (retval)
  1356. zfcp_fsf_req_free(req);
  1357. out:
  1358. spin_unlock_irq(&qdio->req_q_lock);
  1359. return retval;
  1360. }
  1361. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1362. {
  1363. struct zfcp_fc_wka_port *wka_port = req->data;
  1364. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1365. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1366. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1");
  1367. }
  1368. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1369. wake_up(&wka_port->completion_wq);
  1370. }
  1371. /**
  1372. * zfcp_fsf_close_wka_port - create and send close wka port request
  1373. * @wka_port: WKA port to open
  1374. * Returns: 0 on success, error otherwise
  1375. */
  1376. int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
  1377. {
  1378. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1379. struct zfcp_fsf_req *req;
  1380. int retval = -EIO;
  1381. spin_lock_irq(&qdio->req_q_lock);
  1382. if (zfcp_qdio_sbal_get(qdio))
  1383. goto out;
  1384. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1385. SBAL_SFLAGS0_TYPE_READ,
  1386. qdio->adapter->pool.erp_req);
  1387. if (IS_ERR(req)) {
  1388. retval = PTR_ERR(req);
  1389. goto out;
  1390. }
  1391. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1392. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1393. req->handler = zfcp_fsf_close_wka_port_handler;
  1394. req->data = wka_port;
  1395. req->qtcb->header.port_handle = wka_port->handle;
  1396. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1397. retval = zfcp_fsf_req_send(req);
  1398. if (retval)
  1399. zfcp_fsf_req_free(req);
  1400. out:
  1401. spin_unlock_irq(&qdio->req_q_lock);
  1402. return retval;
  1403. }
  1404. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1405. {
  1406. struct zfcp_port *port = req->data;
  1407. struct fsf_qtcb_header *header = &req->qtcb->header;
  1408. struct scsi_device *sdev;
  1409. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1410. return;
  1411. switch (header->fsf_status) {
  1412. case FSF_PORT_HANDLE_NOT_VALID:
  1413. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1");
  1414. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1415. break;
  1416. case FSF_ACCESS_DENIED:
  1417. zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
  1418. break;
  1419. case FSF_PORT_BOXED:
  1420. /* can't use generic zfcp_erp_modify_port_status because
  1421. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1422. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1423. shost_for_each_device(sdev, port->adapter->scsi_host)
  1424. if (sdev_to_zfcp(sdev)->port == port)
  1425. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1426. &sdev_to_zfcp(sdev)->status);
  1427. zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1428. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
  1429. "fscpph2");
  1430. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1431. break;
  1432. case FSF_ADAPTER_STATUS_AVAILABLE:
  1433. switch (header->fsf_status_qual.word[0]) {
  1434. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1435. /* fall through */
  1436. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1437. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1438. break;
  1439. }
  1440. break;
  1441. case FSF_GOOD:
  1442. /* can't use generic zfcp_erp_modify_port_status because
  1443. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1444. */
  1445. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1446. shost_for_each_device(sdev, port->adapter->scsi_host)
  1447. if (sdev_to_zfcp(sdev)->port == port)
  1448. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1449. &sdev_to_zfcp(sdev)->status);
  1450. break;
  1451. }
  1452. }
  1453. /**
  1454. * zfcp_fsf_close_physical_port - close physical port
  1455. * @erp_action: pointer to struct zfcp_erp_action
  1456. * Returns: 0 on success
  1457. */
  1458. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1459. {
  1460. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1461. struct zfcp_fsf_req *req;
  1462. int retval = -EIO;
  1463. spin_lock_irq(&qdio->req_q_lock);
  1464. if (zfcp_qdio_sbal_get(qdio))
  1465. goto out;
  1466. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1467. SBAL_SFLAGS0_TYPE_READ,
  1468. qdio->adapter->pool.erp_req);
  1469. if (IS_ERR(req)) {
  1470. retval = PTR_ERR(req);
  1471. goto out;
  1472. }
  1473. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1474. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1475. req->data = erp_action->port;
  1476. req->qtcb->header.port_handle = erp_action->port->handle;
  1477. req->erp_action = erp_action;
  1478. req->handler = zfcp_fsf_close_physical_port_handler;
  1479. erp_action->fsf_req_id = req->req_id;
  1480. zfcp_fsf_start_erp_timer(req);
  1481. retval = zfcp_fsf_req_send(req);
  1482. if (retval) {
  1483. zfcp_fsf_req_free(req);
  1484. erp_action->fsf_req_id = 0;
  1485. }
  1486. out:
  1487. spin_unlock_irq(&qdio->req_q_lock);
  1488. return retval;
  1489. }
  1490. static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req)
  1491. {
  1492. struct zfcp_adapter *adapter = req->adapter;
  1493. struct scsi_device *sdev = req->data;
  1494. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  1495. struct fsf_qtcb_header *header = &req->qtcb->header;
  1496. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1497. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1498. return;
  1499. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1500. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1501. ZFCP_STATUS_LUN_SHARED |
  1502. ZFCP_STATUS_LUN_READONLY,
  1503. &zfcp_sdev->status);
  1504. switch (header->fsf_status) {
  1505. case FSF_PORT_HANDLE_NOT_VALID:
  1506. zfcp_erp_adapter_reopen(adapter, 0, "fsouh_1");
  1507. /* fall through */
  1508. case FSF_LUN_ALREADY_OPEN:
  1509. break;
  1510. case FSF_ACCESS_DENIED:
  1511. zfcp_cfdc_lun_denied(sdev, &header->fsf_status_qual);
  1512. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1513. break;
  1514. case FSF_PORT_BOXED:
  1515. zfcp_erp_set_port_status(zfcp_sdev->port,
  1516. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1517. zfcp_erp_port_reopen(zfcp_sdev->port,
  1518. ZFCP_STATUS_COMMON_ERP_FAILED, "fsouh_2");
  1519. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1520. break;
  1521. case FSF_LUN_SHARING_VIOLATION:
  1522. zfcp_cfdc_lun_shrng_vltn(sdev, &header->fsf_status_qual);
  1523. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1524. break;
  1525. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1526. dev_warn(&adapter->ccw_device->dev,
  1527. "No handle is available for LUN "
  1528. "0x%016Lx on port 0x%016Lx\n",
  1529. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1530. (unsigned long long)zfcp_sdev->port->wwpn);
  1531. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ERP_FAILED);
  1532. /* fall through */
  1533. case FSF_INVALID_COMMAND_OPTION:
  1534. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1535. break;
  1536. case FSF_ADAPTER_STATUS_AVAILABLE:
  1537. switch (header->fsf_status_qual.word[0]) {
  1538. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1539. zfcp_fc_test_link(zfcp_sdev->port);
  1540. /* fall through */
  1541. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1542. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1543. break;
  1544. }
  1545. break;
  1546. case FSF_GOOD:
  1547. zfcp_sdev->lun_handle = header->lun_handle;
  1548. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
  1549. zfcp_cfdc_open_lun_eval(sdev, bottom);
  1550. break;
  1551. }
  1552. }
  1553. /**
  1554. * zfcp_fsf_open_lun - open LUN
  1555. * @erp_action: pointer to struct zfcp_erp_action
  1556. * Returns: 0 on success, error otherwise
  1557. */
  1558. int zfcp_fsf_open_lun(struct zfcp_erp_action *erp_action)
  1559. {
  1560. struct zfcp_adapter *adapter = erp_action->adapter;
  1561. struct zfcp_qdio *qdio = adapter->qdio;
  1562. struct zfcp_fsf_req *req;
  1563. int retval = -EIO;
  1564. spin_lock_irq(&qdio->req_q_lock);
  1565. if (zfcp_qdio_sbal_get(qdio))
  1566. goto out;
  1567. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
  1568. SBAL_SFLAGS0_TYPE_READ,
  1569. adapter->pool.erp_req);
  1570. if (IS_ERR(req)) {
  1571. retval = PTR_ERR(req);
  1572. goto out;
  1573. }
  1574. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1575. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1576. req->qtcb->header.port_handle = erp_action->port->handle;
  1577. req->qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->sdev);
  1578. req->handler = zfcp_fsf_open_lun_handler;
  1579. req->data = erp_action->sdev;
  1580. req->erp_action = erp_action;
  1581. erp_action->fsf_req_id = req->req_id;
  1582. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1583. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1584. zfcp_fsf_start_erp_timer(req);
  1585. retval = zfcp_fsf_req_send(req);
  1586. if (retval) {
  1587. zfcp_fsf_req_free(req);
  1588. erp_action->fsf_req_id = 0;
  1589. }
  1590. out:
  1591. spin_unlock_irq(&qdio->req_q_lock);
  1592. return retval;
  1593. }
  1594. static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req)
  1595. {
  1596. struct scsi_device *sdev = req->data;
  1597. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  1598. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1599. return;
  1600. switch (req->qtcb->header.fsf_status) {
  1601. case FSF_PORT_HANDLE_NOT_VALID:
  1602. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1");
  1603. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1604. break;
  1605. case FSF_LUN_HANDLE_NOT_VALID:
  1606. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fscuh_2");
  1607. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1608. break;
  1609. case FSF_PORT_BOXED:
  1610. zfcp_erp_set_port_status(zfcp_sdev->port,
  1611. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1612. zfcp_erp_port_reopen(zfcp_sdev->port,
  1613. ZFCP_STATUS_COMMON_ERP_FAILED, "fscuh_3");
  1614. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1615. break;
  1616. case FSF_ADAPTER_STATUS_AVAILABLE:
  1617. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1618. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1619. zfcp_fc_test_link(zfcp_sdev->port);
  1620. /* fall through */
  1621. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1622. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1623. break;
  1624. }
  1625. break;
  1626. case FSF_GOOD:
  1627. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
  1628. break;
  1629. }
  1630. }
  1631. /**
  1632. * zfcp_fsf_close_LUN - close LUN
  1633. * @erp_action: pointer to erp_action triggering the "close LUN"
  1634. * Returns: 0 on success, error otherwise
  1635. */
  1636. int zfcp_fsf_close_lun(struct zfcp_erp_action *erp_action)
  1637. {
  1638. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1639. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(erp_action->sdev);
  1640. struct zfcp_fsf_req *req;
  1641. int retval = -EIO;
  1642. spin_lock_irq(&qdio->req_q_lock);
  1643. if (zfcp_qdio_sbal_get(qdio))
  1644. goto out;
  1645. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
  1646. SBAL_SFLAGS0_TYPE_READ,
  1647. qdio->adapter->pool.erp_req);
  1648. if (IS_ERR(req)) {
  1649. retval = PTR_ERR(req);
  1650. goto out;
  1651. }
  1652. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1653. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1654. req->qtcb->header.port_handle = erp_action->port->handle;
  1655. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  1656. req->handler = zfcp_fsf_close_lun_handler;
  1657. req->data = erp_action->sdev;
  1658. req->erp_action = erp_action;
  1659. erp_action->fsf_req_id = req->req_id;
  1660. zfcp_fsf_start_erp_timer(req);
  1661. retval = zfcp_fsf_req_send(req);
  1662. if (retval) {
  1663. zfcp_fsf_req_free(req);
  1664. erp_action->fsf_req_id = 0;
  1665. }
  1666. out:
  1667. spin_unlock_irq(&qdio->req_q_lock);
  1668. return retval;
  1669. }
  1670. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1671. {
  1672. lat_rec->sum += lat;
  1673. lat_rec->min = min(lat_rec->min, lat);
  1674. lat_rec->max = max(lat_rec->max, lat);
  1675. }
  1676. static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
  1677. {
  1678. struct fsf_qual_latency_info *lat_in;
  1679. struct latency_cont *lat = NULL;
  1680. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scsi->device);
  1681. struct zfcp_blk_drv_data blktrc;
  1682. int ticks = req->adapter->timer_ticks;
  1683. lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
  1684. blktrc.flags = 0;
  1685. blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1686. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1687. blktrc.flags |= ZFCP_BLK_REQ_ERROR;
  1688. blktrc.inb_usage = 0;
  1689. blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
  1690. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
  1691. !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1692. blktrc.flags |= ZFCP_BLK_LAT_VALID;
  1693. blktrc.channel_lat = lat_in->channel_lat * ticks;
  1694. blktrc.fabric_lat = lat_in->fabric_lat * ticks;
  1695. switch (req->qtcb->bottom.io.data_direction) {
  1696. case FSF_DATADIR_DIF_READ_STRIP:
  1697. case FSF_DATADIR_DIF_READ_CONVERT:
  1698. case FSF_DATADIR_READ:
  1699. lat = &zfcp_sdev->latencies.read;
  1700. break;
  1701. case FSF_DATADIR_DIF_WRITE_INSERT:
  1702. case FSF_DATADIR_DIF_WRITE_CONVERT:
  1703. case FSF_DATADIR_WRITE:
  1704. lat = &zfcp_sdev->latencies.write;
  1705. break;
  1706. case FSF_DATADIR_CMND:
  1707. lat = &zfcp_sdev->latencies.cmd;
  1708. break;
  1709. }
  1710. if (lat) {
  1711. spin_lock(&zfcp_sdev->latencies.lock);
  1712. zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
  1713. zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
  1714. lat->counter++;
  1715. spin_unlock(&zfcp_sdev->latencies.lock);
  1716. }
  1717. }
  1718. blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
  1719. sizeof(blktrc));
  1720. }
  1721. static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req)
  1722. {
  1723. struct scsi_cmnd *scmnd = req->data;
  1724. struct scsi_device *sdev = scmnd->device;
  1725. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  1726. struct fsf_qtcb_header *header = &req->qtcb->header;
  1727. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1728. return;
  1729. switch (header->fsf_status) {
  1730. case FSF_HANDLE_MISMATCH:
  1731. case FSF_PORT_HANDLE_NOT_VALID:
  1732. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fssfch1");
  1733. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1734. break;
  1735. case FSF_FCPLUN_NOT_VALID:
  1736. case FSF_LUN_HANDLE_NOT_VALID:
  1737. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2");
  1738. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1739. break;
  1740. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1741. zfcp_fsf_class_not_supp(req);
  1742. break;
  1743. case FSF_ACCESS_DENIED:
  1744. zfcp_cfdc_lun_denied(sdev, &header->fsf_status_qual);
  1745. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1746. break;
  1747. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1748. dev_err(&req->adapter->ccw_device->dev,
  1749. "Incorrect direction %d, LUN 0x%016Lx on port "
  1750. "0x%016Lx closed\n",
  1751. req->qtcb->bottom.io.data_direction,
  1752. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1753. (unsigned long long)zfcp_sdev->port->wwpn);
  1754. zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
  1755. "fssfch3");
  1756. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1757. break;
  1758. case FSF_CMND_LENGTH_NOT_VALID:
  1759. dev_err(&req->adapter->ccw_device->dev,
  1760. "Incorrect CDB length %d, LUN 0x%016Lx on "
  1761. "port 0x%016Lx closed\n",
  1762. req->qtcb->bottom.io.fcp_cmnd_length,
  1763. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1764. (unsigned long long)zfcp_sdev->port->wwpn);
  1765. zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
  1766. "fssfch4");
  1767. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1768. break;
  1769. case FSF_PORT_BOXED:
  1770. zfcp_erp_set_port_status(zfcp_sdev->port,
  1771. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1772. zfcp_erp_port_reopen(zfcp_sdev->port,
  1773. ZFCP_STATUS_COMMON_ERP_FAILED, "fssfch5");
  1774. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1775. break;
  1776. case FSF_LUN_BOXED:
  1777. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1778. zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
  1779. "fssfch6");
  1780. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1781. break;
  1782. case FSF_ADAPTER_STATUS_AVAILABLE:
  1783. if (header->fsf_status_qual.word[0] ==
  1784. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1785. zfcp_fc_test_link(zfcp_sdev->port);
  1786. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1787. break;
  1788. }
  1789. }
  1790. static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
  1791. {
  1792. struct scsi_cmnd *scpnt;
  1793. struct fcp_resp_with_ext *fcp_rsp;
  1794. unsigned long flags;
  1795. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1796. scpnt = req->data;
  1797. if (unlikely(!scpnt)) {
  1798. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1799. return;
  1800. }
  1801. zfcp_fsf_fcp_handler_common(req);
  1802. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1803. set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
  1804. goto skip_fsfstatus;
  1805. }
  1806. switch (req->qtcb->header.fsf_status) {
  1807. case FSF_INCONSISTENT_PROT_DATA:
  1808. case FSF_INVALID_PROT_PARM:
  1809. set_host_byte(scpnt, DID_ERROR);
  1810. goto skip_fsfstatus;
  1811. case FSF_BLOCK_GUARD_CHECK_FAILURE:
  1812. zfcp_scsi_dif_sense_error(scpnt, 0x1);
  1813. goto skip_fsfstatus;
  1814. case FSF_APP_TAG_CHECK_FAILURE:
  1815. zfcp_scsi_dif_sense_error(scpnt, 0x2);
  1816. goto skip_fsfstatus;
  1817. case FSF_REF_TAG_CHECK_FAILURE:
  1818. zfcp_scsi_dif_sense_error(scpnt, 0x3);
  1819. goto skip_fsfstatus;
  1820. }
  1821. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1822. zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
  1823. skip_fsfstatus:
  1824. zfcp_fsf_req_trace(req, scpnt);
  1825. zfcp_dbf_scsi_result(scpnt, req);
  1826. scpnt->host_scribble = NULL;
  1827. (scpnt->scsi_done) (scpnt);
  1828. /*
  1829. * We must hold this lock until scsi_done has been called.
  1830. * Otherwise we may call scsi_done after abort regarding this
  1831. * command has completed.
  1832. * Note: scsi_done must not block!
  1833. */
  1834. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1835. }
  1836. static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
  1837. {
  1838. switch (scsi_get_prot_op(scsi_cmnd)) {
  1839. case SCSI_PROT_NORMAL:
  1840. switch (scsi_cmnd->sc_data_direction) {
  1841. case DMA_NONE:
  1842. *data_dir = FSF_DATADIR_CMND;
  1843. break;
  1844. case DMA_FROM_DEVICE:
  1845. *data_dir = FSF_DATADIR_READ;
  1846. break;
  1847. case DMA_TO_DEVICE:
  1848. *data_dir = FSF_DATADIR_WRITE;
  1849. break;
  1850. case DMA_BIDIRECTIONAL:
  1851. return -EINVAL;
  1852. }
  1853. break;
  1854. case SCSI_PROT_READ_STRIP:
  1855. *data_dir = FSF_DATADIR_DIF_READ_STRIP;
  1856. break;
  1857. case SCSI_PROT_WRITE_INSERT:
  1858. *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
  1859. break;
  1860. case SCSI_PROT_READ_PASS:
  1861. *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
  1862. break;
  1863. case SCSI_PROT_WRITE_PASS:
  1864. *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
  1865. break;
  1866. default:
  1867. return -EINVAL;
  1868. }
  1869. return 0;
  1870. }
  1871. /**
  1872. * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command)
  1873. * @scsi_cmnd: scsi command to be sent
  1874. */
  1875. int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
  1876. {
  1877. struct zfcp_fsf_req *req;
  1878. struct fcp_cmnd *fcp_cmnd;
  1879. u8 sbtype = SBAL_SFLAGS0_TYPE_READ;
  1880. int real_bytes, retval = -EIO, dix_bytes = 0;
  1881. struct scsi_device *sdev = scsi_cmnd->device;
  1882. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  1883. struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
  1884. struct zfcp_qdio *qdio = adapter->qdio;
  1885. struct fsf_qtcb_bottom_io *io;
  1886. unsigned long flags;
  1887. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  1888. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1889. return -EBUSY;
  1890. spin_lock_irqsave(&qdio->req_q_lock, flags);
  1891. if (atomic_read(&qdio->req_q_free) <= 0) {
  1892. atomic_inc(&qdio->req_q_full);
  1893. goto out;
  1894. }
  1895. if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
  1896. sbtype = SBAL_SFLAGS0_TYPE_WRITE;
  1897. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  1898. sbtype, adapter->pool.scsi_req);
  1899. if (IS_ERR(req)) {
  1900. retval = PTR_ERR(req);
  1901. goto out;
  1902. }
  1903. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  1904. io = &req->qtcb->bottom.io;
  1905. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1906. req->data = scsi_cmnd;
  1907. req->handler = zfcp_fsf_fcp_cmnd_handler;
  1908. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  1909. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  1910. io->service_class = FSF_CLASS_3;
  1911. io->fcp_cmnd_length = FCP_CMND_LEN;
  1912. if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
  1913. io->data_block_length = scsi_cmnd->device->sector_size;
  1914. io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
  1915. }
  1916. zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction);
  1917. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  1918. zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd, 0);
  1919. if (scsi_prot_sg_count(scsi_cmnd)) {
  1920. zfcp_qdio_set_data_div(qdio, &req->qdio_req,
  1921. scsi_prot_sg_count(scsi_cmnd));
  1922. dix_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1923. scsi_prot_sglist(scsi_cmnd));
  1924. io->prot_data_length = dix_bytes;
  1925. }
  1926. real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1927. scsi_sglist(scsi_cmnd));
  1928. if (unlikely(real_bytes < 0) || unlikely(dix_bytes < 0))
  1929. goto failed_scsi_cmnd;
  1930. zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
  1931. retval = zfcp_fsf_req_send(req);
  1932. if (unlikely(retval))
  1933. goto failed_scsi_cmnd;
  1934. goto out;
  1935. failed_scsi_cmnd:
  1936. zfcp_fsf_req_free(req);
  1937. scsi_cmnd->host_scribble = NULL;
  1938. out:
  1939. spin_unlock_irqrestore(&qdio->req_q_lock, flags);
  1940. return retval;
  1941. }
  1942. static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req)
  1943. {
  1944. struct fcp_resp_with_ext *fcp_rsp;
  1945. struct fcp_resp_rsp_info *rsp_info;
  1946. zfcp_fsf_fcp_handler_common(req);
  1947. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1948. rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
  1949. if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
  1950. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1951. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1952. }
  1953. /**
  1954. * zfcp_fsf_fcp_task_mgmt - send SCSI task management command
  1955. * @scmnd: SCSI command to send the task management command for
  1956. * @tm_flags: unsigned byte for task management flags
  1957. * Returns: on success pointer to struct fsf_req, NULL otherwise
  1958. */
  1959. struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_cmnd *scmnd,
  1960. u8 tm_flags)
  1961. {
  1962. struct zfcp_fsf_req *req = NULL;
  1963. struct fcp_cmnd *fcp_cmnd;
  1964. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
  1965. struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
  1966. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  1967. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1968. return NULL;
  1969. spin_lock_irq(&qdio->req_q_lock);
  1970. if (zfcp_qdio_sbal_get(qdio))
  1971. goto out;
  1972. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  1973. SBAL_SFLAGS0_TYPE_WRITE,
  1974. qdio->adapter->pool.scsi_req);
  1975. if (IS_ERR(req)) {
  1976. req = NULL;
  1977. goto out;
  1978. }
  1979. req->data = scmnd;
  1980. req->handler = zfcp_fsf_fcp_task_mgmt_handler;
  1981. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  1982. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  1983. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  1984. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  1985. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  1986. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1987. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  1988. zfcp_fc_scsi_to_fcp(fcp_cmnd, scmnd, tm_flags);
  1989. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  1990. if (!zfcp_fsf_req_send(req))
  1991. goto out;
  1992. zfcp_fsf_req_free(req);
  1993. req = NULL;
  1994. out:
  1995. spin_unlock_irq(&qdio->req_q_lock);
  1996. return req;
  1997. }
  1998. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  1999. {
  2000. }
  2001. /**
  2002. * zfcp_fsf_control_file - control file upload/download
  2003. * @adapter: pointer to struct zfcp_adapter
  2004. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2005. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2006. */
  2007. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2008. struct zfcp_fsf_cfdc *fsf_cfdc)
  2009. {
  2010. struct zfcp_qdio *qdio = adapter->qdio;
  2011. struct zfcp_fsf_req *req = NULL;
  2012. struct fsf_qtcb_bottom_support *bottom;
  2013. int retval = -EIO, bytes;
  2014. u8 direction;
  2015. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2016. return ERR_PTR(-EOPNOTSUPP);
  2017. switch (fsf_cfdc->command) {
  2018. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2019. direction = SBAL_SFLAGS0_TYPE_WRITE;
  2020. break;
  2021. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2022. direction = SBAL_SFLAGS0_TYPE_READ;
  2023. break;
  2024. default:
  2025. return ERR_PTR(-EINVAL);
  2026. }
  2027. spin_lock_irq(&qdio->req_q_lock);
  2028. if (zfcp_qdio_sbal_get(qdio))
  2029. goto out;
  2030. req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
  2031. if (IS_ERR(req)) {
  2032. retval = -EPERM;
  2033. goto out;
  2034. }
  2035. req->handler = zfcp_fsf_control_file_handler;
  2036. bottom = &req->qtcb->bottom.support;
  2037. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2038. bottom->option = fsf_cfdc->option;
  2039. bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, fsf_cfdc->sg);
  2040. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2041. zfcp_fsf_req_free(req);
  2042. goto out;
  2043. }
  2044. zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
  2045. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2046. retval = zfcp_fsf_req_send(req);
  2047. out:
  2048. spin_unlock_irq(&qdio->req_q_lock);
  2049. if (!retval) {
  2050. wait_for_completion(&req->completion);
  2051. return req;
  2052. }
  2053. return ERR_PTR(retval);
  2054. }
  2055. /**
  2056. * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
  2057. * @adapter: pointer to struct zfcp_adapter
  2058. * @sbal_idx: response queue index of SBAL to be processed
  2059. */
  2060. void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
  2061. {
  2062. struct zfcp_adapter *adapter = qdio->adapter;
  2063. struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
  2064. struct qdio_buffer_element *sbale;
  2065. struct zfcp_fsf_req *fsf_req;
  2066. unsigned long req_id;
  2067. int idx;
  2068. for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
  2069. sbale = &sbal->element[idx];
  2070. req_id = (unsigned long) sbale->addr;
  2071. fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
  2072. if (!fsf_req) {
  2073. /*
  2074. * Unknown request means that we have potentially memory
  2075. * corruption and must stop the machine immediately.
  2076. */
  2077. zfcp_qdio_siosl(adapter);
  2078. panic("error: unknown req_id (%lx) on adapter %s.\n",
  2079. req_id, dev_name(&adapter->ccw_device->dev));
  2080. }
  2081. fsf_req->qdio_req.sbal_response = sbal_idx;
  2082. zfcp_fsf_req_complete(fsf_req);
  2083. if (likely(sbale->eflags & SBAL_EFLAGS_LAST_ENTRY))
  2084. break;
  2085. }
  2086. }
  2087. struct zfcp_fsf_req *zfcp_fsf_get_req(struct zfcp_qdio *qdio,
  2088. struct qdio_buffer *sbal)
  2089. {
  2090. struct qdio_buffer_element *sbale = &sbal->element[0];
  2091. u64 req_id = (unsigned long) sbale->addr;
  2092. return zfcp_reqlist_find(qdio->adapter->req_list, req_id);
  2093. }