zfcp_fsf.c 69 KB

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