zfcp_fsf.c 67 KB

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