zfcp_fsf.c 66 KB

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