zfcp_fsf.c 67 KB

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