zfcp_fsf.c 66 KB

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